Construct LoopSmallRange

Performance Diagrams

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