Construct BuiltinSumWithGenerator

Performance Diagrams

Construct BuiltinSumWithGenerator 002000000020000000400000004000000060000000600000008000000080000000100000000100000000120000000120000000140000000140000000160000000160000000180000000180000000200000000200000000220000000220000000CPython 2.7Nuitka (master)Nuitka (develop)Nuitka (factory)22311586888.11538461538461264.7688598529354CPython 2.7230357903240.03846153846155257.0Nuitka (master)230357618391.96153846153845257.00030573244373Nuitka (develop)230357622543.8846153846154257.00030144146206Nuitka (factory)Construct BuiltinSumWithGeneratorTicks Construct BuiltinSumWithGenerator 0040000000400000008000000080000000120000000120000000160000000160000000200000000200000000240000000240000000280000000280000000320000000320000000CPython 3.5Nuitka (master)Nuitka (develop)Nuitka (factory)32286353988.11538461538461257.0CPython 3.5271035063240.03846153846155296.66881432458445Nuitka (master)271077739391.96153846153845296.6361506915632Nuitka (develop)271033495543.8846153846154296.6700144505704Nuitka (factory)Construct BuiltinSumWithGeneratorTicks

Source Code with Construct

empty = ()

def calledRepeatedly():
    # We measure making a generator iterator step or not.
    gen = (x for x in range(1000))

    # This should abort.
# construct_begin
    y = sum(gen)
# construct_alternative



    return y, gen

import itertools
for x in itertools.repeat(None, 500):
    calledRepeatedly()

print("OK.")

Source Code without Construct

empty = ()

def calledRepeatedly():
    # We measure making a generator iterator step or not.
    gen = (x for x in range(1000))

    # This should abort.
# construct_begin

# construct_alternative
    y = gen
# construct_end

    return y, gen

import itertools
for x in itertools.repeat(None, 500):
    calledRepeatedly()

print("OK.")

Context Diff of Source Code


Construct
Baseline
24     # We measure making a generator iterator step or not. 24     # We measure making a generator iterator step or not.
25     gen = (x for x in range(1000)) 25     gen = (x for x in range(1000))
26 26
27     # This should abort. 27     # This should abort.
28 # construct_begin 28 # construct_begin
n 29     y = sum(gen) n 29  
30 # construct_alternative 30 # construct_alternative
t 31   t 31     y = gen
32   32 # construct_end
33 33
34     return y, gen 34     return y, gen
35 35
36 import itertools 36 import itertools
37 for x in itertools.repeat(None, 500): 37 for x in itertools.repeat(None, 500):

Context Diff of Generated Code


