Construct GeneratorExit

Performance Diagrams

Construct GeneratorExit 0040000000400000008000000080000000120000000120000000160000000160000000200000000200000000240000000240000000280000000280000000320000000320000000CPython 2.7Nuitka (master)Nuitka (develop)Nuitka (factory)34737831688.11538461538461257.0CPython 2.7163504050240.03846153846155387.803098151531Nuitka (master)164652818391.96153846153845386.98589617582144Nuitka (develop)164653722543.8846153846154386.9852530950723Nuitka (factory)Construct GeneratorExitTicks Construct GeneratorExit 0010000000100000002000000020000000300000003000000040000000400000005000000050000000600000006000000070000000700000008000000080000000CPython 3.5Nuitka (master)Nuitka (develop)Nuitka (factory)8307019888.95192307692307257.0CPython 3.566604287242.31730769230768305.9824272455411Nuitka (master)66053558395.6826923076923307.6207236735073Nuitka (develop)66055500549.0480769230769307.6149466549317Nuitka (factory)Construct GeneratorExitTicks

Source Code with Construct

def calledRepeatedly():
    # We measure making a generator iterator step or not.
    def generator():
        yield 1
        yield 2
        yield 3

    gen = generator()

    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.
    def generator():
        yield 1
        yield 2
        yield 3

    gen = generator()

    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
32     throw = gen.throw 32     throw = gen.throw
33     exc = GeneratorExit 33     exc = GeneratorExit
34 34
35     try: 35     try:
36 # construct_begin 36 # construct_begin
n 37         throw(exc) n 37  
38 # construct_alternative 38 # construct_alternative
t 39   t 39         pass
40   40 # construct_end
41     except exc: 41     except exc:
42         pass 42         pass
43 43
44     return throw, exc 44     return throw, exc
45 45

Context Diff of Generated Code


