Construct UnpackIterator

Performance Diagrams

Construct UnpackIterator 0010000001000000200000020000003000000300000040000004000000500000050000006000000600000070000007000000800000080000009000000900000010000000100000001100000011000000CPython 2.7Nuitka (master)Nuitka (develop)Nuitka (factory)1119982988.95192307692307257.0CPython 2.76299612242.31730769230768365.11941938165717Nuitka (master)6298552395.6826923076923365.14280744478674Nuitka (develop)6299544549.0480769230769365.1209197479712Nuitka (factory)Construct UnpackIteratorTicks Construct UnpackIterator 001000000100000020000002000000300000030000004000000400000050000005000000600000060000007000000700000080000008000000900000090000001000000010000000CPython 3.5Nuitka (master)Nuitka (develop)Nuitka (factory)1013956788.95192307692307257.0CPython 3.57058304242.31730769230768332.0946752801332Nuitka (master)7241805395.6826923076923327.6225000686761Nuitka (develop)7245841549.0480769230769327.524137121589Nuitka (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_06298f58eeafd8eab31e460fc9bc08a3; 138     struct Nuitka_FrameObject *frame_06298f58eeafd8eab31e460fc9bc08a3;
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_06298f58eeafd8eab31e460fc9bc08a3 = 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     static struct Nuitka_FrameObject *cache_frame_06298f58eeafd8eab31e460fc9bc08a3 = NULL;
157     PyObject *tmp_return_value = 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_06298f58eeafd8eab31e460fc9bc08a3, codeobj_06298f58eeafd8eab31e460fc9bc08a3, module___main__, sizeof(void *)+sizeof(void *)+sizeof(void *)+sizeof(void *) ); 154     MAKE_OR_REUSE_FRAME( cache_frame_06298f58eeafd8eab31e460fc9bc08a3, codeobj_06298f58eeafd8eab31e460fc9bc08a3, module___main__, sizeof(void *)+sizeof(void *)+sizeof(void *)+sizeof(void *) );
258         goto frame_exception_exit_1; 246         goto frame_exception_exit_1;
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
n 263     } n
264     {
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     } 251     }
457 252
458 #if 0 253 #if 0
459     RESTORE_FRAME_EXCEPTION( frame_06298f58eeafd8eab31e460fc9bc08a3 ); 254     RESTORE_FRAME_EXCEPTION( frame_06298f58eeafd8eab31e460fc9bc08a3 );
460 #endif 255 #endif
505     // Return the error. 300     // Return the error.
506     goto try_except_handler_1; 301     goto try_except_handler_1;
507 302
508     frame_no_exception_1:; 303     frame_no_exception_1:;
509     { 304     {
n 510     CHECK_OBJECT( (PyObject *)tmp_tuple_unpack_1__source_iter ); n
511     Py_DECREF( tmp_tuple_unpack_1__source_iter );
512     tmp_tuple_unpack_1__source_iter = NULL;
513  
514     }
515     {
516     PyObject *tmp_assign_source_6; 305     PyObject *tmp_assign_source_3;
517     CHECK_OBJECT( tmp_tuple_unpack_1__element_1 ); 306     CHECK_OBJECT( var_c );
518     tmp_assign_source_6 = tmp_tuple_unpack_1__element_1; 307     tmp_assign_source_3 = var_c;
519     assert( var_a == NULL ); 308     assert( var_a == NULL );
n 520     Py_INCREF( tmp_assign_source_6 ); n 309     Py_INCREF( tmp_assign_source_3 );
521     var_a = tmp_assign_source_6; 310     var_a = tmp_assign_source_3;
522 311
n 523     } n
524     { 312     }
525     Py_XDECREF( tmp_tuple_unpack_1__element_1 );
526     tmp_tuple_unpack_1__element_1 = NULL;
527  
528     } 313     {
529     {
530     PyObject *tmp_assign_source_7; 314     PyObject *tmp_assign_source_4;
531     CHECK_OBJECT( tmp_tuple_unpack_1__element_2 ); 315     CHECK_OBJECT( var_c );
532     tmp_assign_source_7 = tmp_tuple_unpack_1__element_2; 316     tmp_assign_source_4 = var_c;
533     assert( var_b == NULL ); 317     assert( var_b == NULL );
n 534     Py_INCREF( tmp_assign_source_7 ); n 318     Py_INCREF( tmp_assign_source_4 );
535     var_b = tmp_assign_source_7; 319     var_b = tmp_assign_source_4;
536  
537     }
538     {
539     Py_XDECREF( tmp_tuple_unpack_1__element_2 );
540     tmp_tuple_unpack_1__element_2 = NULL;
541 320
542     } 321     }
543     { 322     {
544     PyObject *tmp_tuple_element_1; 323     PyObject *tmp_tuple_element_1;
545     CHECK_OBJECT( var_a ); 324     CHECK_OBJECT( var_a );
585     { 364     {
586     goto function_return_exit; 365     goto function_return_exit;
587     } 366     }
588     // Exception handler code: 367     // Exception handler code:
589     try_except_handler_1:; 368     try_except_handler_1:;
n 590     exception_keeper_type_3 = exception_type; n 369     exception_keeper_type_1 = exception_type;
591     exception_keeper_value_3 = exception_value; 370     exception_keeper_value_1 = exception_value;
592     exception_keeper_tb_3 = exception_tb; 371     exception_keeper_tb_1 = exception_tb;
593     exception_keeper_lineno_3 = exception_lineno; 372     exception_keeper_lineno_1 = exception_lineno;
594     exception_type = NULL; 373     exception_type = NULL;
595     exception_value = NULL; 374     exception_value = NULL;
596     exception_tb = NULL; 375     exception_tb = NULL;
597     exception_lineno = 0; 376     exception_lineno = 0;
598 377
600     Py_XDECREF( var_c ); 379     Py_XDECREF( var_c );
601     var_c = NULL; 380     var_c = NULL;
602 381
603     } 382     }
604     { 383     {
n 605     Py_XDECREF( var_iterator ); n
606     var_iterator = NULL;
607  
608     }
609     {
610     // Re-raise. 384     // Re-raise.
t 611     exception_type = exception_keeper_type_3; t 385     exception_type = exception_keeper_type_1;
612     exception_value = exception_keeper_value_3; 386     exception_value = exception_keeper_value_1;
613     exception_tb = exception_keeper_tb_3; 387     exception_tb = exception_keeper_tb_1;
614     exception_lineno = exception_keeper_lineno_3; 388     exception_lineno = exception_keeper_lineno_1;
615 389
616     goto function_exception_exit; 390     goto function_exception_exit;
617     } 391     }
618     // End of try: 392     // End of try:
619     } 393     }