Construct
Baseline
145 145
146     // Local variable declarations. 146     // Local variable declarations.
147     PyObject *var_y = NULL; 147     PyObject *var_y = NULL;
148     PyObject *var_gen = NULL; 148     PyObject *var_gen = NULL;
149     PyObject *tmp_genexpr_1__$0 = NULL; 149     PyObject *tmp_genexpr_1__$0 = NULL;
n 150     struct Nuitka_FrameObject *frame_f2a39da13f0b1cf9e3265e966fabae2f; n
151     NUITKA_MAY_BE_UNUSED char const *type_description_1 = NULL;
152     PyObject *exception_type = NULL;
153     PyObject *exception_value = NULL;
154     PyTracebackObject *exception_tb = NULL;
155     NUITKA_MAY_BE_UNUSED int exception_lineno = 0;
156     static struct Nuitka_FrameObject *cache_frame_f2a39da13f0b1cf9e3265e966fabae2f = NULL;
157     PyObject *tmp_return_value = NULL; 150     PyObject *tmp_return_value = NULL;
n 158     PyObject *exception_keeper_type_1; n
159     PyObject *exception_keeper_value_1;
160     PyTracebackObject *exception_keeper_tb_1;
161     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_1;
162 151
163     // Actual function code. 152     // Actual function code.
164     { 153     {
165     PyObject *tmp_assign_source_1; 154     PyObject *tmp_assign_source_1;
166     PyObject *tmp_outline_return_value_1; 155     PyObject *tmp_outline_return_value_1;
214     assert( var_gen == NULL ); 203     assert( var_gen == NULL );
215     var_gen = tmp_assign_source_1; 204     var_gen = tmp_assign_source_1;
216 205
217     } 206     }
218     { 207     {
n n 208     PyObject *tmp_assign_source_3;
209     tmp_assign_source_3 = var_gen;
210  
211     CHECK_OBJECT( tmp_assign_source_3 );
212     assert( var_y == NULL );
213     Py_INCREF( tmp_assign_source_3 );
214     var_y = tmp_assign_source_3;
215  
216     }
217     {
219     // Tried code: 218     // Tried code:
n 220     MAKE_OR_REUSE_FRAME( cache_frame_f2a39da13f0b1cf9e3265e966fabae2f, codeobj_f2a39da13f0b1cf9e3265e966fabae2f, module___main__, sizeof(void *)+sizeof(void *) ); n
221     frame_f2a39da13f0b1cf9e3265e966fabae2f = cache_frame_f2a39da13f0b1cf9e3265e966fabae2f;
222  
223     // Push the new frame as the currently active one.
224     pushFrameStack( frame_f2a39da13f0b1cf9e3265e966fabae2f );
225  
226     // Mark the frame object as in use, ref count 1 will be up for reuse.
227     assert( Py_REFCNT( frame_f2a39da13f0b1cf9e3265e966fabae2f ) == 2 ); // Frame stack
228  
229     // Framed code:
230     {
231     PyObject *tmp_assign_source_3;
232     PyObject *tmp_sum_sequence_1;
233     tmp_sum_sequence_1 = var_gen;
234  
235     CHECK_OBJECT( tmp_sum_sequence_1 );
236     tmp_assign_source_3 = BUILTIN_SUM1( tmp_sum_sequence_1 );
237     if ( tmp_assign_source_3 == NULL )
238     {
239         assert( ERROR_OCCURRED() );
240  
241         FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
242  
243  
244         exception_lineno = 29;
245         type_description_1 = "oo";
246         goto frame_exception_exit_1;
247     }
248     assert( var_y == NULL );
249     var_y = tmp_assign_source_3;
250  
251     }
252  
253 #if 0
254     RESTORE_FRAME_EXCEPTION( frame_f2a39da13f0b1cf9e3265e966fabae2f );
255 #endif
256  
257     // Put the previous frame back on top.
258     popFrameStack();
259  
260     goto frame_no_exception_1;
261  
262     frame_exception_exit_1:;
263  
264 #if 0
265     RESTORE_FRAME_EXCEPTION( frame_f2a39da13f0b1cf9e3265e966fabae2f );
266 #endif
267  
268     if ( exception_tb == NULL )
269     {
270         exception_tb = MAKE_TRACEBACK( frame_f2a39da13f0b1cf9e3265e966fabae2f, exception_lineno );
271     }
272     else if ( exception_tb->tb_frame != &frame_f2a39da13f0b1cf9e3265e966fabae2f->m_frame )
273     {
274         exception_tb = ADD_TRACEBACK( exception_tb, frame_f2a39da13f0b1cf9e3265e966fabae2f, exception_lineno );
275     }
276  
277     // Attachs locals to frame if any.
278     Nuitka_Frame_AttachLocals(
279         (struct Nuitka_FrameObject *)frame_f2a39da13f0b1cf9e3265e966fabae2f,
280         type_description_1,
281         var_y,
282         var_gen
283     );
284  
285  
286     // Release cached frame.
287     if ( frame_f2a39da13f0b1cf9e3265e966fabae2f == cache_frame_f2a39da13f0b1cf9e3265e966fabae2f )
288     {
289         Py_DECREF( frame_f2a39da13f0b1cf9e3265e966fabae2f );
290     }
291     cache_frame_f2a39da13f0b1cf9e3265e966fabae2f = NULL;
292  
293     assertFrameObject( frame_f2a39da13f0b1cf9e3265e966fabae2f );
294  
295     // Put the previous frame back on top.
296     popFrameStack();
297  
298     // Return the error.
299     goto try_except_handler_2;
300  
301     frame_no_exception_1:;
302  
303     { 219     {
304     PyObject *tmp_tuple_element_1; 220     PyObject *tmp_tuple_element_1;
305     tmp_tuple_element_1 = var_y; 221     tmp_tuple_element_1 = var_y;
306 222
307     CHECK_OBJECT( tmp_tuple_element_1 ); 223     CHECK_OBJECT( tmp_tuple_element_1 );
332 248
333     } 249     }
334     { 250     {
335     goto function_return_exit; 251     goto function_return_exit;
336     } 252     }
n 337     // Exception handler code: n
338     try_except_handler_2:;
339     exception_keeper_type_1 = exception_type;
340     exception_keeper_value_1 = exception_value;
341     exception_keeper_tb_1 = exception_tb;
342     exception_keeper_lineno_1 = exception_lineno;
343     exception_type = NULL;
344     exception_value = NULL;
345     exception_tb = NULL;
346     exception_lineno = 0;
347  
348     {
349     CHECK_OBJECT( (PyObject *)var_gen );
350     Py_DECREF( var_gen );
351     var_gen = NULL;
352  
353     }
354     {
355     // Re-raise.
356     exception_type = exception_keeper_type_1;
357     exception_value = exception_keeper_value_1;
358     exception_tb = exception_keeper_tb_1;
359     exception_lineno = exception_keeper_lineno_1;
360  
361     goto function_exception_exit;
362     }
363     // End of try: 253     // End of try:
364     } 254     }
365 255
366     // Return statement must have exited already. 256     // Return statement must have exited already.
367     NUITKA_CANNOT_GET_HERE( __main__$$$function_1_calledRepeatedly ); 257     NUITKA_CANNOT_GET_HERE( __main__$$$function_1_calledRepeatedly );
368     return NULL; 258     return NULL;
369 259
t 370 function_exception_exit: t
371     assert( exception_type );
372     RESTORE_ERROR_OCCURRED( exception_type, exception_value, exception_tb );
373  
374     return NULL;
375 function_return_exit: 260 function_return_exit:
376 261
377 CHECK_OBJECT( tmp_return_value ); 262 CHECK_OBJECT( tmp_return_value );
378 assert( had_error || !ERROR_OCCURRED() ); 263 assert( had_error || !ERROR_OCCURRED() );
379 return tmp_return_value; 264 return tmp_return_value;