Construct ClosureVariableAccess

Performance Diagrams

Construct ClosureVariableAccess 001000000100000020000002000000300000030000004000000400000050000005000000600000060000007000000700000080000008000000900000090000001000000010000000CPython 2.7Nuitka (master)Nuitka (develop)Nuitka (factory)1014779388.95192307692307257.0CPython 2.72650169242.31730769230768439.57942771019657Nuitka (master)2650439395.6826923076923439.5728527678572Nuitka (develop)2650163549.0480769230769439.5795738200263Nuitka (factory)Construct ClosureVariableAccessTicks Construct ClosureVariableAccess 00100000010000002000000200000030000003000000400000040000005000000500000060000006000000700000070000008000000800000090000009000000CPython 3.5Nuitka (master)Nuitka (develop)Nuitka (factory)907221389.78846153846155257.0CPython 3.53244008244.59615384615387415.75278944534347Nuitka (master)3250118399.4038461538462415.5863609234382Nuitka (develop)3250150554.2115384615385415.58548928469827Nuitka (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
416         exception_value = PyUnicode_FromFormat( "free variable '%s' referenced before assignment in enclosing scope", "closure_value" ); 416         exception_value = PyUnicode_FromFormat( "free variable '%s' referenced before assignment in enclosing scope", "closure_value" );
417         exception_tb = NULL; 417         exception_tb = NULL;
418         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb ); 418         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
419         CHAIN_EXCEPTION( exception_value ); 419         CHAIN_EXCEPTION( exception_value );
420 420
n 421         exception_lineno = 35; n
422         type_description_1 = "c";
423         goto frame_exception_exit_1;
424     }
425  
426     tmp_assign_source_1 = PyCell_GET( self->m_closure[0] );
427     UPDATE_STRING_DICT0( moduledict___main__, (Nuitka_StringObject *)const_str_plain_module_value2, tmp_assign_source_1 );
428     }
429     {
430     PyObject *tmp_assign_source_2;
431     if ( PyCell_GET( self->m_closure[0] ) == NULL )
432     {
433  
434         exception_type = PyExc_NameError;
435         Py_INCREF( exception_type );
436         exception_value = PyUnicode_FromFormat( "free variable '%s' referenced before assignment in enclosing scope", "closure_value" );
437         exception_tb = NULL;
438         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
439         CHAIN_EXCEPTION( exception_value );
440  
441         exception_lineno = 38; 421         exception_lineno = 38;
442         type_description_1 = "c"; 422         type_description_1 = "c";
443         goto frame_exception_exit_1; 423         goto frame_exception_exit_1;
444     } 424     }
445 425
t 446     tmp_assign_source_2 = PyCell_GET( self->m_closure[0] ); t 426     tmp_assign_source_1 = PyCell_GET( self->m_closure[0] );
447     UPDATE_STRING_DICT0( moduledict___main__, (Nuitka_StringObject *)const_str_plain_module_value3, tmp_assign_source_2 ); 427     UPDATE_STRING_DICT0( moduledict___main__, (Nuitka_StringObject *)const_str_plain_module_value3, tmp_assign_source_1 );
448     } 428     }
449 429
450 #if 0 430 #if 0
451     RESTORE_FRAME_EXCEPTION( frame_34d04183648752f22057ec927cb2b3a1 ); 431     RESTORE_FRAME_EXCEPTION( frame_34d04183648752f22057ec927cb2b3a1 );
452 #endif 432 #endif