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)2549508445.8461538461538430.2985295994812Nuitka (develop)2549427569.6923076923077430.30087482266003Nuitka (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)2949563445.8461538461538412.14669545607774Nuitka (develop)2951934569.6923076923077412.072766619163Nuitka (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_function = NULL; 338     static struct Nuitka_FrameObject *cache_frame_function = NULL;
340 339
341     struct Nuitka_FrameObject *frame_function; 340     struct Nuitka_FrameObject *frame_function;
386         exception_value = PyUnicode_FromFormat( "free variable '%s' referenced before assignment in enclosing scope", "closure_value" ); 385         exception_value = PyUnicode_FromFormat( "free variable '%s' referenced before assignment in enclosing scope", "closure_value" );
387         exception_tb = NULL; 386         exception_tb = NULL;
388         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb ); 387         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
389         CHAIN_EXCEPTION( exception_value ); 388         CHAIN_EXCEPTION( exception_value );
390 389
n 391         exception_lineno = 35; n
392         type_description = "c";
393         goto frame_exception_exit_1;
394     }
395  
396     UPDATE_STRING_DICT0( moduledict___main__, (Nuitka_StringObject *)const_str_plain_module_value2, tmp_assign_source_1 );
397     tmp_assign_source_2 = PyCell_GET( self->m_closure[0] );
398  
399     if ( tmp_assign_source_2 == NULL )
400     {
401  
402         exception_type = PyExc_NameError;
403         Py_INCREF( exception_type );
404         exception_value = PyUnicode_FromFormat( "free variable '%s' referenced before assignment in enclosing scope", "closure_value" );
405         exception_tb = NULL;
406         NORMALIZE_EXCEPTION( &exception_type, &exception_value, &exception_tb );
407         CHAIN_EXCEPTION( exception_value );
408  
409         exception_lineno = 38; 390         exception_lineno = 38;
410         type_description = "c"; 391         type_description = "c";
411         goto frame_exception_exit_1; 392         goto frame_exception_exit_1;
412     } 393     }
413 394
t 414     UPDATE_STRING_DICT0( moduledict___main__, (Nuitka_StringObject *)const_str_plain_module_value3, tmp_assign_source_2 ); t 395     UPDATE_STRING_DICT0( moduledict___main__, (Nuitka_StringObject *)const_str_plain_module_value3, tmp_assign_source_1 );
415 396
416 #if 0 397 #if 0
417     RESTORE_FRAME_EXCEPTION( frame_function ); 398     RESTORE_FRAME_EXCEPTION( frame_function );
418 #endif 399 #endif
419 400