Construct ClosureVariableAccess

Performance Diagrams

Construct ClosureVariableAccess 0010000001000000200000020000003000000300000040000004000000500000050000006000000600000070000007000000CPython 2.7Nuitka (main)Nuitka (develop)Nuitka (factory)734697589.78846153846155257.0CPython 2.73000087244.59615384615387403.2075071713188Nuitka (main)3000087399.4038461538462403.2075071713188Nuitka (develop)3000087554.2115384615385403.2075071713188Nuitka (factory)Construct ClosureVariableAccessTicks Construct ClosureVariableAccess 001000000100000020000002000000300000030000004000000400000050000005000000600000060000007000000700000080000008000000CPython 3.8Nuitka (main)Nuitka (develop)Nuitka (factory)807269989.78846153846155257.0CPython 3.84550524244.59615384615387364.8181695871099Nuitka (main)4550304399.4038461538462364.8249040614927Nuitka (develop)4550304554.2115384615385364.8249040614927Nuitka (factory)Construct ClosureVariableAccessTicks

Source Code with Construct

module_value1 = 1000
module_value2 = None
module_value3 = None

def calledRepeatedly():
    closure_value = module_value1

    def f():
        # Force frame and eliminate forward propagation (currently).
        module_value1

        # Use writing to global variable as access method.
        global module_value2, module_value3

# construct_begin
        module_value2 = closure_value
# construct_end

        module_value3 = closure_value

    f()

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

print("OK.")

Source Code without Construct

module_value1 = 1000
module_value2 = None
module_value3 = None

def calledRepeatedly():
    closure_value = module_value1

    def f():
        # Force frame and eliminate forward propagation (currently).
        module_value1

        # Use writing to global variable as access method.
        global module_value2, module_value3

# construct_begin



        module_value3 = closure_value

    f()

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

print("OK.")

Context Diff of Source Code


Construct
Baseline
30 30
31         # Use writing to global variable as access method. 31         # Use writing to global variable as access method.
32         global module_value2, module_value3 32         global module_value2, module_value3
33 33
34 # construct_begin 34 # construct_begin
t 35         module_value2 = closure_value t 35  
36 # construct_end 36  
37 37
38         module_value3 = closure_value 38         module_value3 = closure_value
39 39
40     f() 40     f()
41 41

Context Diff of Generated Code


