Construct LoopSmallRange

Performance Diagrams

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