Construct ListContraction

Performance Diagrams

Construct ListContraction 002000000020000000400000004000000060000000600000008000000080000000100000000100000000120000000120000000140000000140000000160000000160000000180000000180000000CPython 2.7Nuitka (historic)Nuitka (master)Nuitka (develop)Nuitka (factory)18036872072.9230769230769257.0CPython 2.785779716194.46153846153845386.5923046071744Nuitka (historic)80688251316.0393.5679006624703Nuitka (master)80688863437.53846153846143393.56706218773155Nuitka (develop)80638753559.0769230769231393.6357157321104Nuitka (factory)Construct ListContractionTicks Construct ListContraction 002000000020000000400000004000000060000000600000008000000080000000100000000100000000120000000120000000140000000140000000160000000160000000180000000180000000200000000200000000220000000220000000240000000240000000260000000260000000280000000280000000CPython 3.5Nuitka (historic)Nuitka (master)Nuitka (develop)Nuitka (factory)29009757872.9230769230769257.0CPython 3.50194.46153846153845504.11538461538464Nuitka (historic)99334578316.0419.4986752401794Nuitka (master)99353539437.53846153846143419.4825235892763Nuitka (develop)99356666559.0769230769231419.4798598999997Nuitka (factory)Construct ListContractionTicks

Source Code with Construct

module_value1 = 1000

def calledRepeatedly():
    # Force frame and eliminate forward propagation (currently).
    module_value1

# construct_begin
    l = [
        x
        for x in
        range(7)
    ]
# construct_alternative



    return l, x

for x in xrange(50000):
    calledRepeatedly()

print("OK.")

Source Code without Construct

module_value1 = 1000

def calledRepeatedly():
    # Force frame and eliminate forward propagation (currently).
    module_value1

# construct_begin





# construct_alternative
    l = 1
# construct_end

    return l, x

for x in xrange(50000):
    calledRepeatedly()

print("OK.")

Context Diff of Source Code


Construct
Baseline
22 def calledRepeatedly(): 22 def calledRepeatedly():
23     # Force frame and eliminate forward propagation (currently). 23     # Force frame and eliminate forward propagation (currently).
24     module_value1 24     module_value1
25 25
26 # construct_begin 26 # construct_begin
n 27     l = [ n
28         x
29         for x in
30         range(7)
31     ]
32 # construct_alternative
33 27
34 28
t t 29  
30  
31  
32 # construct_alternative
33     l = 1
34 # construct_end
35 35
36     return l, x 36     return l, x
37 37
38 for x in xrange(50000): 38 for x in xrange(50000):
39     calledRepeatedly() 39     calledRepeatedly()

Context Diff of Generated Code


