Construct GeneratorExpressionExit

Performance Diagrams

Construct GeneratorExpressionExit 0040000000400000008000000080000000120000000120000000160000000160000000200000000200000000240000000240000000280000000280000000320000000320000000CPython 2.7Nuitka (master)Nuitka (develop)Nuitka (factory)33522108388.11538461538461257.0CPython 2.7159653039240.03846153846155386.42373531807596Nuitka (master)159652197391.96153846153845386.4243560163685Nuitka (develop)159652203543.8846153846154386.4243515933403Nuitka (factory)Construct GeneratorExpressionExitTicks Construct GeneratorExpressionExit 0010000000100000002000000020000000300000003000000040000000400000005000000050000000600000006000000070000000700000008000000080000000CPython 3.5Nuitka (master)Nuitka (develop)Nuitka (factory)8107043388.95192307692307257.0CPython 3.566053108242.31730769230768302.7751600175767Nuitka (master)66053259395.6826923076923302.774699745913Nuitka (develop)66053335549.0480769230769302.77446808600274Nuitka (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
56 static PyObject *const_str_digest_5ed1392909ad16e6227b8230f4582352; 56 static PyObject *const_str_digest_5ed1392909ad16e6227b8230f4582352;
57 static PyObject *const_str_plain_repeat; 57 static PyObject *const_str_plain_repeat;
58 static PyObject *const_str_digest_ba6833b423b08511065f3940227d2ef0; 58 static PyObject *const_str_digest_ba6833b423b08511065f3940227d2ef0;
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;
n 61 static PyObject *const_tuple_type_GeneratorExit_tuple; n
62 extern PyObject *const_str_plain___doc__; 61 extern PyObject *const_str_plain___doc__;
63 extern PyObject *const_str_plain___cached__; 62 extern PyObject *const_str_plain___cached__;
64 static PyObject *const_str_plain___debug__; 63 static PyObject *const_str_plain___debug__;
65 static PyObject *module_filename_obj; 64 static PyObject *module_filename_obj;
66 65
97     PyTuple_SET_ITEM( const_tuple_str_digest_b9c4baf879ebd882d40843df3a4dead7_str_plain_x_tuple, 0, const_str_digest_b9c4baf879ebd882d40843df3a4dead7 ); Py_INCREF(const_str_digest_b9c4baf879ebd882d40843df3a4dead7); 96     PyTuple_SET_ITEM( const_tuple_str_digest_b9c4baf879ebd882d40843df3a4dead7_str_plain_x_tuple, 0, const_str_digest_b9c4baf879ebd882d40843df3a4dead7 ); Py_INCREF(const_str_digest_b9c4baf879ebd882d40843df3a4dead7);
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_tuple_none_int_pos_50000_tuple = PyTuple_New( 2 ); 98     const_tuple_none_int_pos_50000_tuple = PyTuple_New( 2 );
100     PyTuple_SET_ITEM( const_tuple_none_int_pos_50000_tuple, 0, Py_None ); Py_INCREF(Py_None); 99     PyTuple_SET_ITEM( const_tuple_none_int_pos_50000_tuple, 0, Py_None ); Py_INCREF(Py_None);
101     PyTuple_SET_ITEM( const_tuple_none_int_pos_50000_tuple, 1, const_int_pos_50000 ); Py_INCREF(const_int_pos_50000); 100     PyTuple_SET_ITEM( const_tuple_none_int_pos_50000_tuple, 1, const_int_pos_50000 ); Py_INCREF(const_int_pos_50000);
n 102     const_tuple_type_GeneratorExit_tuple = PyTuple_New( 1 ); n
103     PyTuple_SET_ITEM( const_tuple_type_GeneratorExit_tuple, 0, (PyObject *)PyExc_GeneratorExit ); Py_INCREF((PyObject *)PyExc_GeneratorExit);
104     const_str_plain___debug__ = UNSTREAM_STRING_ASCII( &constant_bin[ 161 ], 9, 1 ); 101     const_str_plain___debug__ = UNSTREAM_STRING_ASCII( &constant_bin[ 161 ], 9, 1 );
105 102
106     constants_created = true; 103     constants_created = true;
107 } 104 }
108 105
155     NUITKA_MAY_BE_UNUSED char const *type_description_1 = NULL; 152     NUITKA_MAY_BE_UNUSED char const *type_description_1 = NULL;
156     PyObject *exception_type = NULL; 153     PyObject *exception_type = NULL;
157     PyObject *exception_value = NULL; 154     PyObject *exception_value = NULL;
158     PyTracebackObject *exception_tb = NULL; 155     PyTracebackObject *exception_tb = NULL;
159     NUITKA_MAY_BE_UNUSED int exception_lineno = 0; 156     NUITKA_MAY_BE_UNUSED int exception_lineno = 0;
n n 157     static struct Nuitka_FrameObject *cache_frame_f71679fa313cc149e76d90e1362249dc = NULL;
158     PyObject *tmp_return_value = NULL;
160     PyObject *exception_keeper_type_1; 159     PyObject *exception_keeper_type_1;
161     PyObject *exception_keeper_value_1; 160     PyObject *exception_keeper_value_1;
162     PyTracebackObject *exception_keeper_tb_1; 161     PyTracebackObject *exception_keeper_tb_1;
163     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_1; 162     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_1;
n 164     PyObject *exception_preserved_type_1; n
165     PyObject *exception_preserved_value_1;
166     PyTracebackObject *exception_preserved_tb_1;
167     int tmp_res;
168     bool tmp_result;
169     PyObject *exception_keeper_type_2;
170     PyObject *exception_keeper_value_2;
171     PyTracebackObject *exception_keeper_tb_2;
172     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_2;
173     static struct Nuitka_FrameObject *cache_frame_f71679fa313cc149e76d90e1362249dc = NULL;
174     PyObject *tmp_return_value = NULL;
175     PyObject *exception_keeper_type_3;
176     PyObject *exception_keeper_value_3;
177     PyTracebackObject *exception_keeper_tb_3;
178     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_3;
179 163
180     // Actual function body. 164     // Actual function body.
181     { 165     {
182         PyObject *tmp_assign_source_1; 166         PyObject *tmp_assign_source_1;
183         { 167         {
271             goto frame_exception_exit_1; 255             goto frame_exception_exit_1;
272         } 256         }
273         assert(var_throw == NULL); 257         assert(var_throw == NULL);
274         var_throw = tmp_assign_source_3; 258         var_throw = tmp_assign_source_3;
275     } 259     }
n 276     // Tried code: n
277     {
278         PyObject *tmp_called_name_1;
279         PyObject *tmp_call_result_1;
280         CHECK_OBJECT(var_throw);
281         tmp_called_name_1 = var_throw;
282         frame_f71679fa313cc149e76d90e1362249dc->m_frame.f_lineno = 32;
283         tmp_call_result_1 = CALL_FUNCTION_WITH_ARGS1( tmp_called_name_1, &PyTuple_GET_ITEM( const_tuple_type_GeneratorExit_tuple, 0 ) );
284  
285         if ( tmp_call_result_1 == NULL )
286         {
287             assert(ERROR_OCCURRED());
288  
289             FETCH_ERROR_OCCURRED(&exception_type, &exception_value, &exception_tb);
290  
291  
292             exception_lineno = 32;
293             type_description_1 = "oNo";
294             goto try_except_handler_3;
295         }
296         Py_DECREF(tmp_call_result_1);
297     }
298     goto try_end_1;
299     // Exception handler code:
300     try_except_handler_3:;
301     exception_keeper_type_1 = exception_type;
302     exception_keeper_value_1 = exception_value;
303     exception_keeper_tb_1 = exception_tb;
304     exception_keeper_lineno_1 = exception_lineno;
305     exception_type = NULL;
306     exception_value = NULL;
307     exception_tb = NULL;
308     exception_lineno = 0;
309  
310     // Preserve existing published exception.
311     exception_preserved_type_1 = EXC_TYPE(PyThreadState_GET());
312     Py_XINCREF(exception_preserved_type_1);
313     exception_preserved_value_1 = EXC_VALUE(PyThreadState_GET());
314     Py_XINCREF(exception_preserved_value_1);
315     exception_preserved_tb_1 = (PyTracebackObject *)EXC_TRACEBACK(PyThreadState_GET());
316     Py_XINCREF(exception_preserved_tb_1);
317  
318     if ( exception_keeper_tb_1 == NULL ) {
319         exception_keeper_tb_1 = MAKE_TRACEBACK( frame_f71679fa313cc149e76d90e1362249dc, exception_keeper_lineno_1 );
320     }
321     else if ( exception_keeper_lineno_1 != 0 ) {
322         exception_keeper_tb_1 = ADD_TRACEBACK(exception_keeper_tb_1, frame_f71679fa313cc149e76d90e1362249dc, exception_keeper_lineno_1);
323     }
324  
325     NORMALIZE_EXCEPTION( &exception_keeper_type_1, &exception_keeper_value_1, &exception_keeper_tb_1 );
326     PyException_SetTraceback( exception_keeper_value_1, (PyObject *)exception_keeper_tb_1 );
327     PUBLISH_EXCEPTION( &exception_keeper_type_1, &exception_keeper_value_1, &exception_keeper_tb_1 );
328     // Tried code:
329     {
330         nuitka_bool tmp_condition_result_1;
331         PyObject *tmp_operand_name_1;
332         PyObject *tmp_compexpr_left_1;
333         PyObject *tmp_compexpr_right_1;
334         tmp_compexpr_left_1 = EXC_TYPE(PyThreadState_GET());
335         tmp_compexpr_right_1 = PyExc_GeneratorExit;
336         tmp_res = EXCEPTION_MATCH_BOOL( tmp_compexpr_left_1, tmp_compexpr_right_1 );
337         if ( tmp_res == -1 )
338         {
339             assert(ERROR_OCCURRED());
340  
341             FETCH_ERROR_OCCURRED(&exception_type, &exception_value, &exception_tb);
342  
343  
344             exception_lineno = 36;
345             type_description_1 = "oNo";
346             goto try_except_handler_4;
347         }
348         tmp_operand_name_1 = ( tmp_res != 0 ) ? Py_True : Py_False;
349         tmp_res = CHECK_IF_TRUE( tmp_operand_name_1 );
350         if ( tmp_res == -1 )
351         {
352             assert(ERROR_OCCURRED());
353  
354             FETCH_ERROR_OCCURRED(&exception_type, &exception_value, &exception_tb);
355  
356  
357             exception_lineno = 36;
358             type_description_1 = "oNo";
359             goto try_except_handler_4;
360         }
361         tmp_condition_result_1 = ( tmp_res == 0 ) ? NUITKA_BOOL_TRUE : NUITKA_BOOL_FALSE;
362         if (tmp_condition_result_1 == NUITKA_BOOL_TRUE)
363         {
364             goto branch_yes_1;
365         } else {
366             goto branch_no_1;
367         }
368         branch_yes_1:;
369         tmp_result = RERAISE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
370         if (unlikely( tmp_result == false ))
371         {
372             exception_lineno = 30;
373         }
374  
375         if (exception_tb && exception_tb->tb_frame == &frame_f71679fa313cc149e76d90e1362249dc->m_frame) frame_f71679fa313cc149e76d90e1362249dc->m_frame.f_lineno = exception_tb->tb_lineno;
376         type_description_1 = "oNo";
377         goto try_except_handler_4;
378         branch_no_1:;
379     }
380     goto try_end_2;
381     // Exception handler code:
382     try_except_handler_4:;
383     exception_keeper_type_2 = exception_type;
384     exception_keeper_value_2 = exception_value;
385     exception_keeper_tb_2 = exception_tb;
386     exception_keeper_lineno_2 = exception_lineno;
387     exception_type = NULL;
388     exception_value = NULL;
389     exception_tb = NULL;
390     exception_lineno = 0;
391  
392     // Restore previous exception.
393     SET_CURRENT_EXCEPTION( exception_preserved_type_1, exception_preserved_value_1, exception_preserved_tb_1 );
394     // Re-raise.
395     exception_type = exception_keeper_type_2;
396     exception_value = exception_keeper_value_2;
397     exception_tb = exception_keeper_tb_2;
398     exception_lineno = exception_keeper_lineno_2;
399  
400     goto frame_exception_exit_1;
401     // End of try:
402     try_end_2:;
403     // Restore previous exception.
404     SET_CURRENT_EXCEPTION( exception_preserved_type_1, exception_preserved_value_1, exception_preserved_tb_1 );
405     goto try_end_1;
406     // exception handler codes exits in all cases
407     NUITKA_CANNOT_GET_HERE(__main__$$$function_1_calledRepeatedly);
408     return NULL;
409     // End of try:
410     try_end_1:;
411 260
412 #if 0 261 #if 0
413     RESTORE_FRAME_EXCEPTION(frame_f71679fa313cc149e76d90e1362249dc); 262     RESTORE_FRAME_EXCEPTION(frame_f71679fa313cc149e76d90e1362249dc);
414 #endif 263 #endif
415 264
482     var_throw = NULL; 331     var_throw = NULL;
483 332
484     goto function_return_exit; 333     goto function_return_exit;
485     // Exception handler code: 334     // Exception handler code:
486     try_except_handler_2:; 335     try_except_handler_2:;
n 487     exception_keeper_type_3 = exception_type; n 336     exception_keeper_type_1 = exception_type;
488     exception_keeper_value_3 = exception_value; 337     exception_keeper_value_1 = exception_value;
489     exception_keeper_tb_3 = exception_tb; 338     exception_keeper_tb_1 = exception_tb;
490     exception_keeper_lineno_3 = exception_lineno; 339     exception_keeper_lineno_1 = exception_lineno;
491     exception_type = NULL; 340     exception_type = NULL;
492     exception_value = NULL; 341     exception_value = NULL;
493     exception_tb = NULL; 342     exception_tb = NULL;
494     exception_lineno = 0; 343     exception_lineno = 0;
495 344
496     CHECK_OBJECT((PyObject *)var_gen); 345     CHECK_OBJECT((PyObject *)var_gen);
497     Py_DECREF(var_gen); 346     Py_DECREF(var_gen);
498     var_gen = NULL; 347     var_gen = NULL;
499 348
n 500     Py_XDECREF(var_throw); n
501     var_throw = NULL;
502  
503     // Re-raise. 349     // Re-raise.
t 504     exception_type = exception_keeper_type_3; t 350     exception_type = exception_keeper_type_1;
505     exception_value = exception_keeper_value_3; 351     exception_value = exception_keeper_value_1;
506     exception_tb = exception_keeper_tb_3; 352     exception_tb = exception_keeper_tb_1;
507     exception_lineno = exception_keeper_lineno_3; 353     exception_lineno = exception_keeper_lineno_1;
508 354
509     goto function_exception_exit; 355     goto function_exception_exit;
510     // End of try: 356     // End of try:
511 357
512     // Return statement must have exited already. 358     // Return statement must have exited already.