Construct GeneratorExpressionExit

Performance Diagrams

Construct GeneratorExpressionExit 0040000000400000008000000080000000120000000120000000160000000160000000200000000200000000240000000240000000280000000280000000320000000320000000CPython 2.7Nuitka (master)Nuitka (develop)Nuitka (factory)34792867488.11538461538461257.0CPython 2.7164552847240.03846153846155387.2421772178203Nuitka (master)164552863391.96153846153845387.2421658538643Nuitka (develop)164552900543.8846153846154387.24213957471596Nuitka (factory)Construct GeneratorExpressionExitTicks Construct GeneratorExpressionExit 0010000000100000002000000020000000300000003000000040000000400000005000000050000000600000006000000070000000700000008000000080000000CPython 3.5Nuitka (master)Nuitka (develop)Nuitka (factory)8266870388.95192307692307257.0CPython 3.566458187242.31730769230768305.45688574736494Nuitka (master)65953972395.6826923076923306.96409801914626Nuitka (develop)65965298549.0480769230769306.93024205256415Nuitka (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
96     PyTuple_SET_ITEM( const_tuple_str_digest_b9c4baf879ebd882d40843df3a4dead7_str_plain_x_tuple, 0, const_str_digest_b9c4baf879ebd882d40843df3a4dead7 ); Py_INCREF( const_str_digest_b9c4baf879ebd882d40843df3a4dead7 ); 95     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, 1, const_str_plain_x ); Py_INCREF( const_str_plain_x ); 96     PyTuple_SET_ITEM( const_tuple_str_digest_b9c4baf879ebd882d40843df3a4dead7_str_plain_x_tuple, 1, const_str_plain_x ); Py_INCREF( const_str_plain_x );
98     const_tuple_none_int_pos_50000_tuple = PyTuple_New( 2 ); 97     const_tuple_none_int_pos_50000_tuple = PyTuple_New( 2 );
99     PyTuple_SET_ITEM( const_tuple_none_int_pos_50000_tuple, 0, Py_None ); Py_INCREF( Py_None ); 98     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, 1, const_int_pos_50000 ); Py_INCREF( const_int_pos_50000 ); 99     PyTuple_SET_ITEM( const_tuple_none_int_pos_50000_tuple, 1, const_int_pos_50000 ); Py_INCREF( const_int_pos_50000 );
n 101     const_tuple_type_GeneratorExit_tuple = PyTuple_New( 1 ); n
102     PyTuple_SET_ITEM( const_tuple_type_GeneratorExit_tuple, 0, (PyObject *)PyExc_GeneratorExit ); Py_INCREF( (PyObject *)PyExc_GeneratorExit );
103     const_str_plain___debug__ = UNSTREAM_STRING_ASCII( &constant_bin[ 149 ], 9, 1 ); 100     const_str_plain___debug__ = UNSTREAM_STRING_ASCII( &constant_bin[ 149 ], 9, 1 );
104 101
105     constants_created = true; 102     constants_created = true;
106 } 103 }
107 104
154     NUITKA_MAY_BE_UNUSED char const *type_description_1 = NULL; 151     NUITKA_MAY_BE_UNUSED char const *type_description_1 = NULL;
155     PyObject *exception_type = NULL; 152     PyObject *exception_type = NULL;
156     PyObject *exception_value = NULL; 153     PyObject *exception_value = NULL;
157     PyTracebackObject *exception_tb = NULL; 154     PyTracebackObject *exception_tb = NULL;
158     NUITKA_MAY_BE_UNUSED int exception_lineno = 0; 155     NUITKA_MAY_BE_UNUSED int exception_lineno = 0;
n n 156     static struct Nuitka_FrameObject *cache_frame_427d83fd069d9ff4e38163a5a88acfeb = NULL;
157     PyObject *tmp_return_value = NULL;
159     PyObject *exception_keeper_type_1; 158     PyObject *exception_keeper_type_1;
160     PyObject *exception_keeper_value_1; 159     PyObject *exception_keeper_value_1;
161     PyTracebackObject *exception_keeper_tb_1; 160     PyTracebackObject *exception_keeper_tb_1;
162     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_1; 161     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_1;
n 163     PyObject *exception_preserved_type_1; n
164     PyObject *exception_preserved_value_1;
165     PyTracebackObject *exception_preserved_tb_1;
166     int tmp_res;
167     bool tmp_result;
168     PyObject *exception_keeper_type_2;
169     PyObject *exception_keeper_value_2;
170     PyTracebackObject *exception_keeper_tb_2;
171     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_2;
172     static struct Nuitka_FrameObject *cache_frame_427d83fd069d9ff4e38163a5a88acfeb = NULL;
173     PyObject *tmp_return_value = NULL;
174     PyObject *exception_keeper_type_3;
175     PyObject *exception_keeper_value_3;
176     PyTracebackObject *exception_keeper_tb_3;
177     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_3;
178 162
179     // Actual function code. 163     // Actual function code.
180     { 164     {
181     PyObject *tmp_assign_source_1; 165     PyObject *tmp_assign_source_1;
182     { 166     {
287     } 271     }
288     assert( var_throw == NULL ); 272     assert( var_throw == NULL );
289     var_throw = tmp_assign_source_3; 273     var_throw = tmp_assign_source_3;
290 274
291     } 275     }
n 292     { n
293     // Tried code:
294     {
295     PyObject *tmp_called_name_1;
296     PyObject *tmp_call_result_1;
297     CHECK_OBJECT( var_throw );
298     tmp_called_name_1 = var_throw;
299     frame_427d83fd069d9ff4e38163a5a88acfeb->m_frame.f_lineno = 32;
300     tmp_call_result_1 = CALL_FUNCTION_WITH_ARGS1( tmp_called_name_1, &PyTuple_GET_ITEM( const_tuple_type_GeneratorExit_tuple, 0 ) );
301  
302     if ( tmp_call_result_1 == NULL )
303     {
304         assert( ERROR_OCCURRED() );
305  
306         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
307  
308  
309         exception_lineno = 32;
310         type_description_1 = "oNo";
311         goto try_except_handler_3;
312     }
313     Py_DECREF( tmp_call_result_1 );
314     }
315     goto try_end_1;
316     // Exception handler code:
317     try_except_handler_3:;
318     exception_keeper_type_1 = exception_type;
319     exception_keeper_value_1 = exception_value;
320     exception_keeper_tb_1 = exception_tb;
321     exception_keeper_lineno_1 = exception_lineno;
322     exception_type = NULL;
323     exception_value = NULL;
324     exception_tb = NULL;
325     exception_lineno = 0;
326  
327     {
328     // Preserve existing published exception.
329     exception_preserved_type_1 = EXC_TYPE(PyThreadState_GET());
330     Py_XINCREF( exception_preserved_type_1 );
331     exception_preserved_value_1 = EXC_VALUE(PyThreadState_GET());
332     Py_XINCREF( exception_preserved_value_1 );
333     exception_preserved_tb_1 = (PyTracebackObject *)EXC_TRACEBACK(PyThreadState_GET());
334     Py_XINCREF( exception_preserved_tb_1 );
335  
336     }
337     {
338     if ( exception_keeper_tb_1 == NULL )
339     {
340         exception_keeper_tb_1 = MAKE_TRACEBACK( frame_427d83fd069d9ff4e38163a5a88acfeb, exception_keeper_lineno_1 );
341     }
342     else if ( exception_keeper_lineno_1 != 0 )
343     {
344         exception_keeper_tb_1 = ADD_TRACEBACK( exception_keeper_tb_1, frame_427d83fd069d9ff4e38163a5a88acfeb, exception_keeper_lineno_1 );
345     }
346  
347     NORMALIZE_EXCEPTION( &exception_keeper_type_1, &exception_keeper_value_1, &exception_keeper_tb_1 );
348     PyException_SetTraceback( exception_keeper_value_1, (PyObject *)exception_keeper_tb_1 );
349     PUBLISH_EXCEPTION( &exception_keeper_type_1, &exception_keeper_value_1, &exception_keeper_tb_1 );
350     }
351     {
352     // Tried code:
353     {
354     nuitka_bool tmp_condition_result_1;
355     PyObject *tmp_operand_name_1;
356     PyObject *tmp_compexpr_left_1;
357     PyObject *tmp_compexpr_right_1;
358     tmp_compexpr_left_1 = EXC_TYPE(PyThreadState_GET());
359     tmp_compexpr_right_1 = PyExc_GeneratorExit;
360     tmp_res = EXCEPTION_MATCH_BOOL( tmp_compexpr_left_1, tmp_compexpr_right_1 );
361     if ( tmp_res == -1 )
362     {
363         assert( ERROR_OCCURRED() );
364  
365         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
366  
367  
368         exception_lineno = 36;
369         type_description_1 = "oNo";
370         goto try_except_handler_4;
371     }
372     tmp_operand_name_1 = ( tmp_res != 0 ) ? Py_True : Py_False;
373     tmp_res = CHECK_IF_TRUE( tmp_operand_name_1 );
374     if ( tmp_res == -1 )
375     {
376         assert( ERROR_OCCURRED() );
377  
378         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
379  
380  
381         exception_lineno = 36;
382         type_description_1 = "oNo";
383         goto try_except_handler_4;
384     }
385     tmp_condition_result_1 = ( tmp_res == 0 ) ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE;
386     if ( tmp_condition_result_1 == NUITKA_BOOL_TRUE )
387     {
388         goto branch_yes_1;
389     }
390     else
391     {
392         goto branch_no_1;
393     }
394     branch_yes_1:;
395     {
396     tmp_result = RERAISE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
397     if (unlikely( tmp_result == false ))
398     {
399         exception_lineno = 30;
400     }
401  
402     if (exception_tb && exception_tb->tb_frame == &frame_427d83fd069d9ff4e38163a5a88acfeb->m_frame) frame_427d83fd069d9ff4e38163a5a88acfeb->m_frame.f_lineno = exception_tb->tb_lineno;
403     type_description_1 = "oNo";
404     goto try_except_handler_4;
405     }
406     branch_no_1:;
407     }
408     goto try_end_2;
409     // Exception handler code:
410     try_except_handler_4:;
411     exception_keeper_type_2 = exception_type;
412     exception_keeper_value_2 = exception_value;
413     exception_keeper_tb_2 = exception_tb;
414     exception_keeper_lineno_2 = exception_lineno;
415     exception_type = NULL;
416     exception_value = NULL;
417     exception_tb = NULL;
418     exception_lineno = 0;
419  
420     {
421     // Restore previous exception.
422     SET_CURRENT_EXCEPTION( exception_preserved_type_1, exception_preserved_value_1, exception_preserved_tb_1 );
423     }
424     {
425     // Re-raise.
426     exception_type = exception_keeper_type_2;
427     exception_value = exception_keeper_value_2;
428     exception_tb = exception_keeper_tb_2;
429     exception_lineno = exception_keeper_lineno_2;
430  
431     goto frame_exception_exit_1;
432     }
433     // End of try:
434     try_end_2:;
435     }
436     {
437     // Restore previous exception.
438     SET_CURRENT_EXCEPTION( exception_preserved_type_1, exception_preserved_value_1, exception_preserved_tb_1 );
439     }
440     goto try_end_1;
441     // exception handler codes exits in all cases
442     NUITKA_CANNOT_GET_HERE( __main__$$$function_1_calledRepeatedly );
443     return NULL;
444     // End of try:
445     try_end_1:;
446     }
447 276
448 #if 0 277 #if 0
449     RESTORE_FRAME_EXCEPTION( frame_427d83fd069d9ff4e38163a5a88acfeb ); 278     RESTORE_FRAME_EXCEPTION( frame_427d83fd069d9ff4e38163a5a88acfeb );
450 #endif 279 #endif
451 280
527     { 356     {
528     goto function_return_exit; 357     goto function_return_exit;
529     } 358     }
530     // Exception handler code: 359     // Exception handler code:
531     try_except_handler_2:; 360     try_except_handler_2:;
n 532     exception_keeper_type_3 = exception_type; n 361     exception_keeper_type_1 = exception_type;
533     exception_keeper_value_3 = exception_value; 362     exception_keeper_value_1 = exception_value;
534     exception_keeper_tb_3 = exception_tb; 363     exception_keeper_tb_1 = exception_tb;
535     exception_keeper_lineno_3 = exception_lineno; 364     exception_keeper_lineno_1 = exception_lineno;
536     exception_type = NULL; 365     exception_type = NULL;
537     exception_value = NULL; 366     exception_value = NULL;
538     exception_tb = NULL; 367     exception_tb = NULL;
539     exception_lineno = 0; 368     exception_lineno = 0;
540 369
543     Py_DECREF( var_gen ); 372     Py_DECREF( var_gen );
544     var_gen = NULL; 373     var_gen = NULL;
545 374
546     } 375     }
547     { 376     {
n 548     Py_XDECREF( var_throw ); n
549     var_throw = NULL;
550  
551     }
552     {
553     // Re-raise. 377     // Re-raise.
t 554     exception_type = exception_keeper_type_3; t 378     exception_type = exception_keeper_type_1;
555     exception_value = exception_keeper_value_3; 379     exception_value = exception_keeper_value_1;
556     exception_tb = exception_keeper_tb_3; 380     exception_tb = exception_keeper_tb_1;
557     exception_lineno = exception_keeper_lineno_3; 381     exception_lineno = exception_keeper_lineno_1;
558 382
559     goto function_exception_exit; 383     goto function_exception_exit;
560     } 384     }
561     // End of try: 385     // End of try:
562     } 386     }