Construct UnpackIterator

Performance Diagrams

Construct UnpackIterator 0010000001000000200000020000003000000300000040000004000000500000050000006000000600000070000007000000800000080000009000000900000010000000100000001100000011000000CPython 2.7Nuitka (master)Nuitka (develop)Nuitka (factory)1119982988.95192307692307257.0CPython 2.76299218242.31730769230768365.12811268059403Nuitka (master)6299292395.6826923076923365.1264799290171Nuitka (develop)6305444549.0480769230769364.9907409060236Nuitka (factory)Construct UnpackIteratorTicks Construct UnpackIterator 001000000100000020000002000000300000030000004000000400000050000005000000600000060000007000000700000080000008000000900000090000001000000010000000CPython 3.5Nuitka (master)Nuitka (develop)Nuitka (factory)1013956788.95192307692307257.0CPython 3.57050988242.31730769230768332.2729764002743Nuitka (master)7050360395.6826923076923332.28828163584683Nuitka (develop)7050428549.0480769230769332.2866243810396Nuitka (factory)Construct UnpackIteratorTicks

Source Code with Construct

module_var = 1
range_arg = 2

def calledRepeatedly():
    global module_var
    c = module_var

    iterator=iter(range(range_arg))

# construct_begin
    a, b = iterator
# construct_alternative




    return a, b

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

print("OK.")

Source Code without Construct

module_var = 1
range_arg = 2

def calledRepeatedly():
    global module_var
    c = module_var

    iterator=iter(range(range_arg))

# construct_begin

# construct_alternative
    a = c
    b = c
# construct_end

    return a, b

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

print("OK.")

Context Diff of Source Code


Construct
Baseline
25     c = module_var 25     c = module_var
26 26
27     iterator=iter(range(range_arg)) 27     iterator=iter(range(range_arg))
28 28
29 # construct_begin 29 # construct_begin
n 30     a, b = iterator n 30  
31 # construct_alternative 31 # construct_alternative
t 32   t 32     a = c
33   33     b = c
34   34 # construct_end
35 35
36     return a, b 36     return a, b
37 37
38 import itertools 38 import itertools
39 for x in itertools.repeat(None, 50000): 39 for x in itertools.repeat(None, 50000):

Context Diff of Generated Code


