Construct CallCompiledFunctionPosArgsDefaults

Performance Diagrams

Construct CallCompiledFunctionPosArgsDefaults 002000000020000000400000004000000060000000600000008000000080000000100000000100000000120000000120000000140000000140000000160000000160000000CPython 2.7Nuitka (master)Nuitka (develop)Nuitka (factory)16047171588.11538461538461257.0CPython 2.751450330240.03846153846155424.885421337816Nuitka (master)53200328391.96153846153845422.19054499249773Nuitka (develop)53200328543.8846153846154422.19054499249773Nuitka (factory)Construct CallCompiledFunctionPosArgsDefaultsTicks Construct CallCompiledFunctionPosArgsDefaults 002000000020000000400000004000000060000000600000008000000080000000100000000100000000120000000120000000140000000140000000160000000160000000180000000180000000CPython 3.5Nuitka (master)Nuitka (develop)Nuitka (factory)18199101688.11538461538461257.0CPython 3.555450862240.03846153846155428.82177182306623Nuitka (master)58350860391.96153846153845424.8840273293829Nuitka (develop)58350860543.8846153846154424.8840273293829Nuitka (factory)Construct CallCompiledFunctionPosArgsDefaultsTicks

Source Code with Construct

from __future__ import print_function

def compiled_func(a = 1,b = 2,c = 3,d = 4,e = 5,f = 6):
    return a, b, c, d, e, f

def calledRepeatedly():
    # This is supposed to make a call to a non-compiled function, which is
    # being optimized separately.
# construct_begin
    compiled_func()
    compiled_func()
    compiled_func()
# construct_alternative



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

print("OK.")

Source Code without Construct

from __future__ import print_function

def compiled_func(a = 1,b = 2,c = 3,d = 4,e = 5,f = 6):
    return a, b, c, d, e, f

def calledRepeatedly():
    # This is supposed to make a call to a non-compiled function, which is
    # being optimized separately.
# construct_begin



# construct_alternative
    pass
# construct_end

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

print("OK.")

Context Diff of Source Code


Construct
Baseline
24 24
25 def calledRepeatedly(): 25 def calledRepeatedly():
26     # This is supposed to make a call to a non-compiled function, which is 26     # This is supposed to make a call to a non-compiled function, which is
27     # being optimized separately. 27     # being optimized separately.
28 # construct_begin 28 # construct_begin
n 29     compiled_func() n
30     compiled_func()
31     compiled_func()
32 # construct_alternative
33 29
34 30
t t 31  
32 # construct_alternative
33     pass
34 # construct_end
35 35
36 import itertools 36 import itertools
37 for x in itertools.repeat(None, 50000): 37 for x in itertools.repeat(None, 50000):
38     calledRepeatedly() 38     calledRepeatedly()
39 39

Context Diff of Generated Code


