Construct ClosureVariableAccess

Performance Diagrams

Construct ClosureVariableAccess 001000000100000020000002000000300000030000004000000400000050000005000000600000060000007000000700000080000008000000900000090000001000000010000000CPython 2.7Nuitka (master)Nuitka (develop)Nuitka (factory)1014779388.95192307692307257.0CPython 2.72800133242.31730769230768435.92755862511945Nuitka (master)2799877395.6826923076923435.93379264452267Nuitka (develop)2800391549.0480769230769435.9212759024397Nuitka (factory)Construct ClosureVariableAccessTicks Construct ClosureVariableAccess 00100000010000002000000200000030000003000000400000040000005000000500000060000006000000700000070000008000000800000090000009000000CPython 3.5Nuitka (master)Nuitka (develop)Nuitka (factory)907221389.78846153846155257.0CPython 3.53399923244.59615384615387411.50586587858993Nuitka (master)3400591399.4038461538462411.4876704198939Nuitka (develop)3399931554.2115384615385411.50564796890495Nuitka (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
425         exception_value = PyUnicode_FromFormat( "free variable '%s' referenced before assignment in enclosing scope", "closure_value" ); 425         exception_value = PyUnicode_FromFormat( "free variable '%s' referenced before assignment in enclosing scope", "closure_value" );
426         exception_tb = NULL; 426         exception_tb = NULL;
427         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb ); 427         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
428         CHAIN_EXCEPTION( exception_value ); 428         CHAIN_EXCEPTION( exception_value );
429 429
n 430         exception_lineno = 35; n
431         type_description_1 = "c";
432         goto frame_exception_exit_1;
433     }
434  
435     UPDATE_STRING_DICT0( moduledict___main__, (Nuitka_StringObject *)const_str_plain_module_value2, tmp_assign_source_1 );
436     }
437     {
438     PyObject *tmp_assign_source_2;
439     if ( self->m_closure[0] == NULL )
440     {
441         tmp_assign_source_2 = NULL;
442     }
443     else
444     {
445         tmp_assign_source_2 = PyCell_GET( self->m_closure[0] );
446     }
447  
448     if ( tmp_assign_source_2 == NULL )
449     {
450  
451         exception_type = PyExc_NameError;
452         Py_INCREF( exception_type );
453         exception_value = PyUnicode_FromFormat( "free variable '%s' referenced before assignment in enclosing scope", "closure_value" );
454         exception_tb = NULL;
455         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
456         CHAIN_EXCEPTION( exception_value );
457  
458         exception_lineno = 38; 430         exception_lineno = 38;
459         type_description_1 = "c"; 431         type_description_1 = "c";
460         goto frame_exception_exit_1; 432         goto frame_exception_exit_1;
461     } 433     }
462 434
t 463     UPDATE_STRING_DICT0( moduledict___main__, (Nuitka_StringObject *)const_str_plain_module_value3, tmp_assign_source_2 ); t 435     UPDATE_STRING_DICT0( moduledict___main__, (Nuitka_StringObject *)const_str_plain_module_value3, tmp_assign_source_1 );
464     } 436     }
465 437
466 #if 0 438 #if 0
467     RESTORE_FRAME_EXCEPTION( frame_a0bfd33ddd69a47aff83992ae8372444 ); 439     RESTORE_FRAME_EXCEPTION( frame_a0bfd33ddd69a47aff83992ae8372444 );
468 #endif 440 #endif