Construct FunctionCreationLocal

Performance Diagrams

Construct FunctionCreationLocal 00200000020000004000000400000060000006000000800000080000001000000010000000120000001200000014000000140000001600000016000000180000001800000020000000200000002200000022000000240000002400000026000000260000002800000028000000CPython 3.10Nuitka (main)Nuitka (develop)Nuitka (factory)2914076488.95192307692307257.0CPython 3.1010107136242.31730769230768418.4062796653566Nuitka (main)10107136395.6826923076923418.4062796653566Nuitka (develop)10107136549.0480769230769418.4062796653566Nuitka (factory)Construct FunctionCreationLocalTicks Construct FunctionCreationLocal 00200000020000004000000400000060000006000000800000080000001000000010000000120000001200000014000000140000001600000016000000180000001800000020000000200000002200000022000000CPython 3.8Nuitka (main)Nuitka (develop)Nuitka (factory)2207101588.95192307692307257.0CPython 3.810200336242.31730769230768389.9085865208632Nuitka (main)10200336395.6826923076923389.9085865208632Nuitka (develop)10200336549.0480769230769389.9085865208632Nuitka (factory)Construct FunctionCreationLocalTicks Construct FunctionCreationLocal 0010000001000000200000020000003000000300000040000004000000500000050000006000000600000070000007000000800000080000009000000900000010000000100000001100000011000000120000001200000013000000130000001400000014000000CPython 2.7Nuitka (main)Nuitka (develop)Nuitka (factory)1446903188.95192307692307257.0CPython 2.78150638242.31730769230768364.9113118457037Nuitka (main)8150614395.6826923076923364.9117217397202Nuitka (develop)8150614549.0480769230769364.9117217397202Nuitka (factory)Construct FunctionCreationLocalTicks

Source Code with Construct

import itertools


def calledRepeatedly():
    # We measure making a local function that will remain unused.
    # construct_begin
    def empty():
        pass

    # construct_alternative



    return empty


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

print("OK.")

Source Code without Construct

import itertools


def calledRepeatedly():
    # We measure making a local function that will remain unused.
    # construct_begin



    # construct_alternative
    empty = 1
    # construct_end

    return empty


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

print("OK.")

Context Diff of Source Code


Construct
Baseline
21 21
22 22
23 def calledRepeatedly(): 23 def calledRepeatedly():
24     # We measure making a local function that will remain unused. 24     # We measure making a local function that will remain unused.
25     # construct_begin 25     # construct_begin
n 26     def empty(): n 26  
27         pass 27  
28 28
29     # construct_alternative 29     # construct_alternative
t 30   t 30     empty = 1
31   31     # construct_end
32 32
33     return empty 33     return empty
34 34
35 35
36 for x in itertools.repeat(None, 50000): 36 for x in itertools.repeat(None, 50000):

Context Diff of Generated Code


