Construct UnpackIterator

Performance Diagrams

Construct UnpackIterator 001000000100000020000002000000300000030000004000000400000050000005000000600000060000007000000700000080000008000000900000090000001000000010000000CPython 2.7Nuitka (master)Nuitka (develop)Nuitka (factory)1055127788.95192307692307257.0CPython 2.76400535242.31730769230768354.212138944815Nuitka (master)6399389395.6826923076923354.2389787511028Nuitka (develop)6400250549.0480769230769354.21881376575044Nuitka (factory)Construct UnpackIteratorTicks Construct UnpackIterator 0010000001000000200000020000003000000300000040000004000000500000050000006000000600000070000007000000800000080000009000000900000010000000100000001100000011000000CPython 3.5Nuitka (master)Nuitka (develop)Nuitka (factory)1113885488.95192307692307257.0CPython 3.57499657242.31730769230768337.73555559181887Nuitka (master)7500307395.6826923076923337.72113534715095Nuitka (develop)7499566549.0480769230769337.73757442607234Nuitka (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_e34caa256b85878bfe4e08d91d309c12; 138     struct Nuitka_FrameObject *frame_e34caa256b85878bfe4e08d91d309c12;
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_e34caa256b85878bfe4e08d91d309c12 = 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_e34caa256b85878bfe4e08d91d309c12 = 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 body. 151     // Actual function body.
164     // Tried code: 152     // Tried code:
165     MAKE_OR_REUSE_FRAME(cache_frame_e34caa256b85878bfe4e08d91d309c12, codeobj_e34caa256b85878bfe4e08d91d309c12, module___main__, sizeof(void *)+sizeof(void *)+sizeof(void *)+sizeof(void *)); 153     MAKE_OR_REUSE_FRAME(cache_frame_e34caa256b85878bfe4e08d91d309c12, codeobj_e34caa256b85878bfe4e08d91d309c12, module___main__, sizeof(void *)+sizeof(void *)+sizeof(void *)+sizeof(void *));
166     frame_e34caa256b85878bfe4e08d91d309c12 = cache_frame_e34caa256b85878bfe4e08d91d309c12; 154     frame_e34caa256b85878bfe4e08d91d309c12 = cache_frame_e34caa256b85878bfe4e08d91d309c12;
250             goto frame_exception_exit_1; 238             goto frame_exception_exit_1;
251         } 239         }
252         assert(var_iterator == NULL); 240         assert(var_iterator == NULL);
253         var_iterator = tmp_assign_source_2; 241         var_iterator = tmp_assign_source_2;
254     } 242     }
n 255     // Tried code: n
256     {
257         PyObject *tmp_assign_source_3;
258         PyObject *tmp_iter_arg_2;
259         CHECK_OBJECT(var_iterator);
260         tmp_iter_arg_2 = var_iterator;
261         tmp_assign_source_3 = MAKE_ITERATOR(tmp_iter_arg_2);
262         if (tmp_assign_source_3 == NULL) {
263             assert(ERROR_OCCURRED());
264  
265             FETCH_ERROR_OCCURRED(&exception_type, &exception_value, &exception_tb);
266  
267  
268             exception_lineno = 30;
269             type_description_1 = "oooo";
270             goto try_except_handler_2;
271         }
272         assert(tmp_tuple_unpack_1__source_iter == NULL);
273         tmp_tuple_unpack_1__source_iter = tmp_assign_source_3;
274     }
275     // Tried code:
276     {
277         PyObject *tmp_assign_source_4;
278         PyObject *tmp_unpack_1;
279         CHECK_OBJECT(tmp_tuple_unpack_1__source_iter);
280         tmp_unpack_1 = tmp_tuple_unpack_1__source_iter;
281         tmp_assign_source_4 = UNPACK_NEXT(tmp_unpack_1, 0, 2);
282         if (tmp_assign_source_4 == NULL) {
283             if (!ERROR_OCCURRED()) {
284                 exception_type = PyExc_StopIteration;
285                 Py_INCREF(exception_type);
286                 exception_value = NULL;
287                 exception_tb = NULL;
288             } else {
289                 FETCH_ERROR_OCCURRED(&exception_type, &exception_value, &exception_tb);
290             }
291  
292  
293             type_description_1 = "oooo";
294             exception_lineno = 30;
295             goto try_except_handler_3;
296         }
297         assert(tmp_tuple_unpack_1__element_1 == NULL);
298         tmp_tuple_unpack_1__element_1 = tmp_assign_source_4;
299     }
300     {
301         PyObject *tmp_assign_source_5;
302         PyObject *tmp_unpack_2;
303         CHECK_OBJECT(tmp_tuple_unpack_1__source_iter);
304         tmp_unpack_2 = tmp_tuple_unpack_1__source_iter;
305         tmp_assign_source_5 = UNPACK_NEXT(tmp_unpack_2, 1, 2);
306         if (tmp_assign_source_5 == NULL) {
307             if (!ERROR_OCCURRED()) {
308                 exception_type = PyExc_StopIteration;
309                 Py_INCREF(exception_type);
310                 exception_value = NULL;
311                 exception_tb = NULL;
312             } else {
313                 FETCH_ERROR_OCCURRED(&exception_type, &exception_value, &exception_tb);
314             }
315  
316  
317             type_description_1 = "oooo";
318             exception_lineno = 30;
319             goto try_except_handler_3;
320         }
321         assert(tmp_tuple_unpack_1__element_2 == NULL);
322         tmp_tuple_unpack_1__element_2 = tmp_assign_source_5;
323     }
324     {
325         PyObject *tmp_iterator_name_1;
326         CHECK_OBJECT(tmp_tuple_unpack_1__source_iter);
327         tmp_iterator_name_1 = tmp_tuple_unpack_1__source_iter;
328         // Check if iterator has left-over elements.
329         CHECK_OBJECT(tmp_iterator_name_1); assert(HAS_ITERNEXT(tmp_iterator_name_1));
330  
331         tmp_iterator_attempt = (*Py_TYPE(tmp_iterator_name_1)->tp_iternext)(tmp_iterator_name_1);
332  
333         if (likely(tmp_iterator_attempt == NULL))
334         {
335             PyObject *error = GET_ERROR_OCCURRED();
336  
337             if (error != NULL)
338             {
339                 if (EXCEPTION_MATCH_BOOL_SINGLE(error, PyExc_StopIteration))
340                 {
341                     CLEAR_ERROR_OCCURRED();
342                 } else {
343                     FETCH_ERROR_OCCURRED(&exception_type, &exception_value, &exception_tb);
344  
345                     type_description_1 = "oooo";
346                     exception_lineno = 30;
347                     goto try_except_handler_3;
348                 }
349             }
350         } else {
351             Py_DECREF(tmp_iterator_attempt);
352  
353             // TODO: Could avoid PyErr_Format.
354 #if PYTHON_VERSION < 300
355             PyErr_Format(PyExc_ValueError, "too many values to unpack");
356 #else
357             PyErr_Format(PyExc_ValueError, "too many values to unpack (expected 2)");
358 #endif
359             FETCH_ERROR_OCCURRED(&exception_type, &exception_value, &exception_tb);
360  
361             type_description_1 = "oooo";
362             exception_lineno = 30;
363             goto try_except_handler_3;
364         }
365     }
366     goto try_end_1;
367     // Exception handler code:
368     try_except_handler_3:;
369     exception_keeper_type_1 = exception_type;
370     exception_keeper_value_1 = exception_value;
371     exception_keeper_tb_1 = exception_tb;
372     exception_keeper_lineno_1 = exception_lineno;
373     exception_type = NULL;
374     exception_value = NULL;
375     exception_tb = NULL;
376     exception_lineno = 0;
377  
378     CHECK_OBJECT((PyObject *)tmp_tuple_unpack_1__source_iter);
379     Py_DECREF(tmp_tuple_unpack_1__source_iter);
380     tmp_tuple_unpack_1__source_iter = NULL;
381  
382     // Re-raise.
383     exception_type = exception_keeper_type_1;
384     exception_value = exception_keeper_value_1;
385     exception_tb = exception_keeper_tb_1;
386     exception_lineno = exception_keeper_lineno_1;
387  
388     goto try_except_handler_2;
389     // End of try:
390     try_end_1:;
391     goto try_end_2;
392     // Exception handler code:
393     try_except_handler_2:;
394     exception_keeper_type_2 = exception_type;
395     exception_keeper_value_2 = exception_value;
396     exception_keeper_tb_2 = exception_tb;
397     exception_keeper_lineno_2 = exception_lineno;
398     exception_type = NULL;
399     exception_value = NULL;
400     exception_tb = NULL;
401     exception_lineno = 0;
402  
403     Py_XDECREF(tmp_tuple_unpack_1__element_1);
404     tmp_tuple_unpack_1__element_1 = NULL;
405  
406     Py_XDECREF(tmp_tuple_unpack_1__element_2);
407     tmp_tuple_unpack_1__element_2 = NULL;
408  
409     // Re-raise.
410     exception_type = exception_keeper_type_2;
411     exception_value = exception_keeper_value_2;
412     exception_tb = exception_keeper_tb_2;
413     exception_lineno = exception_keeper_lineno_2;
414  
415     goto frame_exception_exit_1;
416     // End of try:
417     try_end_2:;
418 243
419 #if 0 244 #if 0
420     RESTORE_FRAME_EXCEPTION(frame_e34caa256b85878bfe4e08d91d309c12); 245     RESTORE_FRAME_EXCEPTION(frame_e34caa256b85878bfe4e08d91d309c12);
421 #endif 246 #endif
422 247
462 287
463     // Return the error. 288     // Return the error.
464     goto try_except_handler_1; 289     goto try_except_handler_1;
465 290
466     frame_no_exception_1:; 291     frame_no_exception_1:;
n 467     CHECK_OBJECT((PyObject *)tmp_tuple_unpack_1__source_iter); n
468     Py_DECREF(tmp_tuple_unpack_1__source_iter);
469     tmp_tuple_unpack_1__source_iter = NULL;
470  
471     { 292     {
n 472         PyObject *tmp_assign_source_6; n 293         PyObject *tmp_assign_source_3;
473         CHECK_OBJECT(tmp_tuple_unpack_1__element_1); 294         CHECK_OBJECT(var_c);
474         tmp_assign_source_6 = tmp_tuple_unpack_1__element_1; 295         tmp_assign_source_3 = var_c;
475         assert(var_a == NULL); 296         assert(var_a == NULL);
n 476         Py_INCREF(tmp_assign_source_6); n 297         Py_INCREF(tmp_assign_source_3);
477         var_a = tmp_assign_source_6; 298         var_a = tmp_assign_source_3;
478     }
479     Py_XDECREF(tmp_tuple_unpack_1__element_1);
480     tmp_tuple_unpack_1__element_1 = NULL;
481  
482     { 299     }
300     {
483         PyObject *tmp_assign_source_7; 301         PyObject *tmp_assign_source_4;
484         CHECK_OBJECT(tmp_tuple_unpack_1__element_2); 302         CHECK_OBJECT(var_c);
485         tmp_assign_source_7 = tmp_tuple_unpack_1__element_2; 303         tmp_assign_source_4 = var_c;
486         assert(var_b == NULL); 304         assert(var_b == NULL);
n 487         Py_INCREF(tmp_assign_source_7); n 305         Py_INCREF(tmp_assign_source_4);
488         var_b = tmp_assign_source_7; 306         var_b = tmp_assign_source_4;
489     } 307     }
n 490     Py_XDECREF(tmp_tuple_unpack_1__element_2); n
491     tmp_tuple_unpack_1__element_2 = NULL;
492  
493     { 308     {
494         PyObject *tmp_tuple_element_1; 309         PyObject *tmp_tuple_element_1;
495         CHECK_OBJECT(var_a); 310         CHECK_OBJECT(var_a);
496         tmp_tuple_element_1 = var_a; 311         tmp_tuple_element_1 = var_a;
497         tmp_return_value = PyTuple_New(2); 312         tmp_return_value = PyTuple_New(2);
525     var_iterator = NULL; 340     var_iterator = NULL;
526 341
527     goto function_return_exit; 342     goto function_return_exit;
528     // Exception handler code: 343     // Exception handler code:
529     try_except_handler_1:; 344     try_except_handler_1:;
n 530     exception_keeper_type_3 = exception_type; n 345     exception_keeper_type_1 = exception_type;
531     exception_keeper_value_3 = exception_value; 346     exception_keeper_value_1 = exception_value;
532     exception_keeper_tb_3 = exception_tb; 347     exception_keeper_tb_1 = exception_tb;
533     exception_keeper_lineno_3 = exception_lineno; 348     exception_keeper_lineno_1 = exception_lineno;
534     exception_type = NULL; 349     exception_type = NULL;
535     exception_value = NULL; 350     exception_value = NULL;
536     exception_tb = NULL; 351     exception_tb = NULL;
537     exception_lineno = 0; 352     exception_lineno = 0;
538 353
539     Py_XDECREF(var_c); 354     Py_XDECREF(var_c);
540     var_c = NULL; 355     var_c = NULL;
541 356
n 542     Py_XDECREF(var_iterator); n
543     var_iterator = NULL;
544  
545     // Re-raise. 357     // Re-raise.
t 546     exception_type = exception_keeper_type_3; t 358     exception_type = exception_keeper_type_1;
547     exception_value = exception_keeper_value_3; 359     exception_value = exception_keeper_value_1;
548     exception_tb = exception_keeper_tb_3; 360     exception_tb = exception_keeper_tb_1;
549     exception_lineno = exception_keeper_lineno_3; 361     exception_lineno = exception_keeper_lineno_1;
550 362
551     goto function_exception_exit; 363     goto function_exception_exit;
552     // End of try: 364     // End of try:
553 365
554     // Return statement must have exited already. 366     // Return statement must have exited already.