Construct GeneratorExpressionExit

Performance Diagrams

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