Construct
Baseline
30 PyObject *module___main__; 30 PyObject *module___main__;
31 PyDictObject *moduledict___main__; 31 PyDictObject *moduledict___main__;
32 32
33 /* The module constants used, if any. */ 33 /* The module constants used, if any. */
34 static PyObject *const_tuple_str_plain_l_tuple; 34 static PyObject *const_tuple_str_plain_l_tuple;
n 35 static PyObject *const_xrange_0_7; n
36 static PyObject *const_str_plain___package__; 35 static PyObject *const_str_plain___package__;
37 extern PyObject *const_int_pos_1; 36 extern PyObject *const_int_pos_1;
38 extern PyObject *const_dict_empty; 37 extern PyObject *const_dict_empty;
39 extern PyObject *const_str_plain___file__; 38 extern PyObject *const_str_plain___file__;
40 extern PyObject *const_int_0; 39 extern PyObject *const_int_0;
44 static PyObject *const_tuple_str_digest_5ed1392909ad16e6227b8230f4582352_tuple; 43 static PyObject *const_tuple_str_digest_5ed1392909ad16e6227b8230f4582352_tuple;
45 static PyObject *const_int_pos_1000; 44 static PyObject *const_int_pos_1000;
46 static PyObject *const_str_plain_module_value1; 45 static PyObject *const_str_plain_module_value1;
47 static PyObject *const_str_plain_calledRepeatedly; 46 static PyObject *const_str_plain_calledRepeatedly;
48 static PyObject *const_str_angle_module; 47 static PyObject *const_str_angle_module;
n 49 static PyObject *const_int_pos_7; n
50 static PyObject *const_str_plain_x; 48 static PyObject *const_str_plain_x;
51 static PyObject *const_str_plain_l; 49 static PyObject *const_str_plain_l;
52 extern PyObject *const_tuple_empty; 50 extern PyObject *const_tuple_empty;
53 static PyObject *const_str_digest_5ed1392909ad16e6227b8230f4582352; 51 static PyObject *const_str_digest_5ed1392909ad16e6227b8230f4582352;
54 extern PyObject *const_str_plain___loader__; 52 extern PyObject *const_str_plain___loader__;
63 static void createModuleConstants( void ) 61 static void createModuleConstants( void )
64 { 62 {
65     const_tuple_str_plain_l_tuple = PyTuple_New( 1 ); 63     const_tuple_str_plain_l_tuple = PyTuple_New( 1 );
66     const_str_plain_l = UNSTREAM_STRING( &constant_bin[ 0 ], 1, 1 ); 64     const_str_plain_l = UNSTREAM_STRING( &constant_bin[ 0 ], 1, 1 );
67     PyTuple_SET_ITEM( const_tuple_str_plain_l_tuple, 0, const_str_plain_l ); Py_INCREF( const_str_plain_l ); 65     PyTuple_SET_ITEM( const_tuple_str_plain_l_tuple, 0, const_str_plain_l ); Py_INCREF( const_str_plain_l );
n 68     const_int_pos_7 = PyLong_FromUnsignedLong( 7ul ); n
69     const_xrange_0_7 = BUILTIN_XRANGE3( const_int_0, const_int_pos_7, const_int_pos_1 );
70     const_str_plain___package__ = UNSTREAM_STRING( &constant_bin[ 1 ], 11, 1 ); 66     const_str_plain___package__ = UNSTREAM_STRING( &constant_bin[ 1 ], 11, 1 );
71     const_int_pos_50000 = PyLong_FromUnsignedLong( 50000ul ); 67     const_int_pos_50000 = PyLong_FromUnsignedLong( 50000ul );
72     const_xrange_0_50000 = BUILTIN_XRANGE3( const_int_0, const_int_pos_50000, const_int_pos_1 ); 68     const_xrange_0_50000 = BUILTIN_XRANGE3( const_int_0, const_int_pos_50000, const_int_pos_1 );
73     const_tuple_str_digest_5ed1392909ad16e6227b8230f4582352_tuple = PyTuple_New( 1 ); 69     const_tuple_str_digest_5ed1392909ad16e6227b8230f4582352_tuple = PyTuple_New( 1 );
74     const_str_digest_5ed1392909ad16e6227b8230f4582352 = UNSTREAM_STRING( &constant_bin[ 12 ], 3, 0 ); 70     const_str_digest_5ed1392909ad16e6227b8230f4582352 = UNSTREAM_STRING( &constant_bin[ 12 ], 3, 0 );
106     codeobj_main = codeobj_e477659522edebe7afa63b3b796cda39; 102     codeobj_main = codeobj_e477659522edebe7afa63b3b796cda39;
107     codeobj_157e0abe4b86c150e34f02535c32cc8d = MAKE_CODEOBJ( module_filename_obj, const_str_plain_calledRepeatedly, 22, const_tuple_str_plain_l_tuple, 0, 0, CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE ); 103     codeobj_157e0abe4b86c150e34f02535c32cc8d = MAKE_CODEOBJ( module_filename_obj, const_str_plain_calledRepeatedly, 22, const_tuple_str_plain_l_tuple, 0, 0, CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE );
108 } 104 }
109 105
110 // The module function declarations. 106 // The module function declarations.
n 111 NUITKA_LOCAL_MODULE PyObject *impl___main__$$$function_1_calledRepeatedly$$$function_1_listcontraction( PyObject **python_pars ); n
112  
113  
114 static PyObject *MAKE_FUNCTION___main__$$$function_1_calledRepeatedly(  ); 107 static PyObject *MAKE_FUNCTION___main__$$$function_1_calledRepeatedly(  );
115 108
116 109
117 // The module function definitions. 110 // The module function definitions.
118 static PyObject *impl___main__$$$function_1_calledRepeatedly( struct Nuitka_FunctionObject const *self, PyObject **python_pars ) 111 static PyObject *impl___main__$$$function_1_calledRepeatedly( struct Nuitka_FunctionObject const *self, PyObject **python_pars )
121 #ifndef __NUITKA_NO_ASSERT__ 114 #ifndef __NUITKA_NO_ASSERT__
122     NUITKA_MAY_BE_UNUSED bool had_error = ERROR_OCCURRED(); 115     NUITKA_MAY_BE_UNUSED bool had_error = ERROR_OCCURRED();
123 #endif 116 #endif
124 117
125     // Local variable declarations. 118     // Local variable declarations.
n 126     PyObject *var_l = NULL; n
127     PyObject *exception_type = NULL, *exception_value = NULL; 119     PyObject *exception_type = NULL, *exception_value = NULL;
128     PyTracebackObject *exception_tb = NULL; 120     PyTracebackObject *exception_tb = NULL;
129     NUITKA_MAY_BE_UNUSED int exception_lineno = -1; 121     NUITKA_MAY_BE_UNUSED int exception_lineno = -1;
130     PyObject *exception_keeper_type_1; 122     PyObject *exception_keeper_type_1;
131     PyObject *exception_keeper_value_1; 123     PyObject *exception_keeper_value_1;
132     PyTracebackObject *exception_keeper_tb_1; 124     PyTracebackObject *exception_keeper_tb_1;
133     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_1; 125     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_1;
n 134     PyObject *tmp_assign_source_1; n
135     PyObject *tmp_dircall_arg1_1;
136     PyObject *tmp_frame_locals; 126     PyObject *tmp_frame_locals;
n 137     PyObject *tmp_iter_arg_1; n
138     PyObject *tmp_return_value; 127     PyObject *tmp_return_value;
139     PyObject *tmp_tuple_element_1; 128     PyObject *tmp_tuple_element_1;
140     NUITKA_MAY_BE_UNUSED PyObject *tmp_unused; 129     NUITKA_MAY_BE_UNUSED PyObject *tmp_unused;
141     static PyFrameObject *cache_frame_function = NULL; 130     static PyFrameObject *cache_frame_function = NULL;
142 131
180 169
181         exception_lineno = 24; 170         exception_lineno = 24;
182         goto frame_exception_exit_1; 171         goto frame_exception_exit_1;
183     } 172     }
184 173
n 185     tmp_iter_arg_1 = const_xrange_0_7; n
186     tmp_dircall_arg1_1 = MAKE_ITERATOR( tmp_iter_arg_1 );
187     assert( tmp_dircall_arg1_1 != NULL );
188  
189     {
190         PyObject *dir_call_args[] = {tmp_dircall_arg1_1};
191         tmp_assign_source_1 = impl___main__$$$function_1_calledRepeatedly$$$function_1_listcontraction( dir_call_args );
192     }
193     if ( tmp_assign_source_1 == NULL )
194     {
195         assert( ERROR_OCCURRED() );
196  
197         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
198  
199  
200         exception_lineno = 28;
201         goto frame_exception_exit_1;
202     }
203     assert( var_l == NULL );
204     var_l = tmp_assign_source_1;
205  
206     tmp_return_value = PyTuple_New( 2 ); 174     tmp_return_value = PyTuple_New( 2 );
n 207     tmp_tuple_element_1 = var_l; n 175     tmp_tuple_element_1 = const_int_pos_1;
208  
209     Py_INCREF( tmp_tuple_element_1 ); 176     Py_INCREF( tmp_tuple_element_1 );
210     PyTuple_SET_ITEM( tmp_return_value, 0, tmp_tuple_element_1 ); 177     PyTuple_SET_ITEM( tmp_return_value, 0, tmp_tuple_element_1 );
211     tmp_tuple_element_1 = GET_STRING_DICT_VALUE( moduledict___main__, (Nuitka_StringObject *)const_str_plain_x ); 178     tmp_tuple_element_1 = GET_STRING_DICT_VALUE( moduledict___main__, (Nuitka_StringObject *)const_str_plain_x );
212 179
213     if (unlikely( tmp_tuple_element_1 == NULL )) 180     if (unlikely( tmp_tuple_element_1 == NULL ))
251     popFrameStack(); 218     popFrameStack();
252 #if PYTHON_VERSION >= 340 219 #if PYTHON_VERSION >= 340
253     frame_function->f_executing -= 1; 220     frame_function->f_executing -= 1;
254 #endif 221 #endif
255     Py_DECREF( frame_function ); 222     Py_DECREF( frame_function );
n 256     goto try_return_handler_1; n 223     goto function_return_exit;
257 224
258     frame_exception_exit_1:; 225     frame_exception_exit_1:;
259 #if 0 226 #if 0
260     RESTORE_FRAME_EXCEPTION( frame_function ); 227     RESTORE_FRAME_EXCEPTION( frame_function );
261 #endif 228 #endif
279 246
280         if (needs_detach) 247         if (needs_detach)
281         { 248         {
282 249
283             tmp_frame_locals = PyDict_New(); 250             tmp_frame_locals = PyDict_New();
n 284             if ( var_l ) n
285             {
286                 int res = PyDict_SetItem(
287                     tmp_frame_locals,
288                     const_str_plain_l,
289                     var_l
290                 );
291  
292                 assert( res == 0 );
293             }
294  
295 251
296 252
297             detachFrame( exception_tb, tmp_frame_locals ); 253             detachFrame( exception_tb, tmp_frame_locals );
298         } 254         }
299     } 255     }
311     frame_no_exception_1:; 267     frame_no_exception_1:;
312 268
313     // tried codes exits in all cases 269     // tried codes exits in all cases
314     NUITKA_CANNOT_GET_HERE( __main__$$$function_1_calledRepeatedly ); 270     NUITKA_CANNOT_GET_HERE( __main__$$$function_1_calledRepeatedly );
315     return NULL; 271     return NULL;
n 316     // Return handler code: n
317     try_return_handler_1:;
318     CHECK_OBJECT( (PyObject *)var_l );
319     Py_DECREF( var_l );
320     var_l = NULL;
321  
322     goto function_return_exit;
323     // Exception handler code: 272     // Exception handler code:
324     try_except_handler_1:; 273     try_except_handler_1:;
325     exception_keeper_type_1 = exception_type; 274     exception_keeper_type_1 = exception_type;
326     exception_keeper_value_1 = exception_value; 275     exception_keeper_value_1 = exception_value;
327     exception_keeper_tb_1 = exception_tb; 276     exception_keeper_tb_1 = exception_tb;
329     exception_type = NULL; 278     exception_type = NULL;
330     exception_value = NULL; 279     exception_value = NULL;
331     exception_tb = NULL; 280     exception_tb = NULL;
332     exception_lineno = -1; 281     exception_lineno = -1;
333 282
n 334     Py_XDECREF( var_l ); n
335     var_l = NULL;
336  
337     // Re-raise. 283     // Re-raise.
338     exception_type = exception_keeper_type_1; 284     exception_type = exception_keeper_type_1;
339     exception_value = exception_keeper_value_1; 285     exception_value = exception_keeper_value_1;
340     exception_tb = exception_keeper_tb_1; 286     exception_tb = exception_keeper_tb_1;
341     exception_lineno = exception_keeper_lineno_1; 287     exception_lineno = exception_keeper_lineno_1;
343     goto function_exception_exit; 289     goto function_exception_exit;
344     // End of try: 290     // End of try:
345 291
346     // Return statement must have exited already. 292     // Return statement must have exited already.
347     NUITKA_CANNOT_GET_HERE( __main__$$$function_1_calledRepeatedly ); 293     NUITKA_CANNOT_GET_HERE( __main__$$$function_1_calledRepeatedly );
t 348     return NULL; t
349  
350 function_exception_exit:
351     assert( exception_type );
352     RESTORE_ERROR_OCCURRED( exception_type, exception_value, exception_tb );
353  
354     return NULL;
355     function_return_exit:
356  
357     CHECK_OBJECT( tmp_return_value );
358     assert( had_error || !ERROR_OCCURRED() );
359     return tmp_return_value;
360  
361 }
362  
363  
364 NUITKA_LOCAL_MODULE PyObject *impl___main__$$$function_1_calledRepeatedly$$$function_1_listcontraction( PyObject **python_pars )
365 {
366 #ifndef __NUITKA_NO_ASSERT__
367     NUITKA_MAY_BE_UNUSED bool had_error = ERROR_OCCURRED();
368     assert(!had_error); // Do not enter inlined functions with error set.
369 #endif
370  
371     // Local variable declarations.
372     PyObject *par_$0 = python_pars[ 0 ];
373     PyObject *var_x = NULL;
374     PyObject *tmp_contraction_result = NULL;
375     PyObject *tmp_iter_value_0 = NULL;
376     PyObject *exception_type = NULL, *exception_value = NULL;
377     PyTracebackObject *exception_tb = NULL;
378     NUITKA_MAY_BE_UNUSED int exception_lineno = -1;
379     PyObject *exception_keeper_type_1;
380     PyObject *exception_keeper_value_1;
381     PyTracebackObject *exception_keeper_tb_1;
382     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_1;
383     PyObject *exception_keeper_type_2;
384     PyObject *exception_keeper_value_2;
385     PyTracebackObject *exception_keeper_tb_2;
386     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_2;
387     PyObject *tmp_append_list_1;
388     PyObject *tmp_append_value_1;
389     PyObject *tmp_assign_source_1;
390     PyObject *tmp_assign_source_2;
391     PyObject *tmp_assign_source_3;
392     PyObject *tmp_next_source_1;
393     int tmp_res;
394     PyObject *tmp_return_value;
395     tmp_return_value = NULL;
396  
397     // Actual function code.
398     tmp_assign_source_1 = PyList_New( 0 );
399     assert( tmp_contraction_result == NULL );
400     tmp_contraction_result = tmp_assign_source_1;
401  
402     // Tried code:
403     // Tried code:
404     loop_start_1:;
405     tmp_next_source_1 = par_$0;
406  
407     tmp_assign_source_2 = ITERATOR_NEXT( tmp_next_source_1 );
408     if ( tmp_assign_source_2 == NULL )
409     {
410         if ( CHECK_AND_CLEAR_STOP_ITERATION_OCCURRED() )
411         {
412  
413             goto loop_end_1;
414         }
415         else
416         {
417  
418             FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
419             PyThreadState_GET()->frame->f_lineno = 28;
420             goto try_except_handler_2;
421         }
422     }
423  
424     {
425         PyObject *old = tmp_iter_value_0;
426         tmp_iter_value_0 = tmp_assign_source_2;
427         Py_XDECREF( old );
428     }
429  
430     tmp_assign_source_3 = tmp_iter_value_0;
431  
432     {
433         PyObject *old = var_x;
434         var_x = tmp_assign_source_3;
435         Py_INCREF( var_x );
436         Py_XDECREF( old );
437     }
438  
439     tmp_append_list_1 = tmp_contraction_result;
440  
441     tmp_append_value_1 = var_x;
442  
443     assert( PyList_Check( tmp_append_list_1 ) );
444     tmp_res = PyList_Append( tmp_append_list_1, tmp_append_value_1 );
445     if ( tmp_res == -1 )
446     {
447         assert( ERROR_OCCURRED() );
448  
449         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
450  
451  
452         exception_lineno = 28;
453         goto try_except_handler_2;
454     }
455     if ( CONSIDER_THREADING() == false )
456     {
457         assert( ERROR_OCCURRED() );
458  
459         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
460  
461  
462         exception_lineno = 28;
463         goto try_except_handler_2;
464     }
465     goto loop_start_1;
466     loop_end_1:;
467     tmp_return_value = tmp_contraction_result;
468  
469     Py_INCREF( tmp_return_value );
470     goto try_return_handler_2;
471     // tried codes exits in all cases
472     NUITKA_CANNOT_GET_HERE( __main__$$$function_1_calledRepeatedly$$$function_1_listcontraction );
473     return NULL;
474     // Return handler code:
475     try_return_handler_2:;
476     Py_XDECREF( tmp_contraction_result );
477     tmp_contraction_result = NULL;
478  
479     Py_XDECREF( tmp_iter_value_0 );
480     tmp_iter_value_0 = NULL;
481  
482     goto try_return_handler_1;
483     // Exception handler code:
484     try_except_handler_2:;
485     exception_keeper_type_1 = exception_type;
486     exception_keeper_value_1 = exception_value;
487     exception_keeper_tb_1 = exception_tb;
488     exception_keeper_lineno_1 = exception_lineno;
489     exception_type = NULL;
490     exception_value = NULL;
491     exception_tb = NULL;
492     exception_lineno = -1;
493  
494     Py_XDECREF( tmp_contraction_result );
495     tmp_contraction_result = NULL;
496  
497     Py_XDECREF( tmp_iter_value_0 );
498     tmp_iter_value_0 = NULL;
499  
500     // Re-raise.
501     exception_type = exception_keeper_type_1;
502     exception_value = exception_keeper_value_1;
503     exception_tb = exception_keeper_tb_1;
504     exception_lineno = exception_keeper_lineno_1;
505  
506     goto try_except_handler_1;
507     // End of try:
508     // tried codes exits in all cases
509     NUITKA_CANNOT_GET_HERE( __main__$$$function_1_calledRepeatedly$$$function_1_listcontraction );
510     return NULL;
511     // Return handler code:
512     try_return_handler_1:;
513     Py_XDECREF( par_$0 );
514     par_$0 = NULL;
515  
516     Py_XDECREF( var_x );
517     var_x = NULL;
518  
519     goto function_return_exit;
520     // Exception handler code:
521     try_except_handler_1:;
522     exception_keeper_type_2 = exception_type;
523     exception_keeper_value_2 = exception_value;
524     exception_keeper_tb_2 = exception_tb;
525     exception_keeper_lineno_2 = exception_lineno;
526     exception_type = NULL;
527     exception_value = NULL;
528     exception_tb = NULL;
529     exception_lineno = -1;
530  
531     Py_XDECREF( par_$0 );
532     par_$0 = NULL;
533  
534     Py_XDECREF( var_x );
535     var_x = NULL;
536  
537     // Re-raise.
538     exception_type = exception_keeper_type_2;
539     exception_value = exception_keeper_value_2;
540     exception_tb = exception_keeper_tb_2;
541     exception_lineno = exception_keeper_lineno_2;
542  
543     goto function_exception_exit;
544     // End of try:
545  
546     // Return statement must have exited already.
547     NUITKA_CANNOT_GET_HERE( __main__$$$function_1_calledRepeatedly$$$function_1_listcontraction );
548     return NULL; 294     return NULL;
549 295
550 function_exception_exit: 296 function_exception_exit:
551     assert( exception_type ); 297     assert( exception_type );
552     RESTORE_ERROR_OCCURRED( exception_type, exception_value, exception_tb ); 298     RESTORE_ERROR_OCCURRED( exception_type, exception_value, exception_tb );