Construct GeneratorExpressionExit

Performance Diagrams

Construct GeneratorExpressionExit 0040000000400000008000000080000000120000000120000000160000000160000000200000000200000000240000000240000000280000000280000000320000000320000000CPython 2.7Nuitka (master)Nuitka (develop)Nuitka (factory)34717649888.11538461538461257.0CPython 2.7163404330240.03846153846155387.8064636821214Nuitka (master)163402769391.96153846153845387.80757478012947Nuitka (develop)163402878543.8846153846154387.8074971954511Nuitka (factory)Construct GeneratorExpressionExitTicks Construct GeneratorExpressionExit 0010000000100000002000000020000000300000003000000040000000400000005000000050000000600000006000000070000000700000008000000080000000CPython 3.5Nuitka (master)Nuitka (develop)Nuitka (factory)8291831188.95192307692307257.0CPython 3.565952190242.31730769230768307.5628909439093Nuitka (master)65953308395.6826923076923307.5595590501856Nuitka (develop)65957550549.0480769230769307.54691692748804Nuitka (factory)Construct GeneratorExpressionExitTicks

Source Code with Construct

def calledRepeatedly():
    # We measure making a generator iterator step or not.
    gen = (x for x in range(3))

    next(gen)

    # Take attribute lookup out of it, and built-in lookup too.
    throw = gen.throw
    exc = GeneratorExit

    try:
# construct_begin
        throw(exc)
# construct_alternative


    except exc:
        pass

    return throw, exc


import itertools
for x in itertools.repeat(None, 50000):
    calledRepeatedly()

print("OK.")

Source Code without Construct

def calledRepeatedly():
    # We measure making a generator iterator step or not.
    gen = (x for x in range(3))

    next(gen)

    # Take attribute lookup out of it, and built-in lookup too.
    throw = gen.throw
    exc = GeneratorExit

    try:
# construct_begin

# construct_alternative
        pass
# construct_end
    except exc:
        pass

    return throw, exc


import itertools
for x in itertools.repeat(None, 50000):
    calledRepeatedly()

print("OK.")

Context Diff of Source Code


Construct
Baseline
27     throw = gen.throw 27     throw = gen.throw
28     exc = GeneratorExit 28     exc = GeneratorExit
29 29
30     try: 30     try:
31 # construct_begin 31 # construct_begin
n 32         throw(exc) n 32  
33 # construct_alternative 33 # construct_alternative
t 34   t 34         pass
35   35 # construct_end
36     except exc: 36     except exc:
37         pass 37         pass
38 38
39     return throw, exc 39     return throw, exc
40 40

Context Diff of Generated Code


