Construct LoopSmallRange

Performance Diagrams

Construct LoopSmallRange 00100000001000000020000000200000003000000030000000400000004000000050000000500000006000000060000000700000007000000080000000800000009000000090000000CPython 2.7Nuitka (master)Nuitka (develop)Nuitka (factory)9317931988.95192307692307257.0CPython 2.725055970242.31730769230768437.66592211757927Nuitka (master)25055998395.6826923076923437.66584786042824Nuitka (develop)25055998549.0480769230769437.66584786042824Nuitka (factory)Construct LoopSmallRangeTicks Construct LoopSmallRange 00100000001000000020000000200000003000000030000000400000004000000050000000500000006000000060000000700000007000000080000000800000009000000090000000100000000100000000CPython 3.8Nuitka (master)Nuitka (develop)Nuitka (factory)10395744188.11538461538461257.0CPython 3.863253909240.03846153846155353.7556421996249Nuitka (master)63253904391.96153846153845353.755654085036Nuitka (develop)63252926543.8846153846154353.75797887144694Nuitka (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
82 static PyCodeObject *codeobj_5ac58c877419472c7a84becd923ab417; 82 static PyCodeObject *codeobj_5ac58c877419472c7a84becd923ab417;
83 /* For use in "MainProgram.c". */ 83 /* For use in "MainProgram.c". */
84 PyCodeObject *codeobj_main = NULL; 84 PyCodeObject *codeobj_main = NULL;
85 85
86 static void createModuleCodeObjects(void) { 86 static void createModuleCodeObjects(void) {
n 87     module_filename_obj = mod_consts[4]; CHECK_OBJECT(module_filename_obj); n 87     module_filename_obj = mod_consts[3]; CHECK_OBJECT(module_filename_obj);
88     codeobj_4f829774b636b5d7a14d25493bb2083c = MAKE_CODEOBJECT(module_filename_obj, 1, CO_NOFREE, mod_consts[18], NULL, NULL, 0, 0, 0); 88     codeobj_4f829774b636b5d7a14d25493bb2083c = MAKE_CODEOBJECT(module_filename_obj, 1, CO_NOFREE, mod_consts[18], NULL, NULL, 0, 0, 0);
89     codeobj_5ac58c877419472c7a84becd923ab417 = MAKE_CODEOBJECT(module_filename_obj, 24, CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE, mod_consts[10], mod_consts[19], NULL, 0, 0, 0); 89     codeobj_5ac58c877419472c7a84becd923ab417 = MAKE_CODEOBJECT(module_filename_obj, 24, CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE, mod_consts[10], mod_consts[19], NULL, 0, 0, 0);
90 } 90 }
91 91
92 // The module function declarations. 92 // The module function declarations.
101 #endif 101 #endif
102 102
103     // Local variable declarations. 103     // Local variable declarations.
104     PyObject *var_x = NULL; 104     PyObject *var_x = NULL;
105     PyObject *var_local_value = NULL; 105     PyObject *var_local_value = NULL;
n 106     PyObject *tmp_for_loop_1__for_iterator = NULL; n
107     PyObject *tmp_for_loop_1__iter_value = NULL;
108     struct Nuitka_FrameObject *frame_5ac58c877419472c7a84becd923ab417; 106     struct Nuitka_FrameObject *frame_5ac58c877419472c7a84becd923ab417;
109     NUITKA_MAY_BE_UNUSED char const *type_description_1 = NULL; 107     NUITKA_MAY_BE_UNUSED char const *type_description_1 = NULL;
110     NUITKA_MAY_BE_UNUSED nuitka_void tmp_unused; 108     NUITKA_MAY_BE_UNUSED nuitka_void tmp_unused;
111     PyObject *exception_type = NULL; 109     PyObject *exception_type = NULL;
112     PyObject *exception_value = NULL; 110     PyObject *exception_value = NULL;
113     PyTracebackObject *exception_tb = NULL; 111     PyTracebackObject *exception_tb = NULL;
114     NUITKA_MAY_BE_UNUSED int exception_lineno = 0; 112     NUITKA_MAY_BE_UNUSED int exception_lineno = 0;
n n 113     static struct Nuitka_FrameObject *cache_frame_5ac58c877419472c7a84becd923ab417 = NULL;
114     PyObject *tmp_return_value = NULL;
115     PyObject *exception_keeper_type_1; 115     PyObject *exception_keeper_type_1;
116     PyObject *exception_keeper_value_1; 116     PyObject *exception_keeper_value_1;
117     PyTracebackObject *exception_keeper_tb_1; 117     PyTracebackObject *exception_keeper_tb_1;
118     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_1; 118     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_1;
n 119     static struct Nuitka_FrameObject *cache_frame_5ac58c877419472c7a84becd923ab417 = NULL; n
120     PyObject *tmp_return_value = NULL;
121     PyObject *exception_keeper_type_2;
122     PyObject *exception_keeper_value_2;
123     PyTracebackObject *exception_keeper_tb_2;
124     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_2;
125 119
126     // Actual function body. 120     // Actual function body.
127     // Tried code: 121     // Tried code:
128     if (isFrameUnusable(cache_frame_5ac58c877419472c7a84becd923ab417)) { 122     if (isFrameUnusable(cache_frame_5ac58c877419472c7a84becd923ab417)) {
129         Py_XDECREF(cache_frame_5ac58c877419472c7a84becd923ab417); 123         Py_XDECREF(cache_frame_5ac58c877419472c7a84becd923ab417);
198         } 192         }
199         assert(var_local_value == NULL); 193         assert(var_local_value == NULL);
200         Py_INCREF(tmp_assign_source_2); 194         Py_INCREF(tmp_assign_source_2);
201         var_local_value = tmp_assign_source_2; 195         var_local_value = tmp_assign_source_2;
202     } 196     }
n n 197  
198 #if 0
199     RESTORE_FRAME_EXCEPTION(frame_5ac58c877419472c7a84becd923ab417);
200 #endif
201  
202     // Put the previous frame back on top.
203     popFrameStack();
204  
205     goto frame_no_exception_1;
206  
207     frame_exception_exit_1:;
208  
209 #if 0
210     RESTORE_FRAME_EXCEPTION(frame_5ac58c877419472c7a84becd923ab417);
211 #endif
212  
213     if (exception_tb == NULL) {
214         exception_tb = MAKE_TRACEBACK(frame_5ac58c877419472c7a84becd923ab417, exception_lineno);
215     } else if (exception_tb->tb_frame != &frame_5ac58c877419472c7a84becd923ab417->m_frame) {
216         exception_tb = ADD_TRACEBACK(exception_tb, frame_5ac58c877419472c7a84becd923ab417, exception_lineno);
203     { 217     }
204         PyObject *tmp_assign_source_3; 218  
205         PyObject *tmp_iter_arg_1; 219     // Attaches locals to frame if any.
206         PyObject *tmp_xrange_low_1; 220     Nuitka_Frame_AttachLocals(
207         PyObject *tmp_xrange_high_1; 221         frame_5ac58c877419472c7a84becd923ab417,
208         PyObject *tmp_left_name_1; 222         type_description_1,
209         PyObject *tmp_right_name_1; 223         var_x,
224         var_local_value
225     );
226  
227  
228     // Release cached frame if used for exception.
229     if (frame_5ac58c877419472c7a84becd923ab417 == cache_frame_5ac58c877419472c7a84becd923ab417) {
230 #if _DEBUG_REFCOUNTS
231         count_active_frame_cache_instances -= 1;
232         count_released_frame_cache_instances += 1;
233 #endif
234  
235         Py_DECREF(cache_frame_5ac58c877419472c7a84becd923ab417);
236         cache_frame_5ac58c877419472c7a84becd923ab417 = NULL;
237     }
238  
239     assertFrameObject(frame_5ac58c877419472c7a84becd923ab417);
240  
241     // Put the previous frame back on top.
242     popFrameStack();
243  
244     // Return the error.
245     goto try_except_handler_1;
246  
247     frame_no_exception_1:;
248     tmp_return_value = Py_None;
249     Py_INCREF(tmp_return_value);
250     goto try_return_handler_1;
251     NUITKA_CANNOT_GET_HERE("tried codes exits in all cases");
252     return NULL;
253     // Return handler code:
254     try_return_handler_1:;
255     CHECK_OBJECT(var_x);
256     Py_DECREF(var_x);
257     var_x = NULL;
210         CHECK_OBJECT(var_local_value); 258     CHECK_OBJECT(var_local_value);
211         tmp_xrange_low_1 = var_local_value; 259     Py_DECREF(var_local_value);
212         CHECK_OBJECT(var_local_value); 260     var_local_value = NULL;
213         tmp_left_name_1 = var_local_value; 261     goto function_return_exit;
214         tmp_right_name_1 = mod_consts[2];
215         tmp_xrange_high_1 = BINARY_OPERATION_ADD_OBJECT_OBJECT_LONG(tmp_left_name_1, tmp_right_name_1);
216         if (tmp_xrange_high_1 == NULL) {
217             assert(ERROR_OCCURRED());
218  
219             FETCH_ERROR_OCCURRED(&exception_type, &exception_value, &exception_tb);
220  
221  
222             exception_lineno = 34;
223             type_description_1 = "oo";
224             goto frame_exception_exit_1;
225         }
226         tmp_iter_arg_1 = BUILTIN_XRANGE2(tmp_xrange_low_1, tmp_xrange_high_1);
227         Py_DECREF(tmp_xrange_high_1);
228         if (tmp_iter_arg_1 == NULL) {
229             assert(ERROR_OCCURRED());
230  
231             FETCH_ERROR_OCCURRED(&exception_type, &exception_value, &exception_tb);
232  
233  
234             exception_lineno = 34;
235             type_description_1 = "oo";
236             goto frame_exception_exit_1;
237         }
238         tmp_assign_source_3 = MAKE_ITERATOR(tmp_iter_arg_1);
239         Py_DECREF(tmp_iter_arg_1);
240         if (tmp_assign_source_3 == NULL) {
241             assert(ERROR_OCCURRED());
242  
243             FETCH_ERROR_OCCURRED(&exception_type, &exception_value, &exception_tb);
244  
245  
246             exception_lineno = 34;
247             type_description_1 = "oo";
248             goto frame_exception_exit_1;
249         }
250         assert(tmp_for_loop_1__for_iterator == NULL);
251         tmp_for_loop_1__for_iterator = tmp_assign_source_3;
252     }
253     // Tried code:
254     loop_start_1:;
255     {
256         PyObject *tmp_next_source_1;
257         PyObject *tmp_assign_source_4;
258         CHECK_OBJECT(tmp_for_loop_1__for_iterator);
259         tmp_next_source_1 = tmp_for_loop_1__for_iterator;
260         tmp_assign_source_4 = ITERATOR_NEXT(tmp_next_source_1);
261         if (tmp_assign_source_4 == NULL) {
262             if (CHECK_AND_CLEAR_STOP_ITERATION_OCCURRED()) {
263  
264                 goto loop_end_1;
265             } else {
266  
267                 FETCH_ERROR_OCCURRED(&exception_type, &exception_value, &exception_tb);
268                 type_description_1 = "oo";
269                 exception_lineno = 34;
270                 goto try_except_handler_2;
271             }
272         }
273  
274         {
275             PyObject *old = tmp_for_loop_1__iter_value;
276             tmp_for_loop_1__iter_value = tmp_assign_source_4;
277             Py_XDECREF(old);
278         }
279  
280     }
281     {
282         PyObject *tmp_assign_source_5;
283         CHECK_OBJECT(tmp_for_loop_1__iter_value);
284         tmp_assign_source_5 = tmp_for_loop_1__iter_value;
285         {
286             PyObject *old = var_x;
287             var_x = tmp_assign_source_5;
288             Py_INCREF(var_x);
289             Py_XDECREF(old);
290         }
291  
292     }
293     if (CONSIDER_THREADING() == false) {
294         assert(ERROR_OCCURRED());
295  
296         FETCH_ERROR_OCCURRED(&exception_type, &exception_value, &exception_tb);
297  
298  
299         exception_lineno = 34;
300         type_description_1 = "oo";
301         goto try_except_handler_2;
302     }
303     goto loop_start_1;
304     loop_end_1:;
305     goto try_end_1;
306     // Exception handler code: 262     // Exception handler code:
n 307     try_except_handler_2:; n 263     try_except_handler_1:;
308     exception_keeper_type_1 = exception_type; 264     exception_keeper_type_1 = exception_type;
309     exception_keeper_value_1 = exception_value; 265     exception_keeper_value_1 = exception_value;
310     exception_keeper_tb_1 = exception_tb; 266     exception_keeper_tb_1 = exception_tb;
311     exception_keeper_lineno_1 = exception_lineno; 267     exception_keeper_lineno_1 = exception_lineno;
312     exception_type = NULL; 268     exception_type = NULL;
313     exception_value = NULL; 269     exception_value = NULL;
314     exception_tb = NULL; 270     exception_tb = NULL;
315     exception_lineno = 0; 271     exception_lineno = 0;
316 272
n 317     Py_XDECREF(tmp_for_loop_1__iter_value); n 273     Py_XDECREF(var_x);
318     tmp_for_loop_1__iter_value = NULL; 274     var_x = NULL;
319     CHECK_OBJECT(tmp_for_loop_1__for_iterator);
320     Py_DECREF(tmp_for_loop_1__for_iterator);
321     tmp_for_loop_1__for_iterator = NULL;
322     // Re-raise. 275     // Re-raise.
323     exception_type = exception_keeper_type_1; 276     exception_type = exception_keeper_type_1;
324     exception_value = exception_keeper_value_1; 277     exception_value = exception_keeper_value_1;
325     exception_tb = exception_keeper_tb_1; 278     exception_tb = exception_keeper_tb_1;
326     exception_lineno = exception_keeper_lineno_1; 279     exception_lineno = exception_keeper_lineno_1;
n 327   n
328     goto frame_exception_exit_1;
329     // End of try:
330     try_end_1:;
331  
332 #if 0
333     RESTORE_FRAME_EXCEPTION(frame_5ac58c877419472c7a84becd923ab417);
334 #endif
335  
336     // Put the previous frame back on top.
337     popFrameStack();
338  
339     goto frame_no_exception_1;
340  
341     frame_exception_exit_1:;
342  
343 #if 0
344     RESTORE_FRAME_EXCEPTION(frame_5ac58c877419472c7a84becd923ab417);
345 #endif
346  
347     if (exception_tb == NULL) {
348         exception_tb = MAKE_TRACEBACK(frame_5ac58c877419472c7a84becd923ab417, exception_lineno);
349     } else if (exception_tb->tb_frame != &frame_5ac58c877419472c7a84becd923ab417->m_frame) {
350         exception_tb = ADD_TRACEBACK(exception_tb, frame_5ac58c877419472c7a84becd923ab417, exception_lineno);
351     }
352  
353     // Attaches locals to frame if any.
354     Nuitka_Frame_AttachLocals(
355         frame_5ac58c877419472c7a84becd923ab417,
356         type_description_1,
357         var_x,
358         var_local_value
359     );
360  
361  
362     // Release cached frame if used for exception.
363     if (frame_5ac58c877419472c7a84becd923ab417 == cache_frame_5ac58c877419472c7a84becd923ab417) {
364 #if _DEBUG_REFCOUNTS
365         count_active_frame_cache_instances -= 1;
366         count_released_frame_cache_instances += 1;
367 #endif
368  
369         Py_DECREF(cache_frame_5ac58c877419472c7a84becd923ab417);
370         cache_frame_5ac58c877419472c7a84becd923ab417 = NULL;
371     }
372  
373     assertFrameObject(frame_5ac58c877419472c7a84becd923ab417);
374  
375     // Put the previous frame back on top.
376     popFrameStack();
377  
378     // Return the error.
379     goto try_except_handler_1;
380  
381     frame_no_exception_1:;
382     Py_XDECREF(tmp_for_loop_1__iter_value);
383     tmp_for_loop_1__iter_value = NULL;
384     CHECK_OBJECT(tmp_for_loop_1__for_iterator);
385     Py_DECREF(tmp_for_loop_1__for_iterator);
386     tmp_for_loop_1__for_iterator = NULL;
387     tmp_return_value = Py_None;
388     Py_INCREF(tmp_return_value);
389     goto try_return_handler_1;
390     NUITKA_CANNOT_GET_HERE("tried codes exits in all cases");
391     return NULL;
392     // Return handler code:
393     try_return_handler_1:;
394     Py_XDECREF(var_x);
395     var_x = NULL;
396     CHECK_OBJECT(var_local_value);
397     Py_DECREF(var_local_value);
398     var_local_value = NULL;
399     goto function_return_exit;
400     // Exception handler code:
401     try_except_handler_1:;
402     exception_keeper_type_2 = exception_type;
403     exception_keeper_value_2 = exception_value;
404     exception_keeper_tb_2 = exception_tb;
405     exception_keeper_lineno_2 = exception_lineno;
406     exception_type = NULL;
407     exception_value = NULL;
408     exception_tb = NULL;
409     exception_lineno = 0;
410  
411     Py_XDECREF(var_x);
412     var_x = NULL;
413     Py_XDECREF(var_local_value);
414     var_local_value = NULL;
415     // Re-raise.
416     exception_type = exception_keeper_type_2;
417     exception_value = exception_keeper_value_2;
418     exception_tb = exception_keeper_tb_2;
419     exception_lineno = exception_keeper_lineno_2;
420 280
421     goto function_exception_exit; 281     goto function_exception_exit;
422     // End of try: 282     // End of try:
423 283
424     NUITKA_CANNOT_GET_HERE("Return statement must have exited already."); 284     NUITKA_CANNOT_GET_HERE("Return statement must have exited already.");
824 684
825     // Module code. 685     // Module code.
826     { 686     {
827         PyObject *tmp_assign_source_1; 687         PyObject *tmp_assign_source_1;
828         tmp_assign_source_1 = Py_None; 688         tmp_assign_source_1 = Py_None;
n 829         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[3], tmp_assign_source_1); n 689         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[2], tmp_assign_source_1);
830     } 690     }
831     { 691     {
832         PyObject *tmp_assign_source_2; 692         PyObject *tmp_assign_source_2;
n 833         tmp_assign_source_2 = mod_consts[4]; n 693         tmp_assign_source_2 = mod_consts[3];
834         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[5], tmp_assign_source_2); 694         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[4], tmp_assign_source_2);
835     } 695     }
836     { 696     {
837         PyObject *tmp_assign_source_3; 697         PyObject *tmp_assign_source_3;
838         tmp_assign_source_3 = Py_None; 698         tmp_assign_source_3 = Py_None;
n 839         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[6], tmp_assign_source_3); n 699         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[5], tmp_assign_source_3);
840     } 700     }
841     { 701     {
842         PyObject *tmp_assign_source_4; 702         PyObject *tmp_assign_source_4;
843         tmp_assign_source_4 = PyDict_New(); 703         tmp_assign_source_4 = PyDict_New();
n 844         UPDATE_STRING_DICT1(moduledict___main__, (Nuitka_StringObject *)mod_consts[7], tmp_assign_source_4); n 704         UPDATE_STRING_DICT1(moduledict___main__, (Nuitka_StringObject *)mod_consts[6], tmp_assign_source_4);
845     } 705     }
846     { 706     {
847         PyObject *tmp_assign_source_5; 707         PyObject *tmp_assign_source_5;
n 848         tmp_assign_source_5 = mod_consts[8]; n 708         tmp_assign_source_5 = mod_consts[7];
849         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[0], tmp_assign_source_5); 709         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[0], tmp_assign_source_5);
850     } 710     }
851     { 711     {
852         PyObject *tmp_assign_source_6; 712         PyObject *tmp_assign_source_6;
t 853         tmp_assign_source_6 = mod_consts[2]; t 713         tmp_assign_source_6 = mod_consts[8];
854         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[9], tmp_assign_source_6); 714         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[9], tmp_assign_source_6);
855     } 715     }
856     { 716     {
857         PyObject *tmp_assign_source_7; 717         PyObject *tmp_assign_source_7;
858 718