Construct FunctionCreationLocal

Performance Diagrams

Construct FunctionCreationLocal 00100000010000002000000200000030000003000000400000040000005000000500000060000006000000700000070000008000000800000090000009000000100000001000000011000000110000001200000012000000130000001300000014000000140000001500000015000000CPython 2.7Nuitka (master)Nuitka (develop)Nuitka (factory)1501817688.95192307692307257.0CPython 2.78300590242.31730769230768367.53398549044323Nuitka (master)8300590395.6826923076923367.53398549044323Nuitka (develop)8300590549.0480769230769367.53398549044323Nuitka (factory)Construct FunctionCreationLocalTicks Construct FunctionCreationLocal 00200000020000004000000400000060000006000000800000080000001000000010000000120000001200000014000000140000001600000016000000180000001800000020000000200000002200000022000000CPython 3.5Nuitka (master)Nuitka (develop)Nuitka (factory)2212072588.95192307692307257.0CPython 3.510153645242.31730769230768390.68682884141805Nuitka (master)10153648395.6826923076923390.68679532777173Nuitka (develop)10153648549.0480769230769390.68679532777173Nuitka (factory)Construct FunctionCreationLocalTicks

Source Code with Construct

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



    return empty


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

print("OK.")

Source Code without Construct

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


# construct_alternative
    empty = 1
# construct_end

    return empty


import itertools
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
27         pass
28 # construct_alternative
29 26
30 27
t t 28 # construct_alternative
29     empty = 1
30 # construct_end
31 31
32     return empty 32     return empty
33 33
34 34
35 import itertools 35 import itertools

Context Diff of Generated Code