Construct
Baseline
57 static PyObject *const_str_plain_repeat; 57 static PyObject *const_str_plain_repeat;
58 static PyObject *const_tuple_str_digest_b9c4baf879ebd882d40843df3a4dead7_str_plain_x_tuple; 58 static PyObject *const_tuple_str_digest_b9c4baf879ebd882d40843df3a4dead7_str_plain_x_tuple;
59 static PyObject *const_str_digest_0a3be7117465f4a733a7e0a4add9ac0e; 59 static PyObject *const_str_digest_0a3be7117465f4a733a7e0a4add9ac0e;
60 static PyObject *const_tuple_none_int_pos_50000_tuple; 60 static PyObject *const_tuple_none_int_pos_50000_tuple;
61 extern PyObject *const_str_plain___main__; 61 extern PyObject *const_str_plain___main__;
n 62 static PyObject *const_tuple_type_GeneratorExit_tuple; n
63 extern PyObject *const_str_plain___doc__; 62 extern PyObject *const_str_plain___doc__;
64 extern PyObject *const_str_plain___cached__; 63 extern PyObject *const_str_plain___cached__;
65 static PyObject *const_str_plain___debug__; 64 static PyObject *const_str_plain___debug__;
66 static PyObject *module_filename_obj; 65 static PyObject *module_filename_obj;
67 66
98     PyTuple_SET_ITEM( const_tuple_str_digest_b9c4baf879ebd882d40843df3a4dead7_str_plain_x_tuple, 1, const_str_plain_x ); Py_INCREF( const_str_plain_x ); 97     PyTuple_SET_ITEM( const_tuple_str_digest_b9c4baf879ebd882d40843df3a4dead7_str_plain_x_tuple, 1, const_str_plain_x ); Py_INCREF( const_str_plain_x );
99     const_str_digest_0a3be7117465f4a733a7e0a4add9ac0e = UNSTREAM_STRING_ASCII( &constant_bin[ 75 ], 74, 0 ); 98     const_str_digest_0a3be7117465f4a733a7e0a4add9ac0e = UNSTREAM_STRING_ASCII( &constant_bin[ 75 ], 74, 0 );
100     const_tuple_none_int_pos_50000_tuple = PyTuple_New( 2 ); 99     const_tuple_none_int_pos_50000_tuple = PyTuple_New( 2 );
101     PyTuple_SET_ITEM( const_tuple_none_int_pos_50000_tuple, 0, Py_None ); Py_INCREF( Py_None ); 100     PyTuple_SET_ITEM( const_tuple_none_int_pos_50000_tuple, 0, Py_None ); Py_INCREF( Py_None );
102     PyTuple_SET_ITEM( const_tuple_none_int_pos_50000_tuple, 1, const_int_pos_50000 ); Py_INCREF( const_int_pos_50000 ); 101     PyTuple_SET_ITEM( const_tuple_none_int_pos_50000_tuple, 1, const_int_pos_50000 ); Py_INCREF( const_int_pos_50000 );
n 103     const_tuple_type_GeneratorExit_tuple = PyTuple_New( 1 ); n
104     PyTuple_SET_ITEM( const_tuple_type_GeneratorExit_tuple, 0, (PyObject *)PyExc_GeneratorExit ); Py_INCREF( (PyObject *)PyExc_GeneratorExit );
105     const_str_plain___debug__ = UNSTREAM_STRING_ASCII( &constant_bin[ 149 ], 9, 1 ); 102     const_str_plain___debug__ = UNSTREAM_STRING_ASCII( &constant_bin[ 149 ], 9, 1 );
106 103
107     constants_created = true; 104     constants_created = true;
108 } 105 }
109 106
157     NUITKA_MAY_BE_UNUSED char const *type_description_1 = NULL; 154     NUITKA_MAY_BE_UNUSED char const *type_description_1 = NULL;
158     PyObject *exception_type = NULL; 155     PyObject *exception_type = NULL;
159     PyObject *exception_value = NULL; 156     PyObject *exception_value = NULL;
160     PyTracebackObject *exception_tb = NULL; 157     PyTracebackObject *exception_tb = NULL;
161     NUITKA_MAY_BE_UNUSED int exception_lineno = 0; 158     NUITKA_MAY_BE_UNUSED int exception_lineno = 0;
n n 159     static struct Nuitka_FrameObject *cache_frame_977d56a6116d6d7c558c35b3284a4d5e = NULL;
160     PyObject *tmp_return_value = NULL;
162     PyObject *exception_keeper_type_1; 161     PyObject *exception_keeper_type_1;
163     PyObject *exception_keeper_value_1; 162     PyObject *exception_keeper_value_1;
164     PyTracebackObject *exception_keeper_tb_1; 163     PyTracebackObject *exception_keeper_tb_1;
165     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_1; 164     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_1;
n 166     PyObject *exception_preserved_type_1; n
167     PyObject *exception_preserved_value_1;
168     PyTracebackObject *exception_preserved_tb_1;
169     int tmp_res;
170     bool tmp_result;
171     PyObject *exception_keeper_type_2;
172     PyObject *exception_keeper_value_2;
173     PyTracebackObject *exception_keeper_tb_2;
174     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_2;
175     static struct Nuitka_FrameObject *cache_frame_977d56a6116d6d7c558c35b3284a4d5e = NULL;
176     PyObject *tmp_return_value = NULL;
177     PyObject *exception_keeper_type_3;
178     PyObject *exception_keeper_value_3;
179     PyTracebackObject *exception_keeper_tb_3;
180     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_3;
181 165
182     // Actual function body. 166     // Actual function body.
183     { 167     {
184         PyObject *tmp_assign_source_1; 168         PyObject *tmp_assign_source_1;
185         { 169         {
276             goto frame_exception_exit_1; 260             goto frame_exception_exit_1;
277         } 261         }
278         assert( var_throw == NULL ); 262         assert( var_throw == NULL );
279         var_throw = tmp_assign_source_3; 263         var_throw = tmp_assign_source_3;
280     } 264     }
n 281     // Tried code: n
282     {
283         PyObject *tmp_called_name_1;
284         PyObject *tmp_call_result_1;
285         CHECK_OBJECT( var_throw );
286         tmp_called_name_1 = var_throw;
287         frame_977d56a6116d6d7c558c35b3284a4d5e->m_frame.f_lineno = 32;
288         tmp_call_result_1 = CALL_FUNCTION_WITH_ARGS1( tmp_called_name_1, &PyTuple_GET_ITEM( const_tuple_type_GeneratorExit_tuple, 0 ) );
289  
290         if ( tmp_call_result_1 == NULL )
291         {
292             assert( ERROR_OCCURRED() );
293  
294             FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
295  
296  
297             exception_lineno = 32;
298             type_description_1 = "oNo";
299             goto try_except_handler_3;
300         }
301         Py_DECREF( tmp_call_result_1 );
302     }
303     goto try_end_1;
304     // Exception handler code:
305     try_except_handler_3:;
306     exception_keeper_type_1 = exception_type;
307     exception_keeper_value_1 = exception_value;
308     exception_keeper_tb_1 = exception_tb;
309     exception_keeper_lineno_1 = exception_lineno;
310     exception_type = NULL;
311     exception_value = NULL;
312     exception_tb = NULL;
313     exception_lineno = 0;
314  
315     // Preserve existing published exception.
316     exception_preserved_type_1 = EXC_TYPE(PyThreadState_GET());
317     Py_XINCREF( exception_preserved_type_1 );
318     exception_preserved_value_1 = EXC_VALUE(PyThreadState_GET());
319     Py_XINCREF( exception_preserved_value_1 );
320     exception_preserved_tb_1 = (PyTracebackObject *)EXC_TRACEBACK(PyThreadState_GET());
321     Py_XINCREF( exception_preserved_tb_1 );
322  
323     if ( exception_keeper_tb_1 == NULL )
324     {
325         exception_keeper_tb_1 = MAKE_TRACEBACK( frame_977d56a6116d6d7c558c35b3284a4d5e, exception_keeper_lineno_1 );
326     }
327     else if ( exception_keeper_lineno_1 != 0 )
328     {
329         exception_keeper_tb_1 = ADD_TRACEBACK( exception_keeper_tb_1, frame_977d56a6116d6d7c558c35b3284a4d5e, exception_keeper_lineno_1 );
330     }
331  
332     NORMALIZE_EXCEPTION( &exception_keeper_type_1, &exception_keeper_value_1, &exception_keeper_tb_1 );
333     PyException_SetTraceback( exception_keeper_value_1, (PyObject *)exception_keeper_tb_1 );
334     PUBLISH_EXCEPTION( &exception_keeper_type_1, &exception_keeper_value_1, &exception_keeper_tb_1 );
335     // Tried code:
336     {
337         nuitka_bool tmp_condition_result_1;
338         PyObject *tmp_operand_name_1;
339         PyObject *tmp_compexpr_left_1;
340         PyObject *tmp_compexpr_right_1;
341         tmp_compexpr_left_1 = EXC_TYPE(PyThreadState_GET());
342         tmp_compexpr_right_1 = PyExc_GeneratorExit;
343         tmp_res = EXCEPTION_MATCH_BOOL( tmp_compexpr_left_1, tmp_compexpr_right_1 );
344         if ( tmp_res == -1 )
345         {
346             assert( ERROR_OCCURRED() );
347  
348             FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
349  
350  
351             exception_lineno = 36;
352             type_description_1 = "oNo";
353             goto try_except_handler_4;
354         }
355         tmp_operand_name_1 = ( tmp_res != 0 ) ? Py_True : Py_False;
356         tmp_res = CHECK_IF_TRUE( tmp_operand_name_1 );
357         if ( tmp_res == -1 )
358         {
359             assert( ERROR_OCCURRED() );
360  
361             FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
362  
363  
364             exception_lineno = 36;
365             type_description_1 = "oNo";
366             goto try_except_handler_4;
367         }
368         tmp_condition_result_1 = ( tmp_res == 0 ) ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE;
369         if ( tmp_condition_result_1 == NUITKA_BOOL_TRUE )
370         {
371             goto branch_yes_1;
372         }
373         else
374         {
375             goto branch_no_1;
376         }
377         branch_yes_1:;
378         tmp_result = RERAISE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
379         if (unlikely( tmp_result == false ))
380         {
381             exception_lineno = 30;
382         }
383  
384         if (exception_tb && exception_tb->tb_frame == &frame_977d56a6116d6d7c558c35b3284a4d5e->m_frame) frame_977d56a6116d6d7c558c35b3284a4d5e->m_frame.f_lineno = exception_tb->tb_lineno;
385         type_description_1 = "oNo";
386         goto try_except_handler_4;
387         branch_no_1:;
388     }
389     goto try_end_2;
390     // Exception handler code:
391     try_except_handler_4:;
392     exception_keeper_type_2 = exception_type;
393     exception_keeper_value_2 = exception_value;
394     exception_keeper_tb_2 = exception_tb;
395     exception_keeper_lineno_2 = exception_lineno;
396     exception_type = NULL;
397     exception_value = NULL;
398     exception_tb = NULL;
399     exception_lineno = 0;
400  
401     // Restore previous exception.
402     SET_CURRENT_EXCEPTION( exception_preserved_type_1, exception_preserved_value_1, exception_preserved_tb_1 );
403     // Re-raise.
404     exception_type = exception_keeper_type_2;
405     exception_value = exception_keeper_value_2;
406     exception_tb = exception_keeper_tb_2;
407     exception_lineno = exception_keeper_lineno_2;
408  
409     goto frame_exception_exit_1;
410     // End of try:
411     try_end_2:;
412     // Restore previous exception.
413     SET_CURRENT_EXCEPTION( exception_preserved_type_1, exception_preserved_value_1, exception_preserved_tb_1 );
414     goto try_end_1;
415     // exception handler codes exits in all cases
416     NUITKA_CANNOT_GET_HERE( __main__$$$function_1_calledRepeatedly );
417     return NULL;
418     // End of try:
419     try_end_1:;
420 265
421 #if 0 266 #if 0
422     RESTORE_FRAME_EXCEPTION( frame_977d56a6116d6d7c558c35b3284a4d5e ); 267     RESTORE_FRAME_EXCEPTION( frame_977d56a6116d6d7c558c35b3284a4d5e );
423 #endif 268 #endif
424 269
494     var_throw = NULL; 339     var_throw = NULL;
495 340
496     goto function_return_exit; 341     goto function_return_exit;
497     // Exception handler code: 342     // Exception handler code:
498     try_except_handler_2:; 343     try_except_handler_2:;
n 499     exception_keeper_type_3 = exception_type; n 344     exception_keeper_type_1 = exception_type;
500     exception_keeper_value_3 = exception_value; 345     exception_keeper_value_1 = exception_value;
501     exception_keeper_tb_3 = exception_tb; 346     exception_keeper_tb_1 = exception_tb;
502     exception_keeper_lineno_3 = exception_lineno; 347     exception_keeper_lineno_1 = exception_lineno;
503     exception_type = NULL; 348     exception_type = NULL;
504     exception_value = NULL; 349     exception_value = NULL;
505     exception_tb = NULL; 350     exception_tb = NULL;
506     exception_lineno = 0; 351     exception_lineno = 0;
507 352
508     CHECK_OBJECT( (PyObject *)var_gen ); 353     CHECK_OBJECT( (PyObject *)var_gen );
509     Py_DECREF( var_gen ); 354     Py_DECREF( var_gen );
510     var_gen = NULL; 355     var_gen = NULL;
511 356
n 512     Py_XDECREF( var_throw ); n
513     var_throw = NULL;
514  
515     // Re-raise. 357     // Re-raise.
t 516     exception_type = exception_keeper_type_3; t 358     exception_type = exception_keeper_type_1;
517     exception_value = exception_keeper_value_3; 359     exception_value = exception_keeper_value_1;
518     exception_tb = exception_keeper_tb_3; 360     exception_tb = exception_keeper_tb_1;
519     exception_lineno = exception_keeper_lineno_3; 361     exception_lineno = exception_keeper_lineno_1;
520 362
521     goto function_exception_exit; 363     goto function_exception_exit;
522     // End of try: 364     // End of try:
523 365
524     // Return statement must have exited already. 366     // Return statement must have exited already.