Construct ClosureVariableAccess

Performance Diagrams

Construct ClosureVariableAccess 00100000010000002000000200000030000003000000400000040000005000000500000060000006000000700000070000008000000800000090000009000000CPython 2.7Nuitka (master)Nuitka (develop)Nuitka (factory)984811189.78846153846155257.00000000000006CPython 2.72650199244.59615384615387437.6148196651817Nuitka (master)2650175399.4038461538462437.61542188922556Nuitka (develop)2650181554.2115384615385437.61527133321465Nuitka (factory)Construct ClosureVariableAccessTicks Construct ClosureVariableAccess 00100000010000002000000200000030000003000000400000040000005000000500000060000006000000700000070000008000000800000090000009000000CPython 3.5Nuitka (master)Nuitka (develop)Nuitka (factory)927234089.78846153846155257.0CPython 3.53236382244.59615384615387417.86317830151916Nuitka (master)3262202399.4038461538462417.17505435106335Nuitka (develop)3242906554.2115384615385417.6893084079183Nuitka (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
407             exception_value = PyUnicode_FromFormat( "free variable '%s' referenced before assignment in enclosing scope", "closure_value" ); 407             exception_value = PyUnicode_FromFormat( "free variable '%s' referenced before assignment in enclosing scope", "closure_value" );
408             exception_tb = NULL; 408             exception_tb = NULL;
409             NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb ); 409             NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
410             CHAIN_EXCEPTION( exception_value ); 410             CHAIN_EXCEPTION( exception_value );
411 411
n 412             exception_lineno = 35; n
413             type_description_1 = "c";
414             goto frame_exception_exit_1;
415         }
416  
417         tmp_assign_source_1 = PyCell_GET( self->m_closure[0] );
418         UPDATE_STRING_DICT0( moduledict___main__, (Nuitka_StringObject *)const_str_plain_module_value2, tmp_assign_source_1 );
419     }
420     {
421         PyObject *tmp_assign_source_2;
422         if ( PyCell_GET( self->m_closure[0] ) == NULL )
423         {
424  
425             exception_type = PyExc_NameError;
426             Py_INCREF( exception_type );
427             exception_value = PyUnicode_FromFormat( "free variable '%s' referenced before assignment in enclosing scope", "closure_value" );
428             exception_tb = NULL;
429             NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
430             CHAIN_EXCEPTION( exception_value );
431  
432             exception_lineno = 38; 412             exception_lineno = 38;
433             type_description_1 = "c"; 413             type_description_1 = "c";
434             goto frame_exception_exit_1; 414             goto frame_exception_exit_1;
435         } 415         }
436 416
t 437         tmp_assign_source_2 = PyCell_GET( self->m_closure[0] ); t 417         tmp_assign_source_1 = PyCell_GET( self->m_closure[0] );
438         UPDATE_STRING_DICT0( moduledict___main__, (Nuitka_StringObject *)const_str_plain_module_value3, tmp_assign_source_2 ); 418         UPDATE_STRING_DICT0( moduledict___main__, (Nuitka_StringObject *)const_str_plain_module_value3, tmp_assign_source_1 );
439     } 419     }
440 420
441 #if 0 421 #if 0
442     RESTORE_FRAME_EXCEPTION( frame_829ac33ef88e625de06ffea9be2d832e ); 422     RESTORE_FRAME_EXCEPTION( frame_829ac33ef88e625de06ffea9be2d832e );
443 #endif 423 #endif