Construct
Baseline
133     // Local variable declarations. 133     // Local variable declarations.
134     PyObject *var_a = NULL; 134     PyObject *var_a = NULL;
135     PyObject *var_b = NULL; 135     PyObject *var_b = NULL;
136     PyObject *var_c = NULL; 136     PyObject *var_c = NULL;
137     PyObject *var_iterator = NULL; 137     PyObject *var_iterator = NULL;
n 138     PyObject *tmp_tuple_unpack_1__element_1 = NULL; n
139     PyObject *tmp_tuple_unpack_1__element_2 = NULL;
140     PyObject *tmp_tuple_unpack_1__source_iter = NULL;
141     struct Nuitka_FrameObject *frame_75a0e05266557eb24254cddb07a8349a; 138     struct Nuitka_FrameObject *frame_75a0e05266557eb24254cddb07a8349a;
142     NUITKA_MAY_BE_UNUSED char const *type_description_1 = NULL; 139     NUITKA_MAY_BE_UNUSED char const *type_description_1 = NULL;
143     PyObject *exception_type = NULL; 140     PyObject *exception_type = NULL;
144     PyObject *exception_value = NULL; 141     PyObject *exception_value = NULL;
145     PyTracebackObject *exception_tb = NULL; 142     PyTracebackObject *exception_tb = NULL;
146     NUITKA_MAY_BE_UNUSED int exception_lineno = 0; 143     NUITKA_MAY_BE_UNUSED int exception_lineno = 0;
n 147     PyObject *tmp_iterator_attempt; n 144     static struct Nuitka_FrameObject *cache_frame_75a0e05266557eb24254cddb07a8349a = NULL;
145     PyObject *tmp_return_value = NULL;
148     PyObject *exception_keeper_type_1; 146     PyObject *exception_keeper_type_1;
149     PyObject *exception_keeper_value_1; 147     PyObject *exception_keeper_value_1;
150     PyTracebackObject *exception_keeper_tb_1; 148     PyTracebackObject *exception_keeper_tb_1;
151     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_1; 149     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_1;
n 152     PyObject *exception_keeper_type_2; n
153     PyObject *exception_keeper_value_2;
154     PyTracebackObject *exception_keeper_tb_2;
155     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_2;
156     PyObject *tmp_return_value = NULL;
157     static struct Nuitka_FrameObject *cache_frame_75a0e05266557eb24254cddb07a8349a = NULL;
158     PyObject *exception_keeper_type_3;
159     PyObject *exception_keeper_value_3;
160     PyTracebackObject *exception_keeper_tb_3;
161     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_3;
162 150
163     // Actual function code. 151     // Actual function code.
164     { 152     {
165     // Tried code: 153     // Tried code:
166     MAKE_OR_REUSE_FRAME( cache_frame_75a0e05266557eb24254cddb07a8349a, codeobj_75a0e05266557eb24254cddb07a8349a, module___main__, sizeof(void *)+sizeof(void *)+sizeof(void *)+sizeof(void *) ); 154     MAKE_OR_REUSE_FRAME( cache_frame_75a0e05266557eb24254cddb07a8349a, codeobj_75a0e05266557eb24254cddb07a8349a, module___main__, sizeof(void *)+sizeof(void *)+sizeof(void *)+sizeof(void *) );
259     } 247     }
260     assert( var_iterator == NULL ); 248     assert( var_iterator == NULL );
261     var_iterator = tmp_assign_source_2; 249     var_iterator = tmp_assign_source_2;
262 250
263     } 251     }
n 264     { n
265     // Tried code:
266     {
267     PyObject *tmp_assign_source_3;
268     PyObject *tmp_iter_arg_2;
269     CHECK_OBJECT( var_iterator );
270     tmp_iter_arg_2 = var_iterator;
271     tmp_assign_source_3 = MAKE_ITERATOR( tmp_iter_arg_2 );
272     if ( tmp_assign_source_3 == NULL )
273     {
274         assert( ERROR_OCCURRED() );
275  
276         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
277  
278  
279         exception_lineno = 30;
280         type_description_1 = "oooo";
281         goto try_except_handler_2;
282     }
283     assert( tmp_tuple_unpack_1__source_iter == NULL );
284     tmp_tuple_unpack_1__source_iter = tmp_assign_source_3;
285  
286     }
287     {
288     // Tried code:
289     {
290     PyObject *tmp_assign_source_4;
291     PyObject *tmp_unpack_1;
292     CHECK_OBJECT( tmp_tuple_unpack_1__source_iter );
293     tmp_unpack_1 = tmp_tuple_unpack_1__source_iter;
294     tmp_assign_source_4 = UNPACK_NEXT( tmp_unpack_1, 0, 2 );
295     if ( tmp_assign_source_4 == NULL )
296     {
297         if ( !ERROR_OCCURRED() )
298         {
299             exception_type = PyExc_StopIteration;
300             Py_INCREF( exception_type );
301             exception_value = NULL;
302             exception_tb = NULL;
303         }
304         else
305         {
306             FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
307         }
308  
309  
310         type_description_1 = "oooo";
311         exception_lineno = 30;
312         goto try_except_handler_3;
313     }
314     assert( tmp_tuple_unpack_1__element_1 == NULL );
315     tmp_tuple_unpack_1__element_1 = tmp_assign_source_4;
316  
317     }
318     {
319     PyObject *tmp_assign_source_5;
320     PyObject *tmp_unpack_2;
321     CHECK_OBJECT( tmp_tuple_unpack_1__source_iter );
322     tmp_unpack_2 = tmp_tuple_unpack_1__source_iter;
323     tmp_assign_source_5 = UNPACK_NEXT( tmp_unpack_2, 1, 2 );
324     if ( tmp_assign_source_5 == NULL )
325     {
326         if ( !ERROR_OCCURRED() )
327         {
328             exception_type = PyExc_StopIteration;
329             Py_INCREF( exception_type );
330             exception_value = NULL;
331             exception_tb = NULL;
332         }
333         else
334         {
335             FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
336         }
337  
338  
339         type_description_1 = "oooo";
340         exception_lineno = 30;
341         goto try_except_handler_3;
342     }
343     assert( tmp_tuple_unpack_1__element_2 == NULL );
344     tmp_tuple_unpack_1__element_2 = tmp_assign_source_5;
345  
346     }
347     {
348     PyObject *tmp_iterator_name_1;
349     CHECK_OBJECT( tmp_tuple_unpack_1__source_iter );
350     tmp_iterator_name_1 = tmp_tuple_unpack_1__source_iter;
351     // Check if iterator has left-over elements.
352     CHECK_OBJECT( tmp_iterator_name_1 ); assert( HAS_ITERNEXT( tmp_iterator_name_1 ) );
353  
354     tmp_iterator_attempt = (*Py_TYPE( tmp_iterator_name_1 )->tp_iternext)( tmp_iterator_name_1 );
355  
356     if (likely( tmp_iterator_attempt == NULL ))
357     {
358         PyObject *error = GET_ERROR_OCCURRED();
359  
360         if ( error != NULL )
361         {
362             if ( EXCEPTION_MATCH_BOOL_SINGLE( error, PyExc_StopIteration ))
363             {
364                 CLEAR_ERROR_OCCURRED();
365             }
366             else
367             {
368                 FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
369  
370                 type_description_1 = "oooo";
371                 exception_lineno = 30;
372                 goto try_except_handler_3;
373             }
374         }
375     }
376     else
377     {
378         Py_DECREF( tmp_iterator_attempt );
379  
380         // TODO: Could avoid PyErr_Format.
381 #if PYTHON_VERSION < 300
382         PyErr_Format( PyExc_ValueError, "too many values to unpack" );
383 #else
384         PyErr_Format( PyExc_ValueError, "too many values to unpack (expected 2)" );
385 #endif
386         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
387  
388         type_description_1 = "oooo";
389         exception_lineno = 30;
390         goto try_except_handler_3;
391     }
392     }
393     goto try_end_1;
394     // Exception handler code:
395     try_except_handler_3:;
396     exception_keeper_type_1 = exception_type;
397     exception_keeper_value_1 = exception_value;
398     exception_keeper_tb_1 = exception_tb;
399     exception_keeper_lineno_1 = exception_lineno;
400     exception_type = NULL;
401     exception_value = NULL;
402     exception_tb = NULL;
403     exception_lineno = 0;
404  
405     {
406     CHECK_OBJECT( (PyObject *)tmp_tuple_unpack_1__source_iter );
407     Py_DECREF( tmp_tuple_unpack_1__source_iter );
408     tmp_tuple_unpack_1__source_iter = NULL;
409  
410     }
411     {
412     // Re-raise.
413     exception_type = exception_keeper_type_1;
414     exception_value = exception_keeper_value_1;
415     exception_tb = exception_keeper_tb_1;
416     exception_lineno = exception_keeper_lineno_1;
417  
418     goto try_except_handler_2;
419     }
420     // End of try:
421     try_end_1:;
422     }
423     goto try_end_2;
424     // Exception handler code:
425     try_except_handler_2:;
426     exception_keeper_type_2 = exception_type;
427     exception_keeper_value_2 = exception_value;
428     exception_keeper_tb_2 = exception_tb;
429     exception_keeper_lineno_2 = exception_lineno;
430     exception_type = NULL;
431     exception_value = NULL;
432     exception_tb = NULL;
433     exception_lineno = 0;
434  
435     {
436     Py_XDECREF( tmp_tuple_unpack_1__element_1 );
437     tmp_tuple_unpack_1__element_1 = NULL;
438  
439     }
440     {
441     Py_XDECREF( tmp_tuple_unpack_1__element_2 );
442     tmp_tuple_unpack_1__element_2 = NULL;
443  
444     }
445     {
446     // Re-raise.
447     exception_type = exception_keeper_type_2;
448     exception_value = exception_keeper_value_2;
449     exception_tb = exception_keeper_tb_2;
450     exception_lineno = exception_keeper_lineno_2;
451  
452     goto frame_exception_exit_1;
453     }
454     // End of try:
455     try_end_2:;
456     }
457     {
458     CHECK_OBJECT( (PyObject *)tmp_tuple_unpack_1__source_iter );
459     Py_DECREF( tmp_tuple_unpack_1__source_iter );
460     tmp_tuple_unpack_1__source_iter = NULL;
461  
462     }
463     {
464     PyObject *tmp_assign_source_6;
465     CHECK_OBJECT( tmp_tuple_unpack_1__element_1 );
466     tmp_assign_source_6 = tmp_tuple_unpack_1__element_1;
467     assert( var_a == NULL );
468     Py_INCREF( tmp_assign_source_6 );
469     var_a = tmp_assign_source_6;
470  
471     }
472     {
473     Py_XDECREF( tmp_tuple_unpack_1__element_1 );
474     tmp_tuple_unpack_1__element_1 = NULL;
475  
476     }
477     {
478     PyObject *tmp_assign_source_7;
479     CHECK_OBJECT( tmp_tuple_unpack_1__element_2 );
480     tmp_assign_source_7 = tmp_tuple_unpack_1__element_2;
481     assert( var_b == NULL );
482     Py_INCREF( tmp_assign_source_7 );
483     var_b = tmp_assign_source_7;
484  
485     }
486     {
487     Py_XDECREF( tmp_tuple_unpack_1__element_2 );
488     tmp_tuple_unpack_1__element_2 = NULL;
489  
490     }
491     {
492     PyObject *tmp_tuple_element_1;
493     if ( var_a == NULL )
494     {
495  
496         exception_type = PyExc_UnboundLocalError;
497         Py_INCREF( exception_type );
498         exception_value = PyUnicode_FromFormat( "local variable '%s' referenced before assignment", "a" );
499         exception_tb = NULL;
500         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
501         CHAIN_EXCEPTION( exception_value );
502  
503         exception_lineno = 36;
504         type_description_1 = "oooo";
505         goto frame_exception_exit_1;
506     }
507  
508     tmp_tuple_element_1 = var_a;
509     tmp_return_value = PyTuple_New( 2 );
510     Py_INCREF( tmp_tuple_element_1 );
511     PyTuple_SET_ITEM( tmp_return_value, 0, tmp_tuple_element_1 );
512     if ( var_b == NULL )
513     {
514         Py_DECREF( tmp_return_value );
515         exception_type = PyExc_UnboundLocalError;
516         Py_INCREF( exception_type );
517         exception_value = PyUnicode_FromFormat( "local variable '%s' referenced before assignment", "b" );
518         exception_tb = NULL;
519         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
520         CHAIN_EXCEPTION( exception_value );
521  
522         exception_lineno = 36;
523         type_description_1 = "oooo";
524         goto frame_exception_exit_1;
525     }
526  
527     tmp_tuple_element_1 = var_b;
528     Py_INCREF( tmp_tuple_element_1 );
529     PyTuple_SET_ITEM( tmp_return_value, 1, tmp_tuple_element_1 );
530     goto frame_return_exit_1;
531     }
532 252
533 #if 0 253 #if 0
534     RESTORE_FRAME_EXCEPTION( frame_75a0e05266557eb24254cddb07a8349a ); 254     RESTORE_FRAME_EXCEPTION( frame_75a0e05266557eb24254cddb07a8349a );
535 #endif 255 #endif
536 256
537     // Put the previous frame back on top. 257     // Put the previous frame back on top.
538     popFrameStack(); 258     popFrameStack();
539 259
540     goto frame_no_exception_1; 260     goto frame_no_exception_1;
n 541   n
542     frame_return_exit_1:;
543 #if 0
544     RESTORE_FRAME_EXCEPTION( frame_75a0e05266557eb24254cddb07a8349a );
545 #endif
546  
547     // Put the previous frame back on top.
548     popFrameStack();
549  
550     goto try_return_handler_1;
551 261
552     frame_exception_exit_1:; 262     frame_exception_exit_1:;
553 263
554 #if 0 264 #if 0
555     RESTORE_FRAME_EXCEPTION( frame_75a0e05266557eb24254cddb07a8349a ); 265     RESTORE_FRAME_EXCEPTION( frame_75a0e05266557eb24254cddb07a8349a );
589 299
590     // Return the error. 300     // Return the error.
591     goto try_except_handler_1; 301     goto try_except_handler_1;
592 302
593     frame_no_exception_1:; 303     frame_no_exception_1:;
n n 304     {
305     PyObject *tmp_assign_source_3;
306     CHECK_OBJECT( var_c );
307     tmp_assign_source_3 = var_c;
308     assert( var_a == NULL );
309     Py_INCREF( tmp_assign_source_3 );
310     var_a = tmp_assign_source_3;
311  
312     }
313     {
314     PyObject *tmp_assign_source_4;
315     CHECK_OBJECT( var_c );
316     tmp_assign_source_4 = var_c;
317     assert( var_b == NULL );
318     Py_INCREF( tmp_assign_source_4 );
319     var_b = tmp_assign_source_4;
320  
321     }
322     {
323     PyObject *tmp_tuple_element_1;
324     CHECK_OBJECT( var_a );
325     tmp_tuple_element_1 = var_a;
326     tmp_return_value = PyTuple_New( 2 );
327     Py_INCREF( tmp_tuple_element_1 );
328     PyTuple_SET_ITEM( tmp_return_value, 0, tmp_tuple_element_1 );
329     CHECK_OBJECT( var_b );
330     tmp_tuple_element_1 = var_b;
331     Py_INCREF( tmp_tuple_element_1 );
332     PyTuple_SET_ITEM( tmp_return_value, 1, tmp_tuple_element_1 );
333     goto try_return_handler_1;
334     }
594     // tried codes exits in all cases 335     // tried codes exits in all cases
595     NUITKA_CANNOT_GET_HERE( __main__$$$function_1_calledRepeatedly ); 336     NUITKA_CANNOT_GET_HERE( __main__$$$function_1_calledRepeatedly );
596     return NULL; 337     return NULL;
597     // Return handler code: 338     // Return handler code:
598     try_return_handler_1:; 339     try_return_handler_1:;
599     { 340     {
n n 341     CHECK_OBJECT( (PyObject *)var_a );
600     Py_XDECREF( var_a ); 342     Py_DECREF( var_a );
601     var_a = NULL; 343     var_a = NULL;
602 344
603     } 345     }
604     { 346     {
605     Py_XDECREF( var_b ); 347     Py_XDECREF( var_b );
619     { 361     {
620     goto function_return_exit; 362     goto function_return_exit;
621     } 363     }
622     // Exception handler code: 364     // Exception handler code:
623     try_except_handler_1:; 365     try_except_handler_1:;
n 624     exception_keeper_type_3 = exception_type; n 366     exception_keeper_type_1 = exception_type;
625     exception_keeper_value_3 = exception_value; 367     exception_keeper_value_1 = exception_value;
626     exception_keeper_tb_3 = exception_tb; 368     exception_keeper_tb_1 = exception_tb;
627     exception_keeper_lineno_3 = exception_lineno; 369     exception_keeper_lineno_1 = exception_lineno;
628     exception_type = NULL; 370     exception_type = NULL;
629     exception_value = NULL; 371     exception_value = NULL;
630     exception_tb = NULL; 372     exception_tb = NULL;
631     exception_lineno = 0; 373     exception_lineno = 0;
632 374
633     { 375     {
n 634     Py_XDECREF( var_a ); n
635     var_a = NULL;
636  
637     }
638     {
639     Py_XDECREF( var_b );
640     var_b = NULL;
641  
642     }
643     {
644     Py_XDECREF( var_c ); 376     Py_XDECREF( var_c );
645     var_c = NULL; 377     var_c = NULL;
646 378
647     } 379     }
648     { 380     {
n 649     Py_XDECREF( var_iterator ); n
650     var_iterator = NULL;
651  
652     }
653     {
654     // Re-raise. 381     // Re-raise.
t 655     exception_type = exception_keeper_type_3; t 382     exception_type = exception_keeper_type_1;
656     exception_value = exception_keeper_value_3; 383     exception_value = exception_keeper_value_1;
657     exception_tb = exception_keeper_tb_3; 384     exception_tb = exception_keeper_tb_1;
658     exception_lineno = exception_keeper_lineno_3; 385     exception_lineno = exception_keeper_lineno_1;
659 386
660     goto function_exception_exit; 387     goto function_exception_exit;
661     } 388     }
662     // End of try: 389     // End of try:
663     } 390     }