Construct LoopSmallRange

Performance Diagrams

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