Construct
Baseline
57 } 57 }
58 #endif 58 #endif
59 59
60 // The module code objects. 60 // The module code objects.
61 static PyCodeObject *codeobj_7402e2cf9ca6b6ad2109c107debf9c4d; 61 static PyCodeObject *codeobj_7402e2cf9ca6b6ad2109c107debf9c4d;
n 62 static PyCodeObject *codeobj_d679e7335ac061a6c592cda4a2014174; n 62 static PyCodeObject *codeobj_c8264dd43f9cf91b59f28f2a1f496524;
63 static PyCodeObject *codeobj_bccaebbf3494fa0435e8a806c15f5b16; 63 static PyCodeObject *codeobj_bccaebbf3494fa0435e8a806c15f5b16;
64 /* For use in "MainProgram.c". */ 64 /* For use in "MainProgram.c". */
65 PyCodeObject *codeobj_main = NULL; 65 PyCodeObject *codeobj_main = NULL;
66 66
67 static void createModuleCodeObjects(void) { 67 static void createModuleCodeObjects(void) {
n 68     module_filename_obj = mod_consts[2]; CHECK_OBJECT(module_filename_obj); n 68     module_filename_obj = mod_consts[1]; CHECK_OBJECT(module_filename_obj);
69     codeobj_7402e2cf9ca6b6ad2109c107debf9c4d = MAKE_CODEOBJECT(module_filename_obj, 1, CO_NOFREE, mod_consts[15], mod_consts[16], 0, 0, 0); 69     codeobj_7402e2cf9ca6b6ad2109c107debf9c4d = MAKE_CODEOBJECT(module_filename_obj, 1, CO_NOFREE, mod_consts[15], mod_consts[16], 0, 0, 0);
n 70     codeobj_d679e7335ac061a6c592cda4a2014174 = MAKE_CODEOBJECT(module_filename_obj, 25, CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE, mod_consts[8], mod_consts[16], 0, 0, 0); n 70     codeobj_c8264dd43f9cf91b59f28f2a1f496524 = MAKE_CODEOBJECT(module_filename_obj, 25, CO_NOFREE, mod_consts[8], mod_consts[16], 0, 0, 0);
71     codeobj_bccaebbf3494fa0435e8a806c15f5b16 = MAKE_CODEOBJECT(module_filename_obj, 22, CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE, mod_consts[0], mod_consts[17], 6, 0, 0); 71     codeobj_bccaebbf3494fa0435e8a806c15f5b16 = MAKE_CODEOBJECT(module_filename_obj, 22, CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE, mod_consts[7], mod_consts[17], 6, 0, 0);
72 } 72 }
73 73
74 // The module function declarations. 74 // The module function declarations.
75 static PyObject *MAKE_FUNCTION___main__$$$function_1_compiled_func(PyObject *defaults); 75 static PyObject *MAKE_FUNCTION___main__$$$function_1_compiled_func(PyObject *defaults);
76 76
144    assert(had_error || !ERROR_OCCURRED()); 144    assert(had_error || !ERROR_OCCURRED());
145    return tmp_return_value; 145    return tmp_return_value;
146 } 146 }
147 147
148 148
n 149 static PyObject *impl___main__$$$function_2_calledRepeatedly(struct Nuitka_FunctionObject const *self, PyObject **python_pars) { n
150     // Preserve error status for checks
151 #ifndef __NUITKA_NO_ASSERT__
152     NUITKA_MAY_BE_UNUSED bool had_error = ERROR_OCCURRED();
153 #endif
154  
155     // Local variable declarations.
156     struct Nuitka_FrameObject *frame_d679e7335ac061a6c592cda4a2014174;
157     NUITKA_MAY_BE_UNUSED char const *type_description_1 = NULL;
158     NUITKA_MAY_BE_UNUSED nuitka_void tmp_unused;
159     PyObject *exception_type = NULL;
160     PyObject *exception_value = NULL;
161     PyTracebackObject *exception_tb = NULL;
162     NUITKA_MAY_BE_UNUSED int exception_lineno = 0;
163     static struct Nuitka_FrameObject *cache_frame_d679e7335ac061a6c592cda4a2014174 = NULL;
164     PyObject *tmp_return_value = NULL;
165  
166     // Actual function body.
167     if (isFrameUnusable(cache_frame_d679e7335ac061a6c592cda4a2014174)) {
168         Py_XDECREF(cache_frame_d679e7335ac061a6c592cda4a2014174);
169  
170 #if _DEBUG_REFCOUNTS
171         if (cache_frame_d679e7335ac061a6c592cda4a2014174 == NULL) {
172             count_active_frame_cache_instances += 1;
173         } else {
174             count_released_frame_cache_instances += 1;
175         }
176         count_allocated_frame_cache_instances += 1;
177 #endif
178         cache_frame_d679e7335ac061a6c592cda4a2014174 = MAKE_FUNCTION_FRAME(codeobj_d679e7335ac061a6c592cda4a2014174, module___main__, 0);
179 #if _DEBUG_REFCOUNTS
180     } else {
181         count_hit_frame_cache_instances += 1;
182 #endif
183     }
184     assert(cache_frame_d679e7335ac061a6c592cda4a2014174->m_type_description == NULL);
185     frame_d679e7335ac061a6c592cda4a2014174 = cache_frame_d679e7335ac061a6c592cda4a2014174;
186  
187     // Push the new frame as the currently active one.
188     pushFrameStack(frame_d679e7335ac061a6c592cda4a2014174);
189  
190     // Mark the frame object as in use, ref count 1 will be up for reuse.
191     assert(Py_REFCNT(frame_d679e7335ac061a6c592cda4a2014174) == 2); // Frame stack
192  
193     // Framed code:
194     {
195         PyObject *tmp_called_name_1;
196         PyObject *tmp_call_result_1;
197         tmp_called_name_1 = GET_MODULE_VARIABLE_VALUE(moduledict___main__, mod_consts[0]);
198         if (tmp_called_name_1 == NULL) {
199             assert(ERROR_OCCURRED());
200  
201             FETCH_ERROR_OCCURRED(&exception_type, &exception_value, &exception_tb);
202  
203  
204             exception_lineno = 29;
205  
206             goto frame_exception_exit_1;
207         }
208         frame_d679e7335ac061a6c592cda4a2014174->m_frame.f_lineno = 29;
209         tmp_call_result_1 = CALL_FUNCTION_NO_ARGS(tmp_called_name_1);
210         if (tmp_call_result_1 == NULL) {
211             assert(ERROR_OCCURRED());
212  
213             FETCH_ERROR_OCCURRED(&exception_type, &exception_value, &exception_tb);
214  
215  
216             exception_lineno = 29;
217  
218             goto frame_exception_exit_1;
219         }
220         Py_DECREF(tmp_call_result_1);
221     }
222     {
223         PyObject *tmp_called_name_2;
224         PyObject *tmp_call_result_2;
225         tmp_called_name_2 = GET_MODULE_VARIABLE_VALUE(moduledict___main__, mod_consts[0]);
226         if (tmp_called_name_2 == NULL) {
227             assert(ERROR_OCCURRED());
228  
229             FETCH_ERROR_OCCURRED(&exception_type, &exception_value, &exception_tb);
230  
231  
232             exception_lineno = 30;
233  
234             goto frame_exception_exit_1;
235         }
236         frame_d679e7335ac061a6c592cda4a2014174->m_frame.f_lineno = 30;
237         tmp_call_result_2 = CALL_FUNCTION_NO_ARGS(tmp_called_name_2);
238         if (tmp_call_result_2 == NULL) {
239             assert(ERROR_OCCURRED());
240  
241             FETCH_ERROR_OCCURRED(&exception_type, &exception_value, &exception_tb);
242  
243  
244             exception_lineno = 30;
245  
246             goto frame_exception_exit_1;
247         }
248         Py_DECREF(tmp_call_result_2);
249     }
250     {
251         PyObject *tmp_called_name_3;
252         PyObject *tmp_call_result_3;
253         tmp_called_name_3 = GET_MODULE_VARIABLE_VALUE(moduledict___main__, mod_consts[0]);
254         if (tmp_called_name_3 == NULL) {
255             assert(ERROR_OCCURRED());
256  
257             FETCH_ERROR_OCCURRED(&exception_type, &exception_value, &exception_tb);
258  
259  
260             exception_lineno = 31;
261  
262             goto frame_exception_exit_1;
263         }
264         frame_d679e7335ac061a6c592cda4a2014174->m_frame.f_lineno = 31;
265         tmp_call_result_3 = CALL_FUNCTION_NO_ARGS(tmp_called_name_3);
266         if (tmp_call_result_3 == NULL) {
267             assert(ERROR_OCCURRED());
268  
269             FETCH_ERROR_OCCURRED(&exception_type, &exception_value, &exception_tb);
270  
271  
272             exception_lineno = 31;
273  
274             goto frame_exception_exit_1;
275         }
276         Py_DECREF(tmp_call_result_3);
277     }
278  
279 #if 0
280     RESTORE_FRAME_EXCEPTION(frame_d679e7335ac061a6c592cda4a2014174);
281 #endif
282  
283     // Put the previous frame back on top.
284     popFrameStack();
285  
286     goto frame_no_exception_1;
287  
288     frame_exception_exit_1:;
289  
290 #if 0
291     RESTORE_FRAME_EXCEPTION(frame_d679e7335ac061a6c592cda4a2014174);
292 #endif
293  
294     if (exception_tb == NULL) {
295         exception_tb = MAKE_TRACEBACK(frame_d679e7335ac061a6c592cda4a2014174, exception_lineno);
296     } else if (exception_tb->tb_frame != &frame_d679e7335ac061a6c592cda4a2014174->m_frame) {
297         exception_tb = ADD_TRACEBACK(exception_tb, frame_d679e7335ac061a6c592cda4a2014174, exception_lineno);
298     }
299  
300     // Attaches locals to frame if any.
301     Nuitka_Frame_AttachLocals(
302         frame_d679e7335ac061a6c592cda4a2014174,
303         type_description_1
304     );
305  
306  
307     // Release cached frame.
308     if (frame_d679e7335ac061a6c592cda4a2014174 == cache_frame_d679e7335ac061a6c592cda4a2014174) {
309 #if _DEBUG_REFCOUNTS
310         count_active_frame_cache_instances -= 1;
311         count_released_frame_cache_instances += 1;
312 #endif
313  
314         Py_DECREF(frame_d679e7335ac061a6c592cda4a2014174);
315     }
316     cache_frame_d679e7335ac061a6c592cda4a2014174 = NULL;
317  
318     assertFrameObject(frame_d679e7335ac061a6c592cda4a2014174);
319  
320     // Put the previous frame back on top.
321     popFrameStack();
322  
323     // Return the error.
324     goto function_exception_exit;
325  
326     frame_no_exception_1:;
327     tmp_return_value = Py_None;
328     Py_INCREF(tmp_return_value);
329     goto function_return_exit;
330  
331     NUITKA_CANNOT_GET_HERE("Return statement must have exited already.");
332     return NULL;
333  
334 function_exception_exit:
335     assert(exception_type);
336     RESTORE_ERROR_OCCURRED(exception_type, exception_value, exception_tb);
337  
338     return NULL;
339  
340 function_return_exit:
341    // Function cleanup code if any.
342  
343  
344    // Actual function exit with return value, making sure we did not make
345    // the error status worse despite non-NULL return.
346    CHECK_OBJECT(tmp_return_value);
347    assert(had_error || !ERROR_OCCURRED());
348    return tmp_return_value;
349 }
350  
351  
352 149
353 static PyObject *MAKE_FUNCTION___main__$$$function_1_compiled_func(PyObject *defaults) { 150 static PyObject *MAKE_FUNCTION___main__$$$function_1_compiled_func(PyObject *defaults) {
354     struct Nuitka_FunctionObject *result = Nuitka_Function_New( 151     struct Nuitka_FunctionObject *result = Nuitka_Function_New(
355         impl___main__$$$function_1_compiled_func, 152         impl___main__$$$function_1_compiled_func,
n 356         mod_consts[0], n 153         mod_consts[7],
357 #if PYTHON_VERSION >= 300 154 #if PYTHON_VERSION >= 300
358         NULL, 155         NULL,
359 #endif 156 #endif
360         codeobj_bccaebbf3494fa0435e8a806c15f5b16, 157         codeobj_bccaebbf3494fa0435e8a806c15f5b16,
361         defaults, 158         defaults,
375 172
376 173
377 174
378 static PyObject *MAKE_FUNCTION___main__$$$function_2_calledRepeatedly() { 175 static PyObject *MAKE_FUNCTION___main__$$$function_2_calledRepeatedly() {
379     struct Nuitka_FunctionObject *result = Nuitka_Function_New( 176     struct Nuitka_FunctionObject *result = Nuitka_Function_New(
n 380         impl___main__$$$function_2_calledRepeatedly, n 177         NULL,
381         mod_consts[8], 178         mod_consts[8],
382 #if PYTHON_VERSION >= 300 179 #if PYTHON_VERSION >= 300
383         NULL, 180         NULL,
384 #endif 181 #endif
n 385         codeobj_d679e7335ac061a6c592cda4a2014174, n 182         codeobj_c8264dd43f9cf91b59f28f2a1f496524,
386         NULL, 183         NULL,
387 #if PYTHON_VERSION >= 300 184 #if PYTHON_VERSION >= 300
388         NULL, 185         NULL,
389         NULL, 186         NULL,
390 #endif 187 #endif
411 // Provide a way to create find a function via its C code and create it back 208 // Provide a way to create find a function via its C code and create it back
412 // in another process, useful for multiprocessing extensions like dill 209 // in another process, useful for multiprocessing extensions like dill
413 210
414 function_impl_code functable___main__[] = { 211 function_impl_code functable___main__[] = {
415     impl___main__$$$function_1_compiled_func, 212     impl___main__$$$function_1_compiled_func,
n 416     impl___main__$$$function_2_calledRepeatedly, n 213     NULL,
417     NULL 214     NULL
418 }; 215 };
419 216
420 static char const *_reduce_compiled_function_argnames[] = { 217 static char const *_reduce_compiled_function_argnames[] = {
421     "func", 218     "func",
779 576
780     // Module code. 577     // Module code.
781     { 578     {
782         PyObject *tmp_assign_source_1; 579         PyObject *tmp_assign_source_1;
783         tmp_assign_source_1 = Py_None; 580         tmp_assign_source_1 = Py_None;
n 784         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[1], tmp_assign_source_1); n 581         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[0], tmp_assign_source_1);
785     } 582     }
786     { 583     {
787         PyObject *tmp_assign_source_2; 584         PyObject *tmp_assign_source_2;
n 788         tmp_assign_source_2 = mod_consts[2]; n 585         tmp_assign_source_2 = mod_consts[1];
789         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[3], tmp_assign_source_2); 586         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[2], tmp_assign_source_2);
790     } 587     }
791     { 588     {
792         PyObject *tmp_assign_source_3; 589         PyObject *tmp_assign_source_3;
793         tmp_assign_source_3 = Py_None; 590         tmp_assign_source_3 = Py_None;
n 794         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[4], tmp_assign_source_3); n 591         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[3], tmp_assign_source_3);
795     } 592     }
796     // Frame without reuse. 593     // Frame without reuse.
797     frame_7402e2cf9ca6b6ad2109c107debf9c4d = MAKE_MODULE_FRAME(codeobj_7402e2cf9ca6b6ad2109c107debf9c4d, module___main__); 594     frame_7402e2cf9ca6b6ad2109c107debf9c4d = MAKE_MODULE_FRAME(codeobj_7402e2cf9ca6b6ad2109c107debf9c4d, module___main__);
798 595
799     // Push the new frame as the currently active one, and we should be exclusively 596     // Push the new frame as the currently active one, and we should be exclusively
810         assert(!(tmp_import_name_from_1 == NULL)); 607         assert(!(tmp_import_name_from_1 == NULL));
811         if (PyModule_Check(tmp_import_name_from_1)) { 608         if (PyModule_Check(tmp_import_name_from_1)) {
812             tmp_assign_source_4 = IMPORT_NAME_OR_MODULE( 609             tmp_assign_source_4 = IMPORT_NAME_OR_MODULE(
813                 tmp_import_name_from_1, 610                 tmp_import_name_from_1,
814                 (PyObject *)moduledict___main__, 611                 (PyObject *)moduledict___main__,
n n 612                 mod_consts[4],
815                 mod_consts[5], 613                 mod_consts[5]
816                 mod_consts[6]
817             ); 614             );
818         } else { 615         } else {
n 819             tmp_assign_source_4 = IMPORT_NAME(tmp_import_name_from_1, mod_consts[5]); n 616             tmp_assign_source_4 = IMPORT_NAME(tmp_import_name_from_1, mod_consts[4]);
820         } 617         }
821 618
822         if (tmp_assign_source_4 == NULL) { 619         if (tmp_assign_source_4 == NULL) {
823             assert(ERROR_OCCURRED()); 620             assert(ERROR_OCCURRED());
824 621
827 624
828             exception_lineno = 20; 625             exception_lineno = 20;
829 626
830             goto frame_exception_exit_1; 627             goto frame_exception_exit_1;
831         } 628         }
n 832         UPDATE_STRING_DICT1(moduledict___main__, (Nuitka_StringObject *)mod_consts[5], tmp_assign_source_4); n 629         UPDATE_STRING_DICT1(moduledict___main__, (Nuitka_StringObject *)mod_consts[4], tmp_assign_source_4);
833     } 630     }
834     { 631     {
835         PyObject *tmp_assign_source_5; 632         PyObject *tmp_assign_source_5;
836         PyObject *tmp_defaults_1; 633         PyObject *tmp_defaults_1;
n 837         tmp_defaults_1 = mod_consts[7]; n 634         tmp_defaults_1 = mod_consts[6];
838         Py_INCREF(tmp_defaults_1); 635         Py_INCREF(tmp_defaults_1);
839 636
840 637
841         tmp_assign_source_5 = MAKE_FUNCTION___main__$$$function_1_compiled_func(tmp_defaults_1); 638         tmp_assign_source_5 = MAKE_FUNCTION___main__$$$function_1_compiled_func(tmp_defaults_1);
842 639
n 843         UPDATE_STRING_DICT1(moduledict___main__, (Nuitka_StringObject *)mod_consts[0], tmp_assign_source_5); n 640         UPDATE_STRING_DICT1(moduledict___main__, (Nuitka_StringObject *)mod_consts[7], tmp_assign_source_5);
844     } 641     }
845     { 642     {
846         PyObject *tmp_assign_source_6; 643         PyObject *tmp_assign_source_6;
847 644
848 645
859         PyObject *tmp_level_name_1; 656         PyObject *tmp_level_name_1;
860         tmp_name_name_1 = mod_consts[9]; 657         tmp_name_name_1 = mod_consts[9];
861         tmp_globals_name_1 = (PyObject *)moduledict___main__; 658         tmp_globals_name_1 = (PyObject *)moduledict___main__;
862         tmp_locals_name_1 = Py_None; 659         tmp_locals_name_1 = Py_None;
863         tmp_fromlist_name_1 = Py_None; 660         tmp_fromlist_name_1 = Py_None;
t 864         tmp_level_name_1 = mod_consts[6]; t 661         tmp_level_name_1 = mod_consts[5];
865         frame_7402e2cf9ca6b6ad2109c107debf9c4d->m_frame.f_lineno = 36; 662         frame_7402e2cf9ca6b6ad2109c107debf9c4d->m_frame.f_lineno = 36;
866         tmp_assign_source_7 = IMPORT_MODULE5(tmp_name_name_1, tmp_globals_name_1, tmp_locals_name_1, tmp_fromlist_name_1, tmp_level_name_1); 663         tmp_assign_source_7 = IMPORT_MODULE5(tmp_name_name_1, tmp_globals_name_1, tmp_locals_name_1, tmp_fromlist_name_1, tmp_level_name_1);
867         assert(!(tmp_assign_source_7 == NULL)); 664         assert(!(tmp_assign_source_7 == NULL));
868         UPDATE_STRING_DICT1(moduledict___main__, (Nuitka_StringObject *)mod_consts[9], tmp_assign_source_7); 665         UPDATE_STRING_DICT1(moduledict___main__, (Nuitka_StringObject *)mod_consts[9], tmp_assign_source_7);
869     } 666     }