Construct
Baseline
54 static PyObject *const_str_plain_generator; 54 static PyObject *const_str_plain_generator;
55 static PyObject *const_str_plain_repeat; 55 static PyObject *const_str_plain_repeat;
56 static PyObject *const_int_pos_2; 56 static PyObject *const_int_pos_2;
57 static PyObject *const_tuple_none_int_pos_50000_tuple; 57 static PyObject *const_tuple_none_int_pos_50000_tuple;
58 extern PyObject *const_str_plain___main__; 58 extern PyObject *const_str_plain___main__;
n 59 static PyObject *const_tuple_type_GeneratorExit_tuple; n
60 extern PyObject *const_str_plain___doc__; 59 extern PyObject *const_str_plain___doc__;
61 extern PyObject *const_str_plain___cached__; 60 extern PyObject *const_str_plain___cached__;
62 static PyObject *module_filename_obj; 61 static PyObject *module_filename_obj;
63 62
64 static bool constants_created = false; 63 static bool constants_created = false;
88     const_str_plain_repeat = UNSTREAM_STRING_ASCII( &constant_bin[ 138 ], 6, 1 ); 87     const_str_plain_repeat = UNSTREAM_STRING_ASCII( &constant_bin[ 138 ], 6, 1 );
89     const_int_pos_2 = PyLong_FromUnsignedLong( 2ul ); 88     const_int_pos_2 = PyLong_FromUnsignedLong( 2ul );
90     const_tuple_none_int_pos_50000_tuple = PyTuple_New( 2 ); 89     const_tuple_none_int_pos_50000_tuple = PyTuple_New( 2 );
91     PyTuple_SET_ITEM( const_tuple_none_int_pos_50000_tuple, 0, Py_None ); Py_INCREF( Py_None ); 90     PyTuple_SET_ITEM( const_tuple_none_int_pos_50000_tuple, 0, Py_None ); Py_INCREF( Py_None );
92     PyTuple_SET_ITEM( const_tuple_none_int_pos_50000_tuple, 1, const_int_pos_50000 ); Py_INCREF( const_int_pos_50000 ); 91     PyTuple_SET_ITEM( const_tuple_none_int_pos_50000_tuple, 1, const_int_pos_50000 ); Py_INCREF( const_int_pos_50000 );
n 93     const_tuple_type_GeneratorExit_tuple = PyTuple_New( 1 ); n
94     PyTuple_SET_ITEM( const_tuple_type_GeneratorExit_tuple, 0, (PyObject *)PyExc_GeneratorExit ); Py_INCREF( (PyObject *)PyExc_GeneratorExit );
95 92
96     constants_created = true; 93     constants_created = true;
97 } 94 }
98 95
99 #ifndef __NUITKA_NO_ASSERT__ 96 #ifndef __NUITKA_NO_ASSERT__
148     NUITKA_MAY_BE_UNUSED char const *type_description_1 = NULL; 145     NUITKA_MAY_BE_UNUSED char const *type_description_1 = NULL;
149     PyObject *exception_type = NULL; 146     PyObject *exception_type = NULL;
150     PyObject *exception_value = NULL; 147     PyObject *exception_value = NULL;
151     PyTracebackObject *exception_tb = NULL; 148     PyTracebackObject *exception_tb = NULL;
152     NUITKA_MAY_BE_UNUSED int exception_lineno = 0; 149     NUITKA_MAY_BE_UNUSED int exception_lineno = 0;
n n 150     static struct Nuitka_FrameObject *cache_frame_78024a3785d29e7a1bdfddaa51b3cd95 = NULL;
151     PyObject *tmp_return_value = NULL;
153     PyObject *exception_keeper_type_1; 152     PyObject *exception_keeper_type_1;
154     PyObject *exception_keeper_value_1; 153     PyObject *exception_keeper_value_1;
155     PyTracebackObject *exception_keeper_tb_1; 154     PyTracebackObject *exception_keeper_tb_1;
156     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_1; 155     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_1;
n 157     PyObject *exception_preserved_type_1; n
158     PyObject *exception_preserved_value_1;
159     PyTracebackObject *exception_preserved_tb_1;
160     int tmp_res;
161     bool tmp_result;
162     PyObject *exception_keeper_type_2;
163     PyObject *exception_keeper_value_2;
164     PyTracebackObject *exception_keeper_tb_2;
165     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_2;
166     static struct Nuitka_FrameObject *cache_frame_78024a3785d29e7a1bdfddaa51b3cd95 = NULL;
167     PyObject *tmp_return_value = NULL;
168     PyObject *exception_keeper_type_3;
169     PyObject *exception_keeper_value_3;
170     PyTracebackObject *exception_keeper_tb_3;
171     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_3;
172 156
173     // Actual function code. 157     // Actual function code.
174     { 158     {
175     PyObject *tmp_assign_source_1; 159     PyObject *tmp_assign_source_1;
176     tmp_assign_source_1 = MAKE_FUNCTION___main__$$$function_1_calledRepeatedly$$$function_1_generator(  ); 160     tmp_assign_source_1 = MAKE_FUNCTION___main__$$$function_1_calledRepeatedly$$$function_1_generator(  );
261     } 245     }
262     assert( var_throw == NULL ); 246     assert( var_throw == NULL );
263     var_throw = tmp_assign_source_3; 247     var_throw = tmp_assign_source_3;
264 248
265     } 249     }
n 266     { n
267     // Tried code:
268     {
269     PyObject *tmp_called_name_2;
270     PyObject *tmp_call_result_1;
271     CHECK_OBJECT( var_throw );
272     tmp_called_name_2 = var_throw;
273     frame_78024a3785d29e7a1bdfddaa51b3cd95->m_frame.f_lineno = 37;
274     tmp_call_result_1 = CALL_FUNCTION_WITH_ARGS1( tmp_called_name_2, &PyTuple_GET_ITEM( const_tuple_type_GeneratorExit_tuple, 0 ) );
275  
276     if ( tmp_call_result_1 == NULL )
277     {
278         assert( ERROR_OCCURRED() );
279  
280         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
281  
282  
283         exception_lineno = 37;
284         type_description_1 = "oNoo";
285         goto try_except_handler_2;
286     }
287     Py_DECREF( tmp_call_result_1 );
288     }
289     goto try_end_1;
290     // Exception handler code:
291     try_except_handler_2:;
292     exception_keeper_type_1 = exception_type;
293     exception_keeper_value_1 = exception_value;
294     exception_keeper_tb_1 = exception_tb;
295     exception_keeper_lineno_1 = exception_lineno;
296     exception_type = NULL;
297     exception_value = NULL;
298     exception_tb = NULL;
299     exception_lineno = 0;
300  
301     {
302     // Preserve existing published exception.
303     exception_preserved_type_1 = EXC_TYPE(PyThreadState_GET());
304     Py_XINCREF( exception_preserved_type_1 );
305     exception_preserved_value_1 = EXC_VALUE(PyThreadState_GET());
306     Py_XINCREF( exception_preserved_value_1 );
307     exception_preserved_tb_1 = (PyTracebackObject *)EXC_TRACEBACK(PyThreadState_GET());
308     Py_XINCREF( exception_preserved_tb_1 );
309  
310     }
311     {
312     if ( exception_keeper_tb_1 == NULL )
313     {
314         exception_keeper_tb_1 = MAKE_TRACEBACK( frame_78024a3785d29e7a1bdfddaa51b3cd95, exception_keeper_lineno_1 );
315     }
316     else if ( exception_keeper_lineno_1 != 0 )
317     {
318         exception_keeper_tb_1 = ADD_TRACEBACK( exception_keeper_tb_1, frame_78024a3785d29e7a1bdfddaa51b3cd95, exception_keeper_lineno_1 );
319     }
320  
321     NORMALIZE_EXCEPTION( &exception_keeper_type_1, &exception_keeper_value_1, &exception_keeper_tb_1 );
322     PyException_SetTraceback( exception_keeper_value_1, (PyObject *)exception_keeper_tb_1 );
323     PUBLISH_EXCEPTION( &exception_keeper_type_1, &exception_keeper_value_1, &exception_keeper_tb_1 );
324     }
325     {
326     // Tried code:
327     {
328     nuitka_bool tmp_condition_result_1;
329     PyObject *tmp_operand_name_1;
330     PyObject *tmp_compexpr_left_1;
331     PyObject *tmp_compexpr_right_1;
332     tmp_compexpr_left_1 = EXC_TYPE(PyThreadState_GET());
333     tmp_compexpr_right_1 = PyExc_GeneratorExit;
334     tmp_res = EXCEPTION_MATCH_BOOL( tmp_compexpr_left_1, tmp_compexpr_right_1 );
335     if ( tmp_res == -1 )
336     {
337         assert( ERROR_OCCURRED() );
338  
339         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
340  
341  
342         exception_lineno = 41;
343         type_description_1 = "oNoo";
344         goto try_except_handler_3;
345     }
346     tmp_operand_name_1 = ( tmp_res != 0 ) ? Py_True : Py_False;
347     tmp_res = CHECK_IF_TRUE( tmp_operand_name_1 );
348     if ( tmp_res == -1 )
349     {
350         assert( ERROR_OCCURRED() );
351  
352         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
353  
354  
355         exception_lineno = 41;
356         type_description_1 = "oNoo";
357         goto try_except_handler_3;
358     }
359     tmp_condition_result_1 = ( tmp_res == 0 ) ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE;
360     if ( tmp_condition_result_1 == NUITKA_BOOL_TRUE )
361     {
362         goto branch_yes_1;
363     }
364     else
365     {
366         goto branch_no_1;
367     }
368     branch_yes_1:;
369     {
370     tmp_result = RERAISE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
371     if (unlikely( tmp_result == false ))
372     {
373         exception_lineno = 35;
374     }
375  
376     if (exception_tb && exception_tb->tb_frame == &frame_78024a3785d29e7a1bdfddaa51b3cd95->m_frame) frame_78024a3785d29e7a1bdfddaa51b3cd95->m_frame.f_lineno = exception_tb->tb_lineno;
377     type_description_1 = "oNoo";
378     goto try_except_handler_3;
379     }
380     branch_no_1:;
381     }
382     goto try_end_2;
383     // Exception handler code:
384     try_except_handler_3:;
385     exception_keeper_type_2 = exception_type;
386     exception_keeper_value_2 = exception_value;
387     exception_keeper_tb_2 = exception_tb;
388     exception_keeper_lineno_2 = exception_lineno;
389     exception_type = NULL;
390     exception_value = NULL;
391     exception_tb = NULL;
392     exception_lineno = 0;
393  
394     {
395     // Restore previous exception.
396     SET_CURRENT_EXCEPTION( exception_preserved_type_1, exception_preserved_value_1, exception_preserved_tb_1 );
397     }
398     {
399     // Re-raise.
400     exception_type = exception_keeper_type_2;
401     exception_value = exception_keeper_value_2;
402     exception_tb = exception_keeper_tb_2;
403     exception_lineno = exception_keeper_lineno_2;
404  
405     goto frame_exception_exit_1;
406     }
407     // End of try:
408     try_end_2:;
409     }
410     {
411     // Restore previous exception.
412     SET_CURRENT_EXCEPTION( exception_preserved_type_1, exception_preserved_value_1, exception_preserved_tb_1 );
413     }
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     }
421 250
422 #if 0 251 #if 0
423     RESTORE_FRAME_EXCEPTION( frame_78024a3785d29e7a1bdfddaa51b3cd95 ); 252     RESTORE_FRAME_EXCEPTION( frame_78024a3785d29e7a1bdfddaa51b3cd95 );
424 #endif 253 #endif
425 254
508     { 337     {
509     goto function_return_exit; 338     goto function_return_exit;
510     } 339     }
511     // Exception handler code: 340     // Exception handler code:
512     try_except_handler_1:; 341     try_except_handler_1:;
n 513     exception_keeper_type_3 = exception_type; n 342     exception_keeper_type_1 = exception_type;
514     exception_keeper_value_3 = exception_value; 343     exception_keeper_value_1 = exception_value;
515     exception_keeper_tb_3 = exception_tb; 344     exception_keeper_tb_1 = exception_tb;
516     exception_keeper_lineno_3 = exception_lineno; 345     exception_keeper_lineno_1 = exception_lineno;
517     exception_type = NULL; 346     exception_type = NULL;
518     exception_value = NULL; 347     exception_value = NULL;
519     exception_tb = NULL; 348     exception_tb = NULL;
520     exception_lineno = 0; 349     exception_lineno = 0;
521 350
523     Py_XDECREF( var_gen ); 352     Py_XDECREF( var_gen );
524     var_gen = NULL; 353     var_gen = NULL;
525 354
526     } 355     }
527     { 356     {
n 528     Py_XDECREF( var_throw ); n
529     var_throw = NULL;
530  
531     }
532     {
533     CHECK_OBJECT( (PyObject *)var_generator ); 357     CHECK_OBJECT( (PyObject *)var_generator );
534     Py_DECREF( var_generator ); 358     Py_DECREF( var_generator );
535     var_generator = NULL; 359     var_generator = NULL;
536 360
537     } 361     }
538     { 362     {
539     // Re-raise. 363     // Re-raise.
t 540     exception_type = exception_keeper_type_3; t 364     exception_type = exception_keeper_type_1;
541     exception_value = exception_keeper_value_3; 365     exception_value = exception_keeper_value_1;
542     exception_tb = exception_keeper_tb_3; 366     exception_tb = exception_keeper_tb_1;
543     exception_lineno = exception_keeper_lineno_3; 367     exception_lineno = exception_keeper_lineno_1;
544 368
545     goto function_exception_exit; 369     goto function_exception_exit;
546     } 370     }
547     // End of try: 371     // End of try:
548     } 372     }