Construct LoopSmallRange

Performance Diagrams

Construct LoopSmallRange 00100000001000000020000000200000003000000030000000400000004000000050000000500000006000000060000000700000007000000080000000800000009000000090000000100000000100000000110000000110000000120000000120000000CPython 2.7Nuitka (master)Nuitka (develop)Nuitka (factory)12613307488.11538461538461257.0CPython 2.751831614240.03846153846155402.5687496000028Nuitka (master)51838828391.96153846153845402.5546161905164Nuitka (develop)51845762543.8846153846154402.5410313469652Nuitka (factory)Construct LoopSmallRangeTicks Construct LoopSmallRange 00100000001000000020000000200000003000000030000000400000004000000050000000500000006000000060000000700000007000000080000000800000009000000090000000100000000100000000110000000110000000120000000120000000130000000130000000CPython 3.5Nuitka (master)Nuitka (develop)Nuitka (factory)13895790988.11538461538461257.0CPython 3.588647249240.03846153846155346.4698127341125Nuitka (master)88646801391.96153846153845346.47060943358144Nuitka (develop)88647232543.8846153846154346.46984296601204Nuitka (factory)Construct LoopSmallRangeTicks

Source Code with Construct

module_value1 = 5
module_value2 = 3

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

    # Make sure we have a local variable x anyway
    x = 2

    local_value = module_value1

# construct_begin
    for x in range(local_value, local_value+3):
        pass
# construct_end

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

print("OK.")

Source Code without Construct

module_value1 = 5
module_value2 = 3

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

    # Make sure we have a local variable x anyway
    x = 2

    local_value = module_value1

# construct_begin




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

print("OK.")

Context Diff of Source Code


Construct
Baseline
29     x = 2 29     x = 2
30 30
31     local_value = module_value1 31     local_value = module_value1
32 32
33 # construct_begin 33 # construct_begin
t 34     for x in range(local_value, local_value+3): t 34  
35         pass 35  
36 # construct_end 36  
37 37
38 import itertools 38 import itertools
39 for x in itertools.repeat(None, 50000): 39 for x in itertools.repeat(None, 50000):
40     calledRepeatedly() 40     calledRepeatedly()
41 41

Context Diff of Generated Code