Construct
Baseline
83 static PyCodeObject *codeobj_03611ab64f0b15f8d61d783fc934e777; 83 static PyCodeObject *codeobj_03611ab64f0b15f8d61d783fc934e777;
84 /* For use in "MainProgram.c". */ 84 /* For use in "MainProgram.c". */
85 PyCodeObject *codeobj_main = NULL; 85 PyCodeObject *codeobj_main = NULL;
86 86
87 static void createModuleCodeObjects(void) { 87 static void createModuleCodeObjects(void) {
n 88     module_filename_obj = mod_consts[7]; CHECK_OBJECT(module_filename_obj); n 88     module_filename_obj = mod_consts[6]; CHECK_OBJECT(module_filename_obj);
89     codeobj_c36834269fa28c67f71509f5ea0e4e1b = MAKE_CODEOBJECT(module_filename_obj, 1, CO_NOFREE, mod_consts[20], NULL, NULL, 0, 0, 0); 89     codeobj_c36834269fa28c67f71509f5ea0e4e1b = MAKE_CODEOBJECT(module_filename_obj, 1, CO_NOFREE, mod_consts[20], NULL, NULL, 0, 0, 0);
90     codeobj_2a9d42f254cfc34864fc607c907c094b = MAKE_CODEOBJECT(module_filename_obj, 24, CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE, mod_consts[12], mod_consts[21], NULL, 0, 0, 0); 90     codeobj_2a9d42f254cfc34864fc607c907c094b = MAKE_CODEOBJECT(module_filename_obj, 24, CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE, mod_consts[12], mod_consts[21], NULL, 0, 0, 0);
91     codeobj_03611ab64f0b15f8d61d783fc934e777 = MAKE_CODEOBJECT(module_filename_obj, 27, CO_OPTIMIZED | CO_NEWLOCALS, mod_consts[1], mod_consts[22], mod_consts[22], 0, 0, 0); 91     codeobj_03611ab64f0b15f8d61d783fc934e777 = MAKE_CODEOBJECT(module_filename_obj, 27, CO_OPTIMIZED | CO_NEWLOCALS, mod_consts[1], mod_consts[22], mod_consts[22], 0, 0, 0);
92 } 92 }
93 93
387             FORMAT_UNBOUND_CLOSURE_ERROR(&exception_type, &exception_value, mod_consts[3]); 387             FORMAT_UNBOUND_CLOSURE_ERROR(&exception_type, &exception_value, mod_consts[3]);
388             exception_tb = NULL; 388             exception_tb = NULL;
389             NORMALIZE_EXCEPTION(&exception_type, &exception_value, &exception_tb); 389             NORMALIZE_EXCEPTION(&exception_type, &exception_value, &exception_tb);
390             CHAIN_EXCEPTION(exception_value); 390             CHAIN_EXCEPTION(exception_value);
391 391
n 392             exception_lineno = 35; n
393             type_description_1 = "c";
394             goto frame_exception_exit_1;
395         }
396  
397         tmp_assign_source_1 = Nuitka_Cell_GET(self->m_closure[0]);
398         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[4], tmp_assign_source_1);
399     }
400     {
401         PyObject *tmp_assign_source_2;
402         if (Nuitka_Cell_GET(self->m_closure[0]) == NULL) {
403  
404             FORMAT_UNBOUND_CLOSURE_ERROR(&exception_type, &exception_value, mod_consts[3]);
405             exception_tb = NULL;
406             NORMALIZE_EXCEPTION(&exception_type, &exception_value, &exception_tb);
407             CHAIN_EXCEPTION(exception_value);
408  
409             exception_lineno = 38; 392             exception_lineno = 38;
410             type_description_1 = "c"; 393             type_description_1 = "c";
411             goto frame_exception_exit_1; 394             goto frame_exception_exit_1;
412         } 395         }
413 396
n 414         tmp_assign_source_2 = Nuitka_Cell_GET(self->m_closure[0]); n 397         tmp_assign_source_1 = Nuitka_Cell_GET(self->m_closure[0]);
415         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[5], tmp_assign_source_2); 398         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[4], tmp_assign_source_1);
416     } 399     }
417 400
418 #if 0 401 #if 0
419     RESTORE_FRAME_EXCEPTION(frame_03611ab64f0b15f8d61d783fc934e777); 402     RESTORE_FRAME_EXCEPTION(frame_03611ab64f0b15f8d61d783fc934e777);
420 #endif 403 #endif
902 885
903     // Module code. 886     // Module code.
904     { 887     {
905         PyObject *tmp_assign_source_1; 888         PyObject *tmp_assign_source_1;
906         tmp_assign_source_1 = Py_None; 889         tmp_assign_source_1 = Py_None;
n 907         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[6], tmp_assign_source_1); n 890         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[5], tmp_assign_source_1);
908     } 891     }
909     { 892     {
910         PyObject *tmp_assign_source_2; 893         PyObject *tmp_assign_source_2;
n 911         tmp_assign_source_2 = mod_consts[7]; n 894         tmp_assign_source_2 = mod_consts[6];
912         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[8], tmp_assign_source_2); 895         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[7], tmp_assign_source_2);
913     } 896     }
914     { 897     {
915         PyObject *tmp_assign_source_3; 898         PyObject *tmp_assign_source_3;
916         tmp_assign_source_3 = Py_None; 899         tmp_assign_source_3 = Py_None;
n 917         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[9], tmp_assign_source_3); n 900         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[8], tmp_assign_source_3);
918     } 901     }
919     { 902     {
920         PyObject *tmp_assign_source_4; 903         PyObject *tmp_assign_source_4;
921         tmp_assign_source_4 = PyDict_New(); 904         tmp_assign_source_4 = PyDict_New();
n 922         UPDATE_STRING_DICT1(moduledict___main__, (Nuitka_StringObject *)mod_consts[10], tmp_assign_source_4); n 905         UPDATE_STRING_DICT1(moduledict___main__, (Nuitka_StringObject *)mod_consts[9], tmp_assign_source_4);
923     } 906     }
924     { 907     {
925         PyObject *tmp_assign_source_5; 908         PyObject *tmp_assign_source_5;
n 926         tmp_assign_source_5 = mod_consts[11]; n 909         tmp_assign_source_5 = mod_consts[10];
927         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[0], tmp_assign_source_5); 910         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[0], tmp_assign_source_5);
928     } 911     }
929     { 912     {
930         PyObject *tmp_assign_source_6; 913         PyObject *tmp_assign_source_6;
931         tmp_assign_source_6 = Py_None; 914         tmp_assign_source_6 = Py_None;
n 932         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[4], tmp_assign_source_6); n 915         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[11], tmp_assign_source_6);
933     } 916     }
934     { 917     {
935         PyObject *tmp_assign_source_7; 918         PyObject *tmp_assign_source_7;
936         tmp_assign_source_7 = Py_None; 919         tmp_assign_source_7 = Py_None;
t 937         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[5], tmp_assign_source_7); t 920         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[4], tmp_assign_source_7);
938     } 921     }
939     { 922     {
940         PyObject *tmp_assign_source_8; 923         PyObject *tmp_assign_source_8;
941 924
942 925