Construct
Baseline
78 #endif 78 #endif
79 79
80 // The module code objects. 80 // The module code objects.
81 static PyCodeObject *codeobj_d86b4e28652466a6b51a8fa77ccee06a; 81 static PyCodeObject *codeobj_d86b4e28652466a6b51a8fa77ccee06a;
82 static PyCodeObject *codeobj_282e5a67c698b847bcc12e08b47b7122; 82 static PyCodeObject *codeobj_282e5a67c698b847bcc12e08b47b7122;
n 83 static PyCodeObject *codeobj_110aff69c70af9bc70732146dd7e4de1; n
84 /* For use in "MainProgram.c". */ 83 /* For use in "MainProgram.c". */
85 PyCodeObject *codeobj_main = NULL; 84 PyCodeObject *codeobj_main = NULL;
86 85
87 static void createModuleCodeObjects(void) { 86 static void createModuleCodeObjects(void) {
n 88     module_filename_obj = mod_consts[2]; CHECK_OBJECT(module_filename_obj); n 87     module_filename_obj = mod_consts[1]; CHECK_OBJECT(module_filename_obj);
89     codeobj_d86b4e28652466a6b51a8fa77ccee06a = MAKE_CODE_OBJECT(module_filename_obj, 1, CO_NOFREE, mod_consts[10], mod_consts[10], NULL, NULL, 0, 0, 0); 88     codeobj_d86b4e28652466a6b51a8fa77ccee06a = MAKE_CODE_OBJECT(module_filename_obj, 1, CO_NOFREE, mod_consts[10], mod_consts[10], NULL, NULL, 0, 0, 0);
90     codeobj_main = codeobj_d86b4e28652466a6b51a8fa77ccee06a; 89     codeobj_main = codeobj_d86b4e28652466a6b51a8fa77ccee06a;
91     codeobj_282e5a67c698b847bcc12e08b47b7122 = MAKE_CODE_OBJECT(module_filename_obj, 23, CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE, mod_consts[5], mod_consts[5], mod_consts[11], NULL, 0, 0, 0); 90     codeobj_282e5a67c698b847bcc12e08b47b7122 = MAKE_CODE_OBJECT(module_filename_obj, 23, CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE, mod_consts[5], mod_consts[5], mod_consts[11], NULL, 0, 0, 0);
n 92     codeobj_110aff69c70af9bc70732146dd7e4de1 = MAKE_CODE_OBJECT(module_filename_obj, 26, CO_NOFREE, mod_consts[0], mod_consts[0], NULL, NULL, 0, 0, 0); n
93 } 91 }
94 92
95 // The module function declarations. 93 // The module function declarations.
96 static PyObject *MAKE_FUNCTION___main__$$$function__1_calledRepeatedly(); 94 static PyObject *MAKE_FUNCTION___main__$$$function__1_calledRepeatedly();
97 95
98 96
n 99 static PyObject *MAKE_FUNCTION___main__$$$function__1_calledRepeatedly$$$function__1_empty(); n
100  
101  
102 // The module function definitions. 97 // The module function definitions.
n 103 static PyObject *impl___main__$$$function__1_calledRepeatedly(PyThreadState *tstate, struct Nuitka_FunctionObject const *self, PyObject **python_pars) { n
104     // Preserve error status for checks
105 #ifndef __NUITKA_NO_ASSERT__
106     NUITKA_MAY_BE_UNUSED bool had_error = HAS_ERROR_OCCURRED(tstate);
107 #endif
108  
109     // Local variable declarations.
110     PyObject *var_empty = NULL;
111     PyObject *tmp_return_value = NULL;
112  
113     // Actual function body.
114     {
115         PyObject *tmp_assign_source_1;
116  
117  
118         tmp_assign_source_1 = MAKE_FUNCTION___main__$$$function__1_calledRepeatedly$$$function__1_empty();
119  
120         assert(var_empty == NULL);
121         var_empty = tmp_assign_source_1;
122     }
123     // Tried code:
124     CHECK_OBJECT(var_empty);
125     tmp_return_value = var_empty;
126     Py_INCREF(tmp_return_value);
127     goto try_return_handler_1;
128     NUITKA_CANNOT_GET_HERE("tried codes exits in all cases");
129     return NULL;
130     // Return handler code:
131     try_return_handler_1:;
132     CHECK_OBJECT(var_empty);
133     Py_DECREF(var_empty);
134     var_empty = NULL;
135     goto function_return_exit;
136     // End of try:
137  
138     NUITKA_CANNOT_GET_HERE("Return statement must have exited already.");
139     return NULL;
140  
141  
142 function_return_exit:
143    // Function cleanup code if any.
144  
145  
146    // Actual function exit with return value, making sure we did not make
147    // the error status worse despite non-NULL return.
148    CHECK_OBJECT(tmp_return_value);
149    assert(had_error || !HAS_ERROR_OCCURRED(tstate));
150    return tmp_return_value;
151 }
152  
153  
154 98
155 static PyObject *MAKE_FUNCTION___main__$$$function__1_calledRepeatedly() { 99 static PyObject *MAKE_FUNCTION___main__$$$function__1_calledRepeatedly() {
156     struct Nuitka_FunctionObject *result = Nuitka_Function_New( 100     struct Nuitka_FunctionObject *result = Nuitka_Function_New(
n 157         impl___main__$$$function__1_calledRepeatedly, n 101         NULL,
158         mod_consts[5], 102         mod_consts[5],
159 #if PYTHON_VERSION >= 0x300 103 #if PYTHON_VERSION >= 0x300
160         NULL, 104         NULL,
161 #endif 105 #endif
162         codeobj_282e5a67c698b847bcc12e08b47b7122, 106         codeobj_282e5a67c698b847bcc12e08b47b7122,
168         module___main__, 112         module___main__,
169         NULL, 113         NULL,
170         NULL, 114         NULL,
171         0 115         0
172     ); 116     );
n 173   n 117     Nuitka_Function_EnableConstReturnGeneric(result, mod_consts[4]);
174  
175     return (PyObject *)result;
176 }
177  
178  
179  
180 static PyObject *MAKE_FUNCTION___main__$$$function__1_calledRepeatedly$$$function__1_empty() {
181     struct Nuitka_FunctionObject *result = Nuitka_Function_New(
182         NULL,
183         mod_consts[0],
184 #if PYTHON_VERSION >= 0x300
185         NULL,
186 #endif
187         codeobj_110aff69c70af9bc70732146dd7e4de1,
188         NULL,
189 #if PYTHON_VERSION >= 0x300
190         NULL,
191         NULL,
192 #endif
193         module___main__,
194         NULL,
195         NULL,
196         0
197     );
198  
199 118
200     return (PyObject *)result; 119     return (PyObject *)result;
201 } 120 }
202 121
203 122
213 // Provide a way to create find a function via its C code and create it back 132 // Provide a way to create find a function via its C code and create it back
214 // in another process, useful for multiprocessing extensions like dill 133 // in another process, useful for multiprocessing extensions like dill
215 extern void registerDillPluginTables(PyThreadState *tstate, char const *module_name, PyMethodDef *reduce_compiled_function, PyMethodDef *create_compiled_function); 134 extern void registerDillPluginTables(PyThreadState *tstate, char const *module_name, PyMethodDef *reduce_compiled_function, PyMethodDef *create_compiled_function);
216 135
217 static function_impl_code const function_table___main__[] = { 136 static function_impl_code const function_table___main__[] = {
n 218     impl___main__$$$function__1_calledRepeatedly, n 137  
219     NULL 138     NULL
220 }; 139 };
221 140
222 static PyObject *_reduce_compiled_function(PyObject *self, PyObject *args, PyObject *kwds) { 141 static PyObject *_reduce_compiled_function(PyObject *self, PyObject *args, PyObject *kwds) {
223     PyObject *func; 142     PyObject *func;
565 484
566     // Module code. 485     // Module code.
567     { 486     {
568         PyObject *tmp_assign_source_1; 487         PyObject *tmp_assign_source_1;
569         tmp_assign_source_1 = Py_None; 488         tmp_assign_source_1 = Py_None;
n 570         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[1], tmp_assign_source_1); n 489         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[0], tmp_assign_source_1);
571     } 490     }
572     { 491     {
573         PyObject *tmp_assign_source_2; 492         PyObject *tmp_assign_source_2;
n 574         tmp_assign_source_2 = mod_consts[2]; n 493         tmp_assign_source_2 = mod_consts[1];
575         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[3], tmp_assign_source_2); 494         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[2], tmp_assign_source_2);
576     } 495     }
577     frame_d86b4e28652466a6b51a8fa77ccee06a = MAKE_MODULE_FRAME(codeobj_d86b4e28652466a6b51a8fa77ccee06a, module___main__); 496     frame_d86b4e28652466a6b51a8fa77ccee06a = MAKE_MODULE_FRAME(codeobj_d86b4e28652466a6b51a8fa77ccee06a, module___main__);
578 497
579     // Push the new frame as the currently active one, and we should be exclusively 498     // Push the new frame as the currently active one, and we should be exclusively
580     // owning it. 499     // owning it.
586         PyObject *tmp_assign_source_3; 505         PyObject *tmp_assign_source_3;
587         PyObject *tmp_name_value_1; 506         PyObject *tmp_name_value_1;
588         PyObject *tmp_globals_arg_value_1; 507         PyObject *tmp_globals_arg_value_1;
589         PyObject *tmp_locals_arg_value_1; 508         PyObject *tmp_locals_arg_value_1;
590         PyObject *tmp_fromlist_value_1; 509         PyObject *tmp_fromlist_value_1;
n 591         tmp_name_value_1 = mod_consts[4]; n 510         tmp_name_value_1 = mod_consts[3];
592         tmp_globals_arg_value_1 = (PyObject *)moduledict___main__; 511         tmp_globals_arg_value_1 = (PyObject *)moduledict___main__;
593         tmp_locals_arg_value_1 = Py_None; 512         tmp_locals_arg_value_1 = Py_None;
594         tmp_fromlist_value_1 = Py_None; 513         tmp_fromlist_value_1 = Py_None;
595         frame_d86b4e28652466a6b51a8fa77ccee06a->m_frame.f_lineno = 20; 514         frame_d86b4e28652466a6b51a8fa77ccee06a->m_frame.f_lineno = 20;
596         tmp_assign_source_3 = IMPORT_MODULE4(tstate, tmp_name_value_1, tmp_globals_arg_value_1, tmp_locals_arg_value_1, tmp_fromlist_value_1); 515         tmp_assign_source_3 = IMPORT_MODULE4(tstate, tmp_name_value_1, tmp_globals_arg_value_1, tmp_locals_arg_value_1, tmp_fromlist_value_1);
602 521
603             exception_lineno = 20; 522             exception_lineno = 20;
604 523
605             goto frame_exception_exit_1; 524             goto frame_exception_exit_1;
606         } 525         }
n 607         UPDATE_STRING_DICT1(moduledict___main__, (Nuitka_StringObject *)mod_consts[4], tmp_assign_source_3); n 526         UPDATE_STRING_DICT1(moduledict___main__, (Nuitka_StringObject *)mod_consts[3], tmp_assign_source_3);
608     } 527     }
609     { 528     {
610         PyObject *tmp_assign_source_4; 529         PyObject *tmp_assign_source_4;
611 530
612 531
616     } 535     }
617     { 536     {
618         PyObject *tmp_assign_source_5; 537         PyObject *tmp_assign_source_5;
619         PyObject *tmp_iter_arg_1; 538         PyObject *tmp_iter_arg_1;
620         PyObject *tmp_called_instance_1; 539         PyObject *tmp_called_instance_1;
n 621         tmp_called_instance_1 = GET_STRING_DICT_VALUE(moduledict___main__, (Nuitka_StringObject *)mod_consts[4]); n 540         tmp_called_instance_1 = GET_STRING_DICT_VALUE(moduledict___main__, (Nuitka_StringObject *)mod_consts[3]);
622 541
623         if (unlikely(tmp_called_instance_1 == NULL)) { 542         if (unlikely(tmp_called_instance_1 == NULL)) {
t 624             tmp_called_instance_1 = GET_MODULE_VARIABLE_VALUE_FALLBACK(tstate, mod_consts[4]); t 543             tmp_called_instance_1 = GET_MODULE_VARIABLE_VALUE_FALLBACK(tstate, mod_consts[3]);
625         } 544         }
626 545
627         assert(!(tmp_called_instance_1 == NULL)); 546         assert(!(tmp_called_instance_1 == NULL));
628         frame_d86b4e28652466a6b51a8fa77ccee06a->m_frame.f_lineno = 36; 547         frame_d86b4e28652466a6b51a8fa77ccee06a->m_frame.f_lineno = 36;
629         tmp_iter_arg_1 = CALL_METHOD_WITH_ARGS2( 548         tmp_iter_arg_1 = CALL_METHOD_WITH_ARGS2(