Construct UnpackIterator

Performance Diagrams

Construct UnpackIterator 0010000001000000200000020000003000000300000040000004000000500000050000006000000600000070000007000000800000080000009000000900000010000000100000001100000011000000CPython 2.7Nuitka (master)Nuitka (develop)Nuitka (factory)1119982988.95192307692307257.0CPython 2.76299396242.31730769230768365.12418525112514Nuitka (master)6304382395.6826923076923365.01417309757414Nuitka (develop)6299448549.0480769230769365.12303791217914Nuitka (factory)Construct UnpackIteratorTicks Construct UnpackIterator 001000000100000020000002000000300000030000004000000400000050000005000000600000060000007000000700000080000008000000900000090000001000000010000000CPython 3.5Nuitka (master)Nuitka (develop)Nuitka (factory)1013956788.95192307692307257.0CPython 3.57049177242.31730769230768332.31711299521356Nuitka (master)7050303395.6826923076923332.2896708053176Nuitka (develop)7049791549.0480769230769332.30214895916015Nuitka (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_7f73b786036d7c3d4aea422a42639f4f; 138     struct Nuitka_FrameObject *frame_7f73b786036d7c3d4aea422a42639f4f;
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_7f73b786036d7c3d4aea422a42639f4f = 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_7f73b786036d7c3d4aea422a42639f4f = 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_7f73b786036d7c3d4aea422a42639f4f, codeobj_7f73b786036d7c3d4aea422a42639f4f, module___main__, sizeof(void *)+sizeof(void *)+sizeof(void *)+sizeof(void *) ); 154     MAKE_OR_REUSE_FRAME( cache_frame_7f73b786036d7c3d4aea422a42639f4f, codeobj_7f73b786036d7c3d4aea422a42639f4f, module___main__, sizeof(void *)+sizeof(void *)+sizeof(void *)+sizeof(void *) );
255     } 243     }
256     assert( var_iterator == NULL ); 244     assert( var_iterator == NULL );
257     var_iterator = tmp_assign_source_2; 245     var_iterator = tmp_assign_source_2;
258 246
259     } 247     }
n 260     { n
261     // Tried code:
262     {
263     PyObject *tmp_assign_source_3;
264     PyObject *tmp_iter_arg_2;
265     tmp_iter_arg_2 = var_iterator;
266  
267     CHECK_OBJECT( tmp_iter_arg_2 );
268     tmp_assign_source_3 = MAKE_ITERATOR( tmp_iter_arg_2 );
269     if ( tmp_assign_source_3 == NULL )
270     {
271         assert( ERROR_OCCURRED() );
272  
273         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
274  
275  
276         exception_lineno = 30;
277         type_description_1 = "oooo";
278         goto try_except_handler_2;
279     }
280     assert( tmp_tuple_unpack_1__source_iter == NULL );
281     tmp_tuple_unpack_1__source_iter = tmp_assign_source_3;
282  
283     }
284     {
285     // Tried code:
286     {
287     PyObject *tmp_assign_source_4;
288     PyObject *tmp_unpack_1;
289     tmp_unpack_1 = tmp_tuple_unpack_1__source_iter;
290  
291     CHECK_OBJECT( tmp_unpack_1 );
292     tmp_assign_source_4 = UNPACK_NEXT( tmp_unpack_1, 0, 2 );
293     if ( tmp_assign_source_4 == NULL )
294     {
295         if ( !ERROR_OCCURRED() )
296         {
297             exception_type = PyExc_StopIteration;
298             Py_INCREF( exception_type );
299             exception_value = NULL;
300             exception_tb = NULL;
301         }
302         else
303         {
304             FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
305         }
306  
307  
308         type_description_1 = "oooo";
309         exception_lineno = 30;
310         goto try_except_handler_3;
311     }
312     assert( tmp_tuple_unpack_1__element_1 == NULL );
313     tmp_tuple_unpack_1__element_1 = tmp_assign_source_4;
314  
315     }
316     {
317     PyObject *tmp_assign_source_5;
318     PyObject *tmp_unpack_2;
319     tmp_unpack_2 = tmp_tuple_unpack_1__source_iter;
320  
321     CHECK_OBJECT( tmp_unpack_2 );
322     tmp_assign_source_5 = UNPACK_NEXT( tmp_unpack_2, 1, 2 );
323     if ( tmp_assign_source_5 == NULL )
324     {
325         if ( !ERROR_OCCURRED() )
326         {
327             exception_type = PyExc_StopIteration;
328             Py_INCREF( exception_type );
329             exception_value = NULL;
330             exception_tb = NULL;
331         }
332         else
333         {
334             FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
335         }
336  
337  
338         type_description_1 = "oooo";
339         exception_lineno = 30;
340         goto try_except_handler_3;
341     }
342     assert( tmp_tuple_unpack_1__element_2 == NULL );
343     tmp_tuple_unpack_1__element_2 = tmp_assign_source_5;
344  
345     }
346     {
347     PyObject *tmp_iterator_name_1;
348     tmp_iterator_name_1 = tmp_tuple_unpack_1__source_iter;
349  
350     CHECK_OBJECT( tmp_iterator_name_1 );
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     tmp_assign_source_6 = tmp_tuple_unpack_1__element_1;
466  
467     CHECK_OBJECT( tmp_assign_source_6 );
468     assert( var_a == NULL );
469     Py_INCREF( tmp_assign_source_6 );
470     var_a = tmp_assign_source_6;
471  
472     }
473     {
474     Py_XDECREF( tmp_tuple_unpack_1__element_1 );
475     tmp_tuple_unpack_1__element_1 = NULL;
476  
477     }
478     {
479     PyObject *tmp_assign_source_7;
480     tmp_assign_source_7 = tmp_tuple_unpack_1__element_2;
481  
482     CHECK_OBJECT( tmp_assign_source_7 );
483     assert( var_b == NULL );
484     Py_INCREF( tmp_assign_source_7 );
485     var_b = tmp_assign_source_7;
486  
487     }
488     {
489     Py_XDECREF( tmp_tuple_unpack_1__element_2 );
490     tmp_tuple_unpack_1__element_2 = NULL;
491  
492     }
493     {
494     PyObject *tmp_tuple_element_1;
495     tmp_tuple_element_1 = var_a;
496  
497     if ( tmp_tuple_element_1 == NULL )
498     {
499  
500         exception_type = PyExc_UnboundLocalError;
501         Py_INCREF( exception_type );
502         exception_value = PyUnicode_FromFormat( "local variable '%s' referenced before assignment", "a" );
503         exception_tb = NULL;
504         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
505         CHAIN_EXCEPTION( exception_value );
506  
507         exception_lineno = 36;
508         type_description_1 = "oooo";
509         goto frame_exception_exit_1;
510     }
511  
512     tmp_return_value = PyTuple_New( 2 );
513     Py_INCREF( tmp_tuple_element_1 );
514     PyTuple_SET_ITEM( tmp_return_value, 0, tmp_tuple_element_1 );
515     tmp_tuple_element_1 = var_b;
516  
517     if ( tmp_tuple_element_1 == NULL )
518     {
519         Py_DECREF( tmp_return_value );
520         exception_type = PyExc_UnboundLocalError;
521         Py_INCREF( exception_type );
522         exception_value = PyUnicode_FromFormat( "local variable '%s' referenced before assignment", "b" );
523         exception_tb = NULL;
524         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
525         CHAIN_EXCEPTION( exception_value );
526  
527         exception_lineno = 36;
528         type_description_1 = "oooo";
529         goto frame_exception_exit_1;
530     }
531  
532     Py_INCREF( tmp_tuple_element_1 );
533     PyTuple_SET_ITEM( tmp_return_value, 1, tmp_tuple_element_1 );
534     goto frame_return_exit_1;
535     }
536 248
537 #if 0 249 #if 0
538     RESTORE_FRAME_EXCEPTION( frame_7f73b786036d7c3d4aea422a42639f4f ); 250     RESTORE_FRAME_EXCEPTION( frame_7f73b786036d7c3d4aea422a42639f4f );
539 #endif 251 #endif
540 252
541     // Put the previous frame back on top. 253     // Put the previous frame back on top.
542     popFrameStack(); 254     popFrameStack();
543 255
544     goto frame_no_exception_1; 256     goto frame_no_exception_1;
n 545   n
546     frame_return_exit_1:;
547 #if 0
548     RESTORE_FRAME_EXCEPTION( frame_7f73b786036d7c3d4aea422a42639f4f );
549 #endif
550  
551     // Put the previous frame back on top.
552     popFrameStack();
553  
554     goto try_return_handler_1;
555 257
556     frame_exception_exit_1:; 258     frame_exception_exit_1:;
557 259
558 #if 0 260 #if 0
559     RESTORE_FRAME_EXCEPTION( frame_7f73b786036d7c3d4aea422a42639f4f ); 261     RESTORE_FRAME_EXCEPTION( frame_7f73b786036d7c3d4aea422a42639f4f );
594     // Return the error. 296     // Return the error.
595     goto try_except_handler_1; 297     goto try_except_handler_1;
596 298
597     frame_no_exception_1:; 299     frame_no_exception_1:;
598 300
n n 301     {
302     PyObject *tmp_assign_source_3;
303     tmp_assign_source_3 = var_c;
304  
305     CHECK_OBJECT( tmp_assign_source_3 );
306     assert( var_a == NULL );
307     Py_INCREF( tmp_assign_source_3 );
308     var_a = tmp_assign_source_3;
309  
310     }
311     {
312     PyObject *tmp_assign_source_4;
313     tmp_assign_source_4 = var_c;
314  
315     CHECK_OBJECT( tmp_assign_source_4 );
316     assert( var_b == NULL );
317     Py_INCREF( tmp_assign_source_4 );
318     var_b = tmp_assign_source_4;
319  
320     }
321     {
322     PyObject *tmp_tuple_element_1;
323     tmp_tuple_element_1 = var_a;
324  
325     CHECK_OBJECT( tmp_tuple_element_1 );
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     tmp_tuple_element_1 = var_b;
330  
331     CHECK_OBJECT( tmp_tuple_element_1 );
332     Py_INCREF( tmp_tuple_element_1 );
333     PyTuple_SET_ITEM( tmp_return_value, 1, tmp_tuple_element_1 );
334     goto try_return_handler_1;
335     }
599     // tried codes exits in all cases 336     // tried codes exits in all cases
600     NUITKA_CANNOT_GET_HERE( __main__$$$function_1_calledRepeatedly ); 337     NUITKA_CANNOT_GET_HERE( __main__$$$function_1_calledRepeatedly );
601     return NULL; 338     return NULL;
602     // Return handler code: 339     // Return handler code:
603     try_return_handler_1:; 340     try_return_handler_1:;
604     { 341     {
n n 342     CHECK_OBJECT( (PyObject *)var_a );
605     Py_XDECREF( var_a ); 343     Py_DECREF( var_a );
606     var_a = NULL; 344     var_a = NULL;
607 345
608     } 346     }
609     { 347     {
610     Py_XDECREF( var_b ); 348     Py_XDECREF( var_b );
624     { 362     {
625     goto function_return_exit; 363     goto function_return_exit;
626     } 364     }
627     // Exception handler code: 365     // Exception handler code:
628     try_except_handler_1:; 366     try_except_handler_1:;
n 629     exception_keeper_type_3 = exception_type; n 367     exception_keeper_type_1 = exception_type;
630     exception_keeper_value_3 = exception_value; 368     exception_keeper_value_1 = exception_value;
631     exception_keeper_tb_3 = exception_tb; 369     exception_keeper_tb_1 = exception_tb;
632     exception_keeper_lineno_3 = exception_lineno; 370     exception_keeper_lineno_1 = exception_lineno;
633     exception_type = NULL; 371     exception_type = NULL;
634     exception_value = NULL; 372     exception_value = NULL;
635     exception_tb = NULL; 373     exception_tb = NULL;
636     exception_lineno = 0; 374     exception_lineno = 0;
637 375
638     { 376     {
n 639     Py_XDECREF( var_a ); n
640     var_a = NULL;
641  
642     }
643     {
644     Py_XDECREF( var_b );
645     var_b = NULL;
646  
647     }
648     {
649     Py_XDECREF( var_c ); 377     Py_XDECREF( var_c );
650     var_c = NULL; 378     var_c = NULL;
651 379
652     } 380     }
653     { 381     {
n 654     Py_XDECREF( var_iterator ); n
655     var_iterator = NULL;
656  
657     }
658     {
659     // Re-raise. 382     // Re-raise.
t 660     exception_type = exception_keeper_type_3; t 383     exception_type = exception_keeper_type_1;
661     exception_value = exception_keeper_value_3; 384     exception_value = exception_keeper_value_1;
662     exception_tb = exception_keeper_tb_3; 385     exception_tb = exception_keeper_tb_1;
663     exception_lineno = exception_keeper_lineno_3; 386     exception_lineno = exception_keeper_lineno_1;
664 387
665     goto function_exception_exit; 388     goto function_exception_exit;
666     } 389     }
667     // End of try: 390     // End of try:
668     } 391     }