Construct ClosureVariableAccess

Performance Diagrams

Construct ClosureVariableAccess 001000000100000020000002000000300000030000004000000400000050000005000000600000060000007000000700000080000008000000CPython 2.7Nuitka (historic)Nuitka (master)Nuitka (develop)Nuitka (factory)853494374.3076923076923257.0CPython 2.72799795198.15384615384616423.0518768369225Nuitka (historic)2550270322.0430.27646712957636Nuitka (master)2550144445.8461538461538430.2801152545212Nuitka (develop)2549862569.6923076923077430.2882801055884Nuitka (factory)Construct ClosureVariableAccessTicks Construct ClosureVariableAccess 0010000001000000200000020000003000000300000040000004000000500000050000006000000600000070000007000000CPython 3.5Nuitka (historic)Nuitka (master)Nuitka (develop)Nuitka (factory)792533274.3076923076923257.0CPython 3.50198.15384615384616504.11538461538464Nuitka (historic)2950653322.0412.1127087701912Nuitka (master)2948307445.8461538461538412.18585809596175Nuitka (develop)2948427569.6923076923077412.18211644246963Nuitka (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
367     // Local variable declarations. 367     // Local variable declarations.
368     PyObject *exception_type = NULL, *exception_value = NULL; 368     PyObject *exception_type = NULL, *exception_value = NULL;
369     PyTracebackObject *exception_tb = NULL; 369     PyTracebackObject *exception_tb = NULL;
370     NUITKA_MAY_BE_UNUSED int exception_lineno = -1; 370     NUITKA_MAY_BE_UNUSED int exception_lineno = -1;
371     PyObject *tmp_assign_source_1; 371     PyObject *tmp_assign_source_1;
n 372     PyObject *tmp_assign_source_2; n
373     PyObject *tmp_frame_locals; 372     PyObject *tmp_frame_locals;
374     PyObject *tmp_return_value; 373     PyObject *tmp_return_value;
375     NUITKA_MAY_BE_UNUSED PyObject *tmp_unused; 374     NUITKA_MAY_BE_UNUSED PyObject *tmp_unused;
376     static PyFrameObject *cache_frame_function = NULL; 375     static PyFrameObject *cache_frame_function = NULL;
377 376
426         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" );
427         exception_tb = NULL; 426         exception_tb = NULL;
428         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb ); 427         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
429         CHAIN_EXCEPTION( exception_value ); 428         CHAIN_EXCEPTION( exception_value );
430 429
n 431         exception_lineno = 35; n
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     tmp_assign_source_2 = PyCell_GET( self->m_closure[0] );
437  
438     if ( tmp_assign_source_2 == NULL )
439     {
440  
441         exception_type = PyExc_NameError;
442         Py_INCREF( exception_type );
443         exception_value = PyUnicode_FromFormat( "free variable '%s' referenced before assignment in enclosing scope", "closure_value" );
444         exception_tb = NULL;
445         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
446         CHAIN_EXCEPTION( exception_value );
447  
448         exception_lineno = 38; 430         exception_lineno = 38;
449         goto frame_exception_exit_1; 431         goto frame_exception_exit_1;
450     } 432     }
451 433
t 452     UPDATE_STRING_DICT0( moduledict___main__, (Nuitka_StringObject *)const_str_plain_module_value3, tmp_assign_source_2 ); t 434     UPDATE_STRING_DICT0( moduledict___main__, (Nuitka_StringObject *)const_str_plain_module_value3, tmp_assign_source_1 );
453 435
454 #if 0 436 #if 0
455     RESTORE_FRAME_EXCEPTION( frame_function ); 437     RESTORE_FRAME_EXCEPTION( frame_function );
456 #endif 438 #endif
457     // Put the previous frame back on top. 439     // Put the previous frame back on top.