Construct ClosureVariableAccess

Performance Diagrams

Construct ClosureVariableAccess 0010000001000000200000020000003000000300000040000004000000500000050000006000000600000070000007000000CPython 2.7Nuitka (master)Nuitka (develop)Nuitka (factory)734697589.78846153846155257.0CPython 2.73050137244.59615384615387401.52407623545747Nuitka (master)3000092399.4038461538462403.20733899640015Nuitka (develop)3000092554.2115384615385403.20733899640015Nuitka (factory)Construct ClosureVariableAccessTicks Construct ClosureVariableAccess 001000000100000020000002000000300000030000004000000400000050000005000000600000060000007000000700000080000008000000CPython 3.8Nuitka (master)Nuitka (develop)Nuitka (factory)807269989.78846153846155257.0CPython 3.84550170244.59615384615387364.8290059686167Nuitka (master)4550242399.4038461538462364.8268019588187Nuitka (develop)4550242554.2115384615385364.8268019588187Nuitka (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_744512ad682ac459111695eced2d74ab; 83 static PyCodeObject *codeobj_744512ad682ac459111695eced2d74ab;
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_92b3e01ac116cc7987cfbac6578fe3de = MAKE_CODEOBJECT(module_filename_obj, 1, CO_NOFREE, mod_consts[20], NULL, NULL, 0, 0, 0); 89     codeobj_92b3e01ac116cc7987cfbac6578fe3de = MAKE_CODEOBJECT(module_filename_obj, 1, CO_NOFREE, mod_consts[20], NULL, NULL, 0, 0, 0);
90     codeobj_8e2801c4bf02c9aa86d28301a44d85d7 = MAKE_CODEOBJECT(module_filename_obj, 24, CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE, mod_consts[12], mod_consts[21], NULL, 0, 0, 0); 90     codeobj_8e2801c4bf02c9aa86d28301a44d85d7 = MAKE_CODEOBJECT(module_filename_obj, 24, CO_OPTIMIZED | CO_NEWLOCALS | CO_NOFREE, mod_consts[12], mod_consts[21], NULL, 0, 0, 0);
91     codeobj_744512ad682ac459111695eced2d74ab = MAKE_CODEOBJECT(module_filename_obj, 27, CO_OPTIMIZED | CO_NEWLOCALS, mod_consts[1], mod_consts[22], mod_consts[22], 0, 0, 0); 91     codeobj_744512ad682ac459111695eced2d74ab = 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_744512ad682ac459111695eced2d74ab); 402     RESTORE_FRAME_EXCEPTION(frame_744512ad682ac459111695eced2d74ab);
420 #endif 403 #endif
897 880
898     // Module code. 881     // Module code.
899     { 882     {
900         PyObject *tmp_assign_source_1; 883         PyObject *tmp_assign_source_1;
901         tmp_assign_source_1 = Py_None; 884         tmp_assign_source_1 = Py_None;
n 902         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[6], tmp_assign_source_1); n 885         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[5], tmp_assign_source_1);
903     } 886     }
904     { 887     {
905         PyObject *tmp_assign_source_2; 888         PyObject *tmp_assign_source_2;
n 906         tmp_assign_source_2 = mod_consts[7]; n 889         tmp_assign_source_2 = mod_consts[6];
907         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[8], tmp_assign_source_2); 890         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[7], tmp_assign_source_2);
908     } 891     }
909     { 892     {
910         PyObject *tmp_assign_source_3; 893         PyObject *tmp_assign_source_3;
911         tmp_assign_source_3 = Py_None; 894         tmp_assign_source_3 = Py_None;
n 912         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[9], tmp_assign_source_3); n 895         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[8], tmp_assign_source_3);
913     } 896     }
914     { 897     {
915         PyObject *tmp_assign_source_4; 898         PyObject *tmp_assign_source_4;
916         tmp_assign_source_4 = PyDict_New(); 899         tmp_assign_source_4 = PyDict_New();
n 917         UPDATE_STRING_DICT1(moduledict___main__, (Nuitka_StringObject *)mod_consts[10], tmp_assign_source_4); n 900         UPDATE_STRING_DICT1(moduledict___main__, (Nuitka_StringObject *)mod_consts[9], tmp_assign_source_4);
918     } 901     }
919     { 902     {
920         PyObject *tmp_assign_source_5; 903         PyObject *tmp_assign_source_5;
n 921         tmp_assign_source_5 = mod_consts[11]; n 904         tmp_assign_source_5 = mod_consts[10];
922         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[0], tmp_assign_source_5); 905         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[0], tmp_assign_source_5);
923     } 906     }
924     { 907     {
925         PyObject *tmp_assign_source_6; 908         PyObject *tmp_assign_source_6;
926         tmp_assign_source_6 = Py_None; 909         tmp_assign_source_6 = Py_None;
n 927         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[4], tmp_assign_source_6); n 910         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[11], tmp_assign_source_6);
928     } 911     }
929     { 912     {
930         PyObject *tmp_assign_source_7; 913         PyObject *tmp_assign_source_7;
931         tmp_assign_source_7 = Py_None; 914         tmp_assign_source_7 = Py_None;
t 932         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[5], tmp_assign_source_7); t 915         UPDATE_STRING_DICT0(moduledict___main__, (Nuitka_StringObject *)mod_consts[4], tmp_assign_source_7);
933     } 916     }
934     { 917     {
935         PyObject *tmp_assign_source_8; 918         PyObject *tmp_assign_source_8;
936 919
937 920