Construct
Baseline
31 31
32 PyObject *module___main__; 32 PyObject *module___main__;
33 PyDictObject *moduledict___main__; 33 PyDictObject *moduledict___main__;
34 34
35 /* The declarations of module constants used, if any. */ 35 /* The declarations of module constants used, if any. */
n 36 static PyObject *mod_consts[16]; n 36 static PyObject *mod_consts[15];
37 37
38 static PyObject *module_filename_obj = NULL; 38 static PyObject *module_filename_obj = NULL;
39 39
40 /* Indicator if this modules private constants were created yet. */ 40 /* Indicator if this modules private constants were created yet. */
41 static bool constants_created = false; 41 static bool constants_created = false;
42 42
43 /* Function to create module private constants. */ 43 /* Function to create module private constants. */
44 static void createModuleConstants(void) { 44 static void createModuleConstants(void) {
n 45     loadConstantsBlob(&mod_consts[0], "__main__", 16); n 45     loadConstantsBlob(&mod_consts[0], "__main__", 15);
46 46
47     constants_created = true; 47     constants_created = true;
48 } 48 }
49 49
50 /* For multiprocessing, we want to be able to initialize the __main__ constants. */ 50 /* For multiprocessing, we want to be able to initialize the __main__ constants. */
58 #ifndef __NUITKA_NO_ASSERT__ 58 #ifndef __NUITKA_NO_ASSERT__
59 void checkModuleConstants___main__(void) { 59 void checkModuleConstants___main__(void) {
60     // The module may not have been used at all, then ignore this. 60     // The module may not have been used at all, then ignore this.
61     if (constants_created == false) return; 61     if (constants_created == false) return;
62 62
n 63     checkConstantsBlob(&mod_consts[0], "__main__", 16); n 63     checkConstantsBlob(&mod_consts[0], "__main__", 15);
64 } 64 }
65 #endif 65 #endif
66 66
67 // The module code objects. 67 // The module code objects.
68 static PyCodeObject *codeobj_cd506a39dd4947e139f2aefdc3f756ba; 68 static PyCodeObject *codeobj_cd506a39dd4947e139f2aefdc3f756ba;
69 static PyCodeObject *codeobj_db6bbf9e10a46adeed25a5494c106ce4; 69 static PyCodeObject *codeobj_db6bbf9e10a46adeed25a5494c106ce4;
n 70 static PyCodeObject *codeobj_2f76dca3e86d30dbc20193f6fc6c35fd; n
71 /* For use in "MainProgram.c". */ 70 /* For use in "MainProgram.c". */
72 PyCodeObject *codeobj_main = NULL; 71 PyCodeObject *codeobj_main = NULL;
73 72
74 static void createModuleCodeObjects(void) { 73 static void createModuleCodeObjects(void) {
n 75     module_filename_obj = mod_consts[3]; CHECK_OBJECT(module_filename_obj); n 74     module_filename_obj = mod_consts[1]; CHECK_OBJECT(module_filename_obj);
76     codeobj_cd506a39dd4947e139f2aefdc3f756ba = MAKE_CODEOBJECT(module_filename_obj, 1, CO_NOFREE, mod_consts[14], NULL, NULL, 0, 0, 0); 75     codeobj_cd506a39dd4947e139f2aefdc3f756ba = MAKE_CODEOBJECT(module_filename_obj, 1, CO_NOFREE, mod_consts[13], NULL, NULL, 0, 0, 0);
77     codeobj_db6bbf9e10a46adeed25a5494c106ce4 = MAKE_CODEOBJECT(module_filename_obj, 23, CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE, mod_consts[6], mod_consts[15], NULL, 0, 0, 0); 76     codeobj_db6bbf9e10a46adeed25a5494c106ce4 = MAKE_CODEOBJECT(module_filename_obj, 23, CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE, mod_consts[5], mod_consts[14], NULL, 0, 0, 0);
78     codeobj_2f76dca3e86d30dbc20193f6fc6c35fd = MAKE_CODEOBJECT(module_filename_obj, 26, CO_NOFREE, mod_consts[0], NULL, NULL, 0, 0, 0);
79 } 77 }
80 78
81 // The module function declarations. 79 // The module function declarations.
82 static PyObject *MAKE_FUNCTION___main__$$$function__1_calledRepeatedly(); 80 static PyObject *MAKE_FUNCTION___main__$$$function__1_calledRepeatedly();
83 81
84 82
n 85 static PyObject *MAKE_FUNCTION___main__$$$function__1_calledRepeatedly$$$function__1_empty(); n
86  
87  
88 // The module function definitions. 83 // The module function definitions.
n 89 static PyObject *impl___main__$$$function__1_calledRepeatedly(struct Nuitka_FunctionObject const *self, PyObject **python_pars) { n
90     // Preserve error status for checks
91 #ifndef __NUITKA_NO_ASSERT__
92     NUITKA_MAY_BE_UNUSED bool had_error = ERROR_OCCURRED();
93 #endif
94  
95     // Local variable declarations.
96     PyObject *var_empty = NULL;
97     PyObject *tmp_return_value = NULL;
98  
99     // Actual function body.
100     {
101         PyObject *tmp_assign_source_1;
102  
103  
104         tmp_assign_source_1 = MAKE_FUNCTION___main__$$$function__1_calledRepeatedly$$$function__1_empty();
105  
106         assert(var_empty == NULL);
107         var_empty = tmp_assign_source_1;
108     }
109     // Tried code:
110     CHECK_OBJECT(var_empty);
111     tmp_return_value = var_empty;
112     Py_INCREF(tmp_return_value);
113     goto try_return_handler_1;
114     NUITKA_CANNOT_GET_HERE("tried codes exits in all cases");
115     return NULL;
116     // Return handler code:
117     try_return_handler_1:;
118     CHECK_OBJECT(var_empty);
119     Py_DECREF(var_empty);
120     var_empty = NULL;
121     goto function_return_exit;
122     // End of try:
123  
124     NUITKA_CANNOT_GET_HERE("Return statement must have exited already.");
125     return NULL;
126  
127  
128 function_return_exit:
129    // Function cleanup code if any.
130  
131  
132    // Actual function exit with return value, making sure we did not make
133    // the error status worse despite non-NULL return.
134    CHECK_OBJECT(tmp_return_value);
135    assert(had_error || !ERROR_OCCURRED());
136    return tmp_return_value;
137 }
138  
139  
140 84
141 static PyObject *MAKE_FUNCTION___main__$$$function__1_calledRepeatedly() { 85 static PyObject *MAKE_FUNCTION___main__$$$function__1_calledRepeatedly() {
142     struct Nuitka_FunctionObject *result = Nuitka_Function_New( 86     struct Nuitka_FunctionObject *result = Nuitka_Function_New(
n 143         impl___main__$$$function__1_calledRepeatedly, n 87         NULL,
144         mod_consts[6], 88         mod_consts[5],
145 #if PYTHON_VERSION >= 0x300 89 #if PYTHON_VERSION >= 0x300
146         NULL, 90         NULL,
147 #endif 91 #endif
148         codeobj_db6bbf9e10a46adeed25a5494c106ce4, 92         codeobj_db6bbf9e10a46adeed25a5494c106ce4,
149         NULL, 93         NULL,
154         module___main__, 98         module___main__,
155         NULL, 99         NULL,
156         NULL, 100         NULL,
157         0 101         0
158     ); 102     );
n 159   n 103     Nuitka_Function_EnableConstReturnGeneric(result, mod_consts[4]);
160  
161     return (PyObject *)result;
162 }
163  
164  
165  
166 static PyObject *MAKE_FUNCTION___main__$$$function__1_calledRepeatedly$$$function__1_empty() {
167     struct Nuitka_FunctionObject *result = Nuitka_Function_New(
168         NULL,
169         mod_consts[0],
170 #if PYTHON_VERSION >= 0x300
171         mod_consts[1],
172 #endif
173         codeobj_2f76dca3e86d30dbc20193f6fc6c35fd,
174         NULL,
175 #if PYTHON_VERSION >= 0x300
176         NULL,
177         NULL,
178 #endif
179         module___main__,
180         NULL,
181         NULL,
182         0
183     );
184  
185 104
186     return (PyObject *)result; 105     return (PyObject *)result;
187 } 106 }
188 107
189 108
199 // Provide a way to create find a function via its C code and create it back 118 // Provide a way to create find a function via its C code and create it back
200 // in another process, useful for multiprocessing extensions like dill 119 // in another process, useful for multiprocessing extensions like dill
201 120
202 function_impl_code functable___main__[] = { 121 function_impl_code functable___main__[] = {
203     NULL, 122     NULL,
n 204     impl___main__$$$function__1_calledRepeatedly, n
205     NULL 123     NULL
206 }; 124 };
207 125
208 static char const *_reduce_compiled_function_argnames[] = { 126 static char const *_reduce_compiled_function_argnames[] = {
209     "func", 127     "func",
575 493
576     // Module code. 494     // Module code.
577     { 495     {
578         PyObject *tmp_assign_source_1; 496         PyObject *tmp_assign_source_1;
579         tmp_assign_source_1 = Py_None; 497         tmp_assign_source_1 = Py_None;
n 580         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[2], tmp_assign_source_1); n 498         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[0], tmp_assign_source_1);
581     } 499     }
582     { 500     {
583         PyObject *tmp_assign_source_2; 501         PyObject *tmp_assign_source_2;
n 584         tmp_assign_source_2 = mod_consts[3]; n 502         tmp_assign_source_2 = mod_consts[1];
585         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[4], tmp_assign_source_2); 503         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[2], tmp_assign_source_2);
586     } 504     }
587     { 505     {
588         PyObject *tmp_assign_source_3; 506         PyObject *tmp_assign_source_3;
589         tmp_assign_source_3 = Py_None; 507         tmp_assign_source_3 = Py_None;
n 590         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[5], tmp_assign_source_3); n 508         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[3], tmp_assign_source_3);
591     } 509     }
592     { 510     {
593         PyObject *tmp_assign_source_4; 511         PyObject *tmp_assign_source_4;
594 512
595 513
596         tmp_assign_source_4 = MAKE_FUNCTION___main__$$$function__1_calledRepeatedly(); 514         tmp_assign_source_4 = MAKE_FUNCTION___main__$$$function__1_calledRepeatedly();
597 515
n 598         UPDATE_STRING_DICT1(moduledict___main__, (Nuitka_StringObject *)mod_consts[6], tmp_assign_source_4); n 516         UPDATE_STRING_DICT1(moduledict___main__, (Nuitka_StringObject *)mod_consts[5], tmp_assign_source_4);
599     } 517     }
600     { 518     {
601         PyObject *tmp_assign_source_5; 519         PyObject *tmp_assign_source_5;
602         PyObject *tmp_name_name_1; 520         PyObject *tmp_name_name_1;
603         PyObject *tmp_globals_arg_name_1; 521         PyObject *tmp_globals_arg_name_1;
604         PyObject *tmp_locals_arg_name_1; 522         PyObject *tmp_locals_arg_name_1;
605         PyObject *tmp_fromlist_name_1; 523         PyObject *tmp_fromlist_name_1;
606         PyObject *tmp_level_name_1; 524         PyObject *tmp_level_name_1;
n 607         tmp_name_name_1 = mod_consts[7]; n 525         tmp_name_name_1 = mod_consts[6];
608         tmp_globals_arg_name_1 = (PyObject *)moduledict___main__; 526         tmp_globals_arg_name_1 = (PyObject *)moduledict___main__;
609         tmp_locals_arg_name_1 = Py_None; 527         tmp_locals_arg_name_1 = Py_None;
610         tmp_fromlist_name_1 = Py_None; 528         tmp_fromlist_name_1 = Py_None;
n 611         tmp_level_name_1 = mod_consts[8]; n 529         tmp_level_name_1 = mod_consts[7];
612         tmp_assign_source_5 = IMPORT_MODULE5(tmp_name_name_1, tmp_globals_arg_name_1, tmp_locals_arg_name_1, tmp_fromlist_name_1, tmp_level_name_1); 530         tmp_assign_source_5 = IMPORT_MODULE5(tmp_name_name_1, tmp_globals_arg_name_1, tmp_locals_arg_name_1, tmp_fromlist_name_1, tmp_level_name_1);
613         assert(!(tmp_assign_source_5 == NULL)); 531         assert(!(tmp_assign_source_5 == NULL));
n 614         UPDATE_STRING_DICT1(moduledict___main__, (Nuitka_StringObject *)mod_consts[7], tmp_assign_source_5); n 532         UPDATE_STRING_DICT1(moduledict___main__, (Nuitka_StringObject *)mod_consts[6], tmp_assign_source_5);
615     } 533     }
616     // Frame without reuse. 534     // Frame without reuse.
617     frame_cd506a39dd4947e139f2aefdc3f756ba = MAKE_MODULE_FRAME(codeobj_cd506a39dd4947e139f2aefdc3f756ba, module___main__); 535     frame_cd506a39dd4947e139f2aefdc3f756ba = MAKE_MODULE_FRAME(codeobj_cd506a39dd4947e139f2aefdc3f756ba, module___main__);
618 536
619     // Push the new frame as the currently active one, and we should be exclusively 537     // Push the new frame as the currently active one, and we should be exclusively
624     // Framed code: 542     // Framed code:
625     { 543     {
626         PyObject *tmp_assign_source_6; 544         PyObject *tmp_assign_source_6;
627         PyObject *tmp_iter_arg_1; 545         PyObject *tmp_iter_arg_1;
628         PyObject *tmp_called_instance_1; 546         PyObject *tmp_called_instance_1;
n 629         tmp_called_instance_1 = GET_STRING_DICT_VALUE(moduledict___main__, (Nuitka_StringObject *)mod_consts[7]); n 547         tmp_called_instance_1 = GET_STRING_DICT_VALUE(moduledict___main__, (Nuitka_StringObject *)mod_consts[6]);
630 548
631         if (unlikely(tmp_called_instance_1 == NULL)) { 549         if (unlikely(tmp_called_instance_1 == NULL)) {
n 632             tmp_called_instance_1 = GET_MODULE_VARIABLE_VALUE_FALLBACK(mod_consts[7]); n 550             tmp_called_instance_1 = GET_MODULE_VARIABLE_VALUE_FALLBACK(mod_consts[6]);
633         } 551         }
634 552
635         assert(!(tmp_called_instance_1 == NULL)); 553         assert(!(tmp_called_instance_1 == NULL));
636         frame_cd506a39dd4947e139f2aefdc3f756ba->m_frame.f_lineno = 36; 554         frame_cd506a39dd4947e139f2aefdc3f756ba->m_frame.f_lineno = 36;
n 637         tmp_iter_arg_1 = CALL_METHOD_WITH_ARGS2(tmp_called_instance_1, mod_consts[9], &PyTuple_GET_ITEM(mod_consts[10], 0)); n 555         tmp_iter_arg_1 = CALL_METHOD_WITH_ARGS2(tmp_called_instance_1, mod_consts[8], &PyTuple_GET_ITEM(mod_consts[9], 0));
638 556
639         if (tmp_iter_arg_1 == NULL) { 557         if (tmp_iter_arg_1 == NULL) {
640             assert(ERROR_OCCURRED()); 558             assert(ERROR_OCCURRED());
641 559
642             FETCH_ERROR_OCCURRED(&exception_type, &exception_value, &exception_tb); 560             FETCH_ERROR_OCCURRED(&exception_type, &exception_value, &exception_tb);
691     } 609     }
692     { 610     {
693         PyObject *tmp_assign_source_8; 611         PyObject *tmp_assign_source_8;
694         CHECK_OBJECT(tmp_for_loop_1__iter_value); 612         CHECK_OBJECT(tmp_for_loop_1__iter_value);
695         tmp_assign_source_8 = tmp_for_loop_1__iter_value; 613         tmp_assign_source_8 = tmp_for_loop_1__iter_value;
n 696         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[11], tmp_assign_source_8); n 614         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[10], tmp_assign_source_8);
697     } 615     }
698     { 616     {
699         PyObject *tmp_called_name_1; 617         PyObject *tmp_called_name_1;
700         PyObject *tmp_call_result_1; 618         PyObject *tmp_call_result_1;
n 701         tmp_called_name_1 = GET_STRING_DICT_VALUE(moduledict___main__, (Nuitka_StringObject *)mod_consts[6]); n 619         tmp_called_name_1 = GET_STRING_DICT_VALUE(moduledict___main__, (Nuitka_StringObject *)mod_consts[5]);
702 620
703         if (unlikely(tmp_called_name_1 == NULL)) { 621         if (unlikely(tmp_called_name_1 == NULL)) {
n 704             tmp_called_name_1 = GET_MODULE_VARIABLE_VALUE_FALLBACK(mod_consts[6]); n 622             tmp_called_name_1 = GET_MODULE_VARIABLE_VALUE_FALLBACK(mod_consts[5]);
705         } 623         }
706 624
707         if (tmp_called_name_1 == NULL) { 625         if (tmp_called_name_1 == NULL) {
708             assert(ERROR_OCCURRED()); 626             assert(ERROR_OCCURRED());
709 627
770     Py_XDECREF(tmp_for_loop_1__for_iterator); 688     Py_XDECREF(tmp_for_loop_1__for_iterator);
771     tmp_for_loop_1__for_iterator = NULL; 689     tmp_for_loop_1__for_iterator = NULL;
772     { 690     {
773         PyObject *tmp_called_name_2; 691         PyObject *tmp_called_name_2;
774         PyObject *tmp_call_result_2; 692         PyObject *tmp_call_result_2;
n 775         tmp_called_name_2 = LOOKUP_BUILTIN(mod_consts[12]); n 693         tmp_called_name_2 = LOOKUP_BUILTIN(mod_consts[11]);
776         assert(tmp_called_name_2 != NULL); 694         assert(tmp_called_name_2 != NULL);
777         frame_cd506a39dd4947e139f2aefdc3f756ba->m_frame.f_lineno = 39; 695         frame_cd506a39dd4947e139f2aefdc3f756ba->m_frame.f_lineno = 39;
t 778         tmp_call_result_2 = CALL_FUNCTION_WITH_SINGLE_ARG(tmp_called_name_2, mod_consts[13]); t 696         tmp_call_result_2 = CALL_FUNCTION_WITH_SINGLE_ARG(tmp_called_name_2, mod_consts[12]);
779         if (tmp_call_result_2 == NULL) { 697         if (tmp_call_result_2 == NULL) {
780             assert(ERROR_OCCURRED()); 698             assert(ERROR_OCCURRED());
781 699
782             FETCH_ERROR_OCCURRED(&exception_type, &exception_value, &exception_tb); 700             FETCH_ERROR_OCCURRED(&exception_type, &exception_value, &exception_tb);
783 701