Construct
Baseline
47 static PyObject *const_str_plain_x; 47 static PyObject *const_str_plain_x;
48 extern PyObject *const_tuple_empty; 48 extern PyObject *const_tuple_empty;
49 static PyObject *const_str_digest_5ed1392909ad16e6227b8230f4582352; 49 static PyObject *const_str_digest_5ed1392909ad16e6227b8230f4582352;
50 static PyObject *const_int_pos_5; 50 static PyObject *const_int_pos_5;
51 static PyObject *const_str_plain_repeat; 51 static PyObject *const_str_plain_repeat;
n 52 static PyObject *const_int_pos_2; n
53 static PyObject *const_str_digest_46cfc54eef6b5c144cb67464bfc7d174; 52 static PyObject *const_str_digest_46cfc54eef6b5c144cb67464bfc7d174;
54 static PyObject *const_tuple_none_int_pos_50000_tuple; 53 static PyObject *const_tuple_none_int_pos_50000_tuple;
55 static PyObject *const_tuple_str_plain_x_str_plain_local_value_tuple; 54 static PyObject *const_tuple_str_plain_x_str_plain_local_value_tuple;
56 extern PyObject *const_str_plain___main__; 55 extern PyObject *const_str_plain___main__;
57 extern PyObject *const_str_plain___doc__; 56 extern PyObject *const_str_plain___doc__;
75     const_str_angle_module = UNSTREAM_STRING_ASCII( &constant_bin[ 65 ], 8, 0 ); 74     const_str_angle_module = UNSTREAM_STRING_ASCII( &constant_bin[ 65 ], 8, 0 );
76     const_str_plain_None = UNSTREAM_STRING_ASCII( &constant_bin[ 73 ], 4, 1 ); 75     const_str_plain_None = UNSTREAM_STRING_ASCII( &constant_bin[ 73 ], 4, 1 );
77     const_str_plain_x = UNSTREAM_STRING_ASCII( &constant_bin[ 77 ], 1, 1 ); 76     const_str_plain_x = UNSTREAM_STRING_ASCII( &constant_bin[ 77 ], 1, 1 );
78     const_int_pos_5 = PyLong_FromUnsignedLong( 5ul ); 77     const_int_pos_5 = PyLong_FromUnsignedLong( 5ul );
79     const_str_plain_repeat = UNSTREAM_STRING_ASCII( &constant_bin[ 78 ], 6, 1 ); 78     const_str_plain_repeat = UNSTREAM_STRING_ASCII( &constant_bin[ 78 ], 6, 1 );
n 80     const_int_pos_2 = PyLong_FromUnsignedLong( 2ul ); n
81     const_str_digest_46cfc54eef6b5c144cb67464bfc7d174 = UNSTREAM_STRING_ASCII( &constant_bin[ 84 ], 65, 0 ); 79     const_str_digest_46cfc54eef6b5c144cb67464bfc7d174 = UNSTREAM_STRING_ASCII( &constant_bin[ 84 ], 65, 0 );
82     const_tuple_none_int_pos_50000_tuple = PyTuple_New( 2 ); 80     const_tuple_none_int_pos_50000_tuple = PyTuple_New( 2 );
83     PyTuple_SET_ITEM( const_tuple_none_int_pos_50000_tuple, 0, Py_None ); Py_INCREF( Py_None ); 81     PyTuple_SET_ITEM( const_tuple_none_int_pos_50000_tuple, 0, Py_None ); Py_INCREF( Py_None );
84     PyTuple_SET_ITEM( const_tuple_none_int_pos_50000_tuple, 1, const_int_pos_50000 ); Py_INCREF( const_int_pos_50000 ); 82     PyTuple_SET_ITEM( const_tuple_none_int_pos_50000_tuple, 1, const_int_pos_50000 ); Py_INCREF( const_int_pos_50000 );
85     const_tuple_str_plain_x_str_plain_local_value_tuple = PyTuple_New( 2 ); 83     const_tuple_str_plain_x_str_plain_local_value_tuple = PyTuple_New( 2 );
124 #ifndef __NUITKA_NO_ASSERT__ 122 #ifndef __NUITKA_NO_ASSERT__
125     NUITKA_MAY_BE_UNUSED bool had_error = ERROR_OCCURRED(); 123     NUITKA_MAY_BE_UNUSED bool had_error = ERROR_OCCURRED();
126 #endif 124 #endif
127 125
128     // Local variable declarations. 126     // Local variable declarations.
n 129     PyObject *var_x = NULL; n
130     PyObject *var_local_value = NULL; 127     PyObject *var_local_value = NULL;
n 131     PyObject *tmp_for_loop_1__for_iterator = NULL; n
132     PyObject *tmp_for_loop_1__iter_value = NULL;
133     struct Nuitka_FrameObject *frame_9964c5f963ec6435b5b0181738ca11be; 128     struct Nuitka_FrameObject *frame_9964c5f963ec6435b5b0181738ca11be;
134     NUITKA_MAY_BE_UNUSED char const *type_description_1 = NULL; 129     NUITKA_MAY_BE_UNUSED char const *type_description_1 = NULL;
135     PyObject *exception_type = NULL; 130     PyObject *exception_type = NULL;
136     PyObject *exception_value = NULL; 131     PyObject *exception_value = NULL;
137     PyTracebackObject *exception_tb = NULL; 132     PyTracebackObject *exception_tb = NULL;
138     NUITKA_MAY_BE_UNUSED int exception_lineno = 0; 133     NUITKA_MAY_BE_UNUSED int exception_lineno = 0;
n n 134     static struct Nuitka_FrameObject *cache_frame_9964c5f963ec6435b5b0181738ca11be = NULL;
135     PyObject *tmp_return_value = NULL;
139     PyObject *exception_keeper_type_1; 136     PyObject *exception_keeper_type_1;
140     PyObject *exception_keeper_value_1; 137     PyObject *exception_keeper_value_1;
141     PyTracebackObject *exception_keeper_tb_1; 138     PyTracebackObject *exception_keeper_tb_1;
142     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_1; 139     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_1;
n 143     static struct Nuitka_FrameObject *cache_frame_9964c5f963ec6435b5b0181738ca11be = NULL; n
144     PyObject *tmp_return_value = NULL;
145     PyObject *exception_keeper_type_2;
146     PyObject *exception_keeper_value_2;
147     PyTracebackObject *exception_keeper_tb_2;
148     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_2;
149 140
150     // Actual function code. 141     // Actual function code.
151     { 142     {
152     // Tried code: 143     // Tried code:
153     MAKE_OR_REUSE_FRAME( cache_frame_9964c5f963ec6435b5b0181738ca11be, codeobj_9964c5f963ec6435b5b0181738ca11be, module___main__, sizeof(void *)+sizeof(void *) ); 144     MAKE_OR_REUSE_FRAME( cache_frame_9964c5f963ec6435b5b0181738ca11be, codeobj_9964c5f963ec6435b5b0181738ca11be, module___main__, sizeof(void *)+sizeof(void *) );
178         exception_tb = NULL; 169         exception_tb = NULL;
179         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb ); 170         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
180         CHAIN_EXCEPTION( exception_value ); 171         CHAIN_EXCEPTION( exception_value );
181 172
182         exception_lineno = 26; 173         exception_lineno = 26;
n 183         type_description_1 = "oo"; n 174         type_description_1 = "No";
184         goto frame_exception_exit_1; 175         goto frame_exception_exit_1;
185     } 176     }
186 177
187     } 178     }
188     { 179     {
189     PyObject *tmp_assign_source_1; 180     PyObject *tmp_assign_source_1;
n 190     tmp_assign_source_1 = const_int_pos_2; n
191     assert( var_x == NULL );
192     Py_INCREF( tmp_assign_source_1 );
193     var_x = tmp_assign_source_1;
194  
195     }
196     {
197     PyObject *tmp_assign_source_2;
198     PyObject *tmp_mvar_value_2; 181     PyObject *tmp_mvar_value_2;
199     tmp_mvar_value_2 = GET_STRING_DICT_VALUE( moduledict___main__, (Nuitka_StringObject *)const_str_plain_module_value1 ); 182     tmp_mvar_value_2 = GET_STRING_DICT_VALUE( moduledict___main__, (Nuitka_StringObject *)const_str_plain_module_value1 );
200 183
201     if (unlikely( tmp_mvar_value_2 == NULL )) 184     if (unlikely( tmp_mvar_value_2 == NULL ))
202     { 185     {
212         exception_tb = NULL; 195         exception_tb = NULL;
213         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb ); 196         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
214         CHAIN_EXCEPTION( exception_value ); 197         CHAIN_EXCEPTION( exception_value );
215 198
216         exception_lineno = 31; 199         exception_lineno = 31;
n 217         type_description_1 = "oo"; n 200         type_description_1 = "No";
218         goto frame_exception_exit_1; 201         goto frame_exception_exit_1;
219     } 202     }
220 203
n 221     tmp_assign_source_2 = tmp_mvar_value_2; n 204     tmp_assign_source_1 = tmp_mvar_value_2;
222     assert( var_local_value == NULL ); 205     assert( var_local_value == NULL );
n 223     Py_INCREF( tmp_assign_source_2 ); n 206     Py_INCREF( tmp_assign_source_1 );
224     var_local_value = tmp_assign_source_2; 207     var_local_value = tmp_assign_source_1;
225 208
n 226     } n
227     { 209     }
228     PyObject *tmp_assign_source_3; 210  
229     PyObject *tmp_iter_arg_1; 211 #if 0
230     PyObject *tmp_xrange_low_1; 212     RESTORE_FRAME_EXCEPTION( frame_9964c5f963ec6435b5b0181738ca11be );
231     PyObject *tmp_xrange_high_1; 213 #endif
232     PyObject *tmp_left_name_1; 214  
233     PyObject *tmp_right_name_1; 215     // Put the previous frame back on top.
234     CHECK_OBJECT( var_local_value ); 216     popFrameStack();
235     tmp_xrange_low_1 = var_local_value; 217  
236     CHECK_OBJECT( var_local_value ); 218     goto frame_no_exception_1;
237     tmp_left_name_1 = var_local_value; 219  
238     tmp_right_name_1 = const_int_pos_3; 220     frame_exception_exit_1:;
239     tmp_xrange_high_1 = BINARY_OPERATION_ADD_OBJECT_OBJECT( tmp_left_name_1, tmp_right_name_1 ); 221  
240     if ( tmp_xrange_high_1 == NULL ) 222 #if 0
223     RESTORE_FRAME_EXCEPTION( frame_9964c5f963ec6435b5b0181738ca11be );
224 #endif
225  
226     if ( exception_tb == NULL )
227     {
228         exception_tb = MAKE_TRACEBACK( frame_9964c5f963ec6435b5b0181738ca11be, exception_lineno );
241     { 229     }
242         assert( ERROR_OCCURRED() ); 230     else if ( exception_tb->tb_frame != &frame_9964c5f963ec6435b5b0181738ca11be->m_frame )
231     {
232         exception_tb = ADD_TRACEBACK( exception_tb, frame_9964c5f963ec6435b5b0181738ca11be, exception_lineno );
233     }
243 234
n 244         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb ); n 235     // Attachs locals to frame if any.
245   236     Nuitka_Frame_AttachLocals(
246   237         (struct Nuitka_FrameObject *)frame_9964c5f963ec6435b5b0181738ca11be,
247         exception_lineno = 34;
248         type_description_1 = "oo"; 238         type_description_1,
249         goto frame_exception_exit_1; 239         NULL,
240         var_local_value
241     );
242  
243  
244     // Release cached frame.
245     if ( frame_9964c5f963ec6435b5b0181738ca11be == cache_frame_9964c5f963ec6435b5b0181738ca11be )
250     } 246     {
251     tmp_iter_arg_1 = BUILTIN_XRANGE2( tmp_xrange_low_1, tmp_xrange_high_1 ); 247         Py_DECREF( frame_9964c5f963ec6435b5b0181738ca11be );
252     Py_DECREF( tmp_xrange_high_1 );
253     if ( tmp_iter_arg_1 == NULL )
254     { 248     }
255         assert( ERROR_OCCURRED() ); 249     cache_frame_9964c5f963ec6435b5b0181738ca11be = NULL;
256 250
n 257         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb ); n 251     assertFrameObject( frame_9964c5f963ec6435b5b0181738ca11be );
258 252
n n 253     // Put the previous frame back on top.
254     popFrameStack();
259 255
n 260         exception_lineno = 34; n 256     // Return the error.
261         type_description_1 = "oo";
262         goto frame_exception_exit_1;
263     }
264     tmp_assign_source_3 = MAKE_ITERATOR( tmp_iter_arg_1 );
265     Py_DECREF( tmp_iter_arg_1 );
266     if ( tmp_assign_source_3 == NULL )
267     {
268         assert( ERROR_OCCURRED() );
269  
270         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
271  
272  
273         exception_lineno = 34;
274         type_description_1 = "oo";
275         goto frame_exception_exit_1;
276     }
277     assert( tmp_for_loop_1__for_iterator == NULL );
278     tmp_for_loop_1__for_iterator = tmp_assign_source_3;
279  
280     }
281     {
282     // Tried code:
283     {
284     loop_start_1:;
285     {
286     PyObject *tmp_next_source_1;
287     PyObject *tmp_assign_source_4;
288     CHECK_OBJECT( tmp_for_loop_1__for_iterator );
289     tmp_next_source_1 = tmp_for_loop_1__for_iterator;
290     tmp_assign_source_4 = ITERATOR_NEXT( tmp_next_source_1 );
291     if ( tmp_assign_source_4 == NULL )
292     {
293         if ( CHECK_AND_CLEAR_STOP_ITERATION_OCCURRED() )
294         {
295  
296             goto loop_end_1;
297         }
298         else
299         {
300  
301             FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
302             type_description_1 = "oo";
303             exception_lineno = 34;
304             goto try_except_handler_2;
305         }
306     }
307  
308     {
309         PyObject *old = tmp_for_loop_1__iter_value;
310         tmp_for_loop_1__iter_value = tmp_assign_source_4;
311         Py_XDECREF( old );
312     }
313  
314     }
315     {
316     PyObject *tmp_assign_source_5;
317     CHECK_OBJECT( tmp_for_loop_1__iter_value );
318     tmp_assign_source_5 = tmp_for_loop_1__iter_value;
319     {
320         PyObject *old = var_x;
321         var_x = tmp_assign_source_5;
322         Py_INCREF( var_x );
323         Py_XDECREF( old );
324     }
325  
326     }
327     if ( CONSIDER_THREADING() == false )
328     {
329         assert( ERROR_OCCURRED() );
330  
331         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
332  
333  
334         exception_lineno = 34;
335         type_description_1 = "oo";
336         goto try_except_handler_2; 257     goto try_except_handler_1;
258  
259     frame_no_exception_1:;
337     } 260     {
338     goto loop_start_1; 261     tmp_return_value = Py_None;
339     loop_end_1:; 262     Py_INCREF( tmp_return_value );
263     goto try_return_handler_1;
264     }
265     // tried codes exits in all cases
266     NUITKA_CANNOT_GET_HERE( __main__$$$function_1_calledRepeatedly );
267     return NULL;
268     // Return handler code:
269     try_return_handler_1:;
340     } 270     {
341     goto try_end_1; 271     CHECK_OBJECT( (PyObject *)var_local_value );
272     Py_DECREF( var_local_value );
273     var_local_value = NULL;
274  
275     }
276     {
277     goto function_return_exit;
278     }
342     // Exception handler code: 279     // Exception handler code:
n 343     try_except_handler_2:; n 280     try_except_handler_1:;
344     exception_keeper_type_1 = exception_type; 281     exception_keeper_type_1 = exception_type;
345     exception_keeper_value_1 = exception_value; 282     exception_keeper_value_1 = exception_value;
346     exception_keeper_tb_1 = exception_tb; 283     exception_keeper_tb_1 = exception_tb;
347     exception_keeper_lineno_1 = exception_lineno; 284     exception_keeper_lineno_1 = exception_lineno;
348     exception_type = NULL; 285     exception_type = NULL;
349     exception_value = NULL; 286     exception_value = NULL;
350     exception_tb = NULL; 287     exception_tb = NULL;
351     exception_lineno = 0; 288     exception_lineno = 0;
352 289
353     { 290     {
n 354     Py_XDECREF( tmp_for_loop_1__iter_value ); n
355     tmp_for_loop_1__iter_value = NULL;
356  
357     }
358     {
359     CHECK_OBJECT( (PyObject *)tmp_for_loop_1__for_iterator );
360     Py_DECREF( tmp_for_loop_1__for_iterator );
361     tmp_for_loop_1__for_iterator = NULL;
362  
363     }
364     {
365     // Re-raise. 291     // Re-raise.
366     exception_type = exception_keeper_type_1; 292     exception_type = exception_keeper_type_1;
367     exception_value = exception_keeper_value_1; 293     exception_value = exception_keeper_value_1;
368     exception_tb = exception_keeper_tb_1; 294     exception_tb = exception_keeper_tb_1;
369     exception_lineno = exception_keeper_lineno_1; 295     exception_lineno = exception_keeper_lineno_1;
t 370   t
371     goto frame_exception_exit_1;
372     }
373     // End of try:
374     try_end_1:;
375     }
376  
377 #if 0
378     RESTORE_FRAME_EXCEPTION( frame_9964c5f963ec6435b5b0181738ca11be );
379 #endif
380  
381     // Put the previous frame back on top.
382     popFrameStack();
383  
384     goto frame_no_exception_1;
385  
386     frame_exception_exit_1:;
387  
388 #if 0
389     RESTORE_FRAME_EXCEPTION( frame_9964c5f963ec6435b5b0181738ca11be );
390 #endif
391  
392     if ( exception_tb == NULL )
393     {
394         exception_tb = MAKE_TRACEBACK( frame_9964c5f963ec6435b5b0181738ca11be, exception_lineno );
395     }
396     else if ( exception_tb->tb_frame != &frame_9964c5f963ec6435b5b0181738ca11be->m_frame )
397     {
398         exception_tb = ADD_TRACEBACK( exception_tb, frame_9964c5f963ec6435b5b0181738ca11be, exception_lineno );
399     }
400  
401     // Attachs locals to frame if any.
402     Nuitka_Frame_AttachLocals(
403         (struct Nuitka_FrameObject *)frame_9964c5f963ec6435b5b0181738ca11be,
404         type_description_1,
405         var_x,
406         var_local_value
407     );
408  
409  
410     // Release cached frame.
411     if ( frame_9964c5f963ec6435b5b0181738ca11be == cache_frame_9964c5f963ec6435b5b0181738ca11be )
412     {
413         Py_DECREF( frame_9964c5f963ec6435b5b0181738ca11be );
414     }
415     cache_frame_9964c5f963ec6435b5b0181738ca11be = NULL;
416  
417     assertFrameObject( frame_9964c5f963ec6435b5b0181738ca11be );
418  
419     // Put the previous frame back on top.
420     popFrameStack();
421  
422     // Return the error.
423     goto try_except_handler_1;
424  
425     frame_no_exception_1:;
426     {
427     Py_XDECREF( tmp_for_loop_1__iter_value );
428     tmp_for_loop_1__iter_value = NULL;
429  
430     }
431     {
432     CHECK_OBJECT( (PyObject *)tmp_for_loop_1__for_iterator );
433     Py_DECREF( tmp_for_loop_1__for_iterator );
434     tmp_for_loop_1__for_iterator = NULL;
435  
436     }
437     {
438     tmp_return_value = Py_None;
439     Py_INCREF( tmp_return_value );
440     goto try_return_handler_1;
441     }
442     // tried codes exits in all cases
443     NUITKA_CANNOT_GET_HERE( __main__$$$function_1_calledRepeatedly );
444     return NULL;
445     // Return handler code:
446     try_return_handler_1:;
447     {
448     Py_XDECREF( var_x );
449     var_x = NULL;
450  
451     }
452     {
453     Py_XDECREF( var_local_value );
454     var_local_value = NULL;
455  
456     }
457     {
458     goto function_return_exit;
459     }
460     // Exception handler code:
461     try_except_handler_1:;
462     exception_keeper_type_2 = exception_type;
463     exception_keeper_value_2 = exception_value;
464     exception_keeper_tb_2 = exception_tb;
465     exception_keeper_lineno_2 = exception_lineno;
466     exception_type = NULL;
467     exception_value = NULL;
468     exception_tb = NULL;
469     exception_lineno = 0;
470  
471     {
472     Py_XDECREF( var_x );
473     var_x = NULL;
474  
475     }
476     {
477     Py_XDECREF( var_local_value );
478     var_local_value = NULL;
479  
480     }
481     {
482     // Re-raise.
483     exception_type = exception_keeper_type_2;
484     exception_value = exception_keeper_value_2;
485     exception_tb = exception_keeper_tb_2;
486     exception_lineno = exception_keeper_lineno_2;
487 296
488     goto function_exception_exit; 297     goto function_exception_exit;
489     } 298     }
490     // End of try: 299     // End of try:
491     } 300     }