Construct ClosureVariableAccess

Performance Diagrams

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