Construct ClosureVariableAccess

Performance Diagrams

Construct ClosureVariableAccess 001000000100000020000002000000300000030000004000000400000050000005000000600000060000007000000700000080000008000000CPython 2.7Nuitka (historic)Nuitka (master)Nuitka (develop)Nuitka (factory)853494374.3076923076923257.0CPython 2.72799795198.15384615384616423.0518768369225Nuitka (historic)2700141322.0425.9371962278618Nuitka (master)2700177445.8461538461538425.93615390644896Nuitka (develop)2700159569.6923076923077425.93667506715536Nuitka (factory)Construct ClosureVariableAccessTicks Construct ClosureVariableAccess 0010000001000000200000020000003000000300000040000004000000500000050000006000000600000070000007000000CPython 3.5Nuitka (historic)Nuitka (master)Nuitka (develop)Nuitka (factory)792533274.3076923076923257.0CPython 3.50198.15384615384616504.11538461538464Nuitka (historic)3104343322.0407.32058606018506Nuitka (master)3100928445.8461538461538407.42706728248106Nuitka (develop)3099146569.6923076923077407.4826308368387Nuitka (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()

for x in xrange(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()

for x in xrange(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
331     // Local variable declarations. 331     // Local variable declarations.
332     PyObject *exception_type = NULL, *exception_value = NULL; 332     PyObject *exception_type = NULL, *exception_value = NULL;
333     PyTracebackObject *exception_tb = NULL; 333     PyTracebackObject *exception_tb = NULL;
334     NUITKA_MAY_BE_UNUSED int exception_lineno = -1; 334     NUITKA_MAY_BE_UNUSED int exception_lineno = -1;
335     PyObject *tmp_assign_source_1; 335     PyObject *tmp_assign_source_1;
n 336     PyObject *tmp_assign_source_2; n
337     PyObject *tmp_return_value; 336     PyObject *tmp_return_value;
338     NUITKA_MAY_BE_UNUSED PyObject *tmp_unused; 337     NUITKA_MAY_BE_UNUSED PyObject *tmp_unused;
339     static struct Nuitka_FrameObject *cache_frame_97186bbecfe7fd58856ae48224d8f14f = NULL; 338     static struct Nuitka_FrameObject *cache_frame_97186bbecfe7fd58856ae48224d8f14f = NULL;
340 339
341     struct Nuitka_FrameObject *frame_97186bbecfe7fd58856ae48224d8f14f; 340     struct Nuitka_FrameObject *frame_97186bbecfe7fd58856ae48224d8f14f;
393         exception_value = PyUnicode_FromFormat( "free variable '%s' referenced before assignment in enclosing scope", "closure_value" ); 392         exception_value = PyUnicode_FromFormat( "free variable '%s' referenced before assignment in enclosing scope", "closure_value" );
394         exception_tb = NULL; 393         exception_tb = NULL;
395         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb ); 394         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
396         CHAIN_EXCEPTION( exception_value ); 395         CHAIN_EXCEPTION( exception_value );
397 396
n 398         exception_lineno = 35; n
399         type_description = "c";
400         goto frame_exception_exit_1;
401     }
402  
403     UPDATE_STRING_DICT0( moduledict___main__, (Nuitka_StringObject *)const_str_plain_module_value2, tmp_assign_source_1 );
404     if ( self->m_closure[0] == NULL )
405     {
406         tmp_assign_source_2 = NULL;
407     }
408     else
409     {
410         tmp_assign_source_2 = PyCell_GET( self->m_closure[0] );
411     }
412  
413     if ( tmp_assign_source_2 == NULL )
414     {
415  
416         exception_type = PyExc_NameError;
417         Py_INCREF( exception_type );
418         exception_value = PyUnicode_FromFormat( "free variable '%s' referenced before assignment in enclosing scope", "closure_value" );
419         exception_tb = NULL;
420         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
421         CHAIN_EXCEPTION( exception_value );
422  
423         exception_lineno = 38; 397         exception_lineno = 38;
424         type_description = "c"; 398         type_description = "c";
425         goto frame_exception_exit_1; 399         goto frame_exception_exit_1;
426     } 400     }
427 401
t 428     UPDATE_STRING_DICT0( moduledict___main__, (Nuitka_StringObject *)const_str_plain_module_value3, tmp_assign_source_2 ); t 402     UPDATE_STRING_DICT0( moduledict___main__, (Nuitka_StringObject *)const_str_plain_module_value3, tmp_assign_source_1 );
429 403
430 #if 0 404 #if 0
431     RESTORE_FRAME_EXCEPTION( frame_97186bbecfe7fd58856ae48224d8f14f ); 405     RESTORE_FRAME_EXCEPTION( frame_97186bbecfe7fd58856ae48224d8f14f );
432 #endif 406 #endif
433 407