Construct BuiltinSumWithGenerator

Performance Diagrams

Construct BuiltinSumWithGenerator 002000000020000000400000004000000060000000600000008000000080000000100000000100000000120000000120000000140000000140000000160000000160000000180000000180000000200000000200000000CPython 2.7Nuitka (master)Nuitka (develop)Nuitka (factory)21909606688.11538461538461257.0CPython 2.7121828646240.03846153846155366.7065608829606Nuitka (master)121828117391.96153846153845366.7071575346525Nuitka (develop)121825579543.8846153846154366.7100201093103Nuitka (factory)Construct BuiltinSumWithGeneratorTicks Construct BuiltinSumWithGenerator 0040000000400000008000000080000000120000000120000000160000000160000000200000000200000000240000000240000000280000000280000000320000000320000000CPython 3.5Nuitka (master)Nuitka (develop)Nuitka (factory)32636598388.11538461538461257.0CPython 3.5172804505240.03846153846155373.2725457759393Nuitka (master)172803428391.96153846153845373.2733612508451Nuitka (develop)172804158543.8846153846154373.2728085148365Nuitka (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
147 147
148     // Local variable declarations. 148     // Local variable declarations.
149     PyObject *var_y = NULL; 149     PyObject *var_y = NULL;
150     PyObject *var_gen = NULL; 150     PyObject *var_gen = NULL;
151     PyObject *tmp_genexpr_1__$0 = NULL; 151     PyObject *tmp_genexpr_1__$0 = NULL;
n 152     struct Nuitka_FrameObject *frame_4247af9bc176fb7dbbae7ff31027820d; n
153     NUITKA_MAY_BE_UNUSED char const *type_description_1 = NULL;
154     PyObject *exception_type = NULL;
155     PyObject *exception_value = NULL;
156     PyTracebackObject *exception_tb = NULL;
157     NUITKA_MAY_BE_UNUSED int exception_lineno = 0;
158     static struct Nuitka_FrameObject *cache_frame_4247af9bc176fb7dbbae7ff31027820d = NULL;
159     PyObject *tmp_return_value = NULL; 152     PyObject *tmp_return_value = NULL;
n 160     PyObject *exception_keeper_type_1; n
161     PyObject *exception_keeper_value_1;
162     PyTracebackObject *exception_keeper_tb_1;
163     NUITKA_MAY_BE_UNUSED int exception_keeper_lineno_1;
164 153
165     // Actual function body. 154     // Actual function body.
166     { 155     {
167         PyObject *tmp_assign_source_1; 156         PyObject *tmp_assign_source_1;
168         { 157         {
201         return NULL; 190         return NULL;
202         outline_result_1:; 191         outline_result_1:;
203         assert( var_gen == NULL ); 192         assert( var_gen == NULL );
204         var_gen = tmp_assign_source_1; 193         var_gen = tmp_assign_source_1;
205     } 194     }
n n 195     {
196         PyObject *tmp_assign_source_3;
197         CHECK_OBJECT( var_gen );
198         tmp_assign_source_3 = var_gen;
199         assert( var_y == NULL );
200         Py_INCREF( tmp_assign_source_3 );
201         var_y = tmp_assign_source_3;
202     }
206     // Tried code: 203     // Tried code:
n 207     MAKE_OR_REUSE_FRAME( cache_frame_4247af9bc176fb7dbbae7ff31027820d, codeobj_4247af9bc176fb7dbbae7ff31027820d, module___main__, sizeof(void *)+sizeof(void *) ); n
208     frame_4247af9bc176fb7dbbae7ff31027820d = cache_frame_4247af9bc176fb7dbbae7ff31027820d;
209  
210     // Push the new frame as the currently active one.
211     pushFrameStack( frame_4247af9bc176fb7dbbae7ff31027820d );
212  
213     // Mark the frame object as in use, ref count 1 will be up for reuse.
214     assert( Py_REFCNT( frame_4247af9bc176fb7dbbae7ff31027820d ) == 2 ); // Frame stack
215  
216     // Framed code:
217     {
218         PyObject *tmp_assign_source_3;
219         PyObject *tmp_sum_sequence_1;
220         CHECK_OBJECT( var_gen );
221         tmp_sum_sequence_1 = var_gen;
222         tmp_assign_source_3 = BUILTIN_SUM1( tmp_sum_sequence_1 );
223         if ( tmp_assign_source_3 == NULL )
224         {
225             assert( ERROR_OCCURRED() );
226  
227             FETCH_ERROR_OCCURRED( &exception_type, &exception_value, &exception_tb );
228  
229  
230             exception_lineno = 29;
231             type_description_1 = "oo";
232             goto frame_exception_exit_1;
233         }
234         assert( var_y == NULL );
235         var_y = tmp_assign_source_3;
236     }
237  
238 #if 0
239     RESTORE_FRAME_EXCEPTION( frame_4247af9bc176fb7dbbae7ff31027820d );
240 #endif
241  
242     // Put the previous frame back on top.
243     popFrameStack();
244  
245     goto frame_no_exception_1;
246  
247     frame_exception_exit_1:;
248  
249 #if 0
250     RESTORE_FRAME_EXCEPTION( frame_4247af9bc176fb7dbbae7ff31027820d );
251 #endif
252  
253     if ( exception_tb == NULL )
254     {
255         exception_tb = MAKE_TRACEBACK( frame_4247af9bc176fb7dbbae7ff31027820d, exception_lineno );
256     }
257     else if ( exception_tb->tb_frame != &frame_4247af9bc176fb7dbbae7ff31027820d->m_frame )
258     {
259         exception_tb = ADD_TRACEBACK( exception_tb, frame_4247af9bc176fb7dbbae7ff31027820d, exception_lineno );
260     }
261  
262     // Attachs locals to frame if any.
263     Nuitka_Frame_AttachLocals(
264         (struct Nuitka_FrameObject *)frame_4247af9bc176fb7dbbae7ff31027820d,
265         type_description_1,
266         var_y,
267         var_gen
268     );
269  
270  
271     // Release cached frame.
272     if ( frame_4247af9bc176fb7dbbae7ff31027820d == cache_frame_4247af9bc176fb7dbbae7ff31027820d )
273     {
274         Py_DECREF( frame_4247af9bc176fb7dbbae7ff31027820d );
275     }
276     cache_frame_4247af9bc176fb7dbbae7ff31027820d = NULL;
277  
278     assertFrameObject( frame_4247af9bc176fb7dbbae7ff31027820d );
279  
280     // Put the previous frame back on top.
281     popFrameStack();
282  
283     // Return the error.
284     goto try_except_handler_2;
285  
286     frame_no_exception_1:;
287     { 204     {
288         PyObject *tmp_tuple_element_1; 205         PyObject *tmp_tuple_element_1;
289         CHECK_OBJECT( var_y ); 206         CHECK_OBJECT( var_y );
290         tmp_tuple_element_1 = var_y; 207         tmp_tuple_element_1 = var_y;
291         tmp_return_value = PyTuple_New( 2 ); 208         tmp_return_value = PyTuple_New( 2 );
309     CHECK_OBJECT( (PyObject *)var_gen ); 226     CHECK_OBJECT( (PyObject *)var_gen );
310     Py_DECREF( var_gen ); 227     Py_DECREF( var_gen );
311     var_gen = NULL; 228     var_gen = NULL;
312 229
313     goto function_return_exit; 230     goto function_return_exit;
n 314     // Exception handler code: n
315     try_except_handler_2:;
316     exception_keeper_type_1 = exception_type;
317     exception_keeper_value_1 = exception_value;
318     exception_keeper_tb_1 = exception_tb;
319     exception_keeper_lineno_1 = exception_lineno;
320     exception_type = NULL;
321     exception_value = NULL;
322     exception_tb = NULL;
323     exception_lineno = 0;
324  
325     CHECK_OBJECT( (PyObject *)var_gen );
326     Py_DECREF( var_gen );
327     var_gen = NULL;
328  
329     // Re-raise.
330     exception_type = exception_keeper_type_1;
331     exception_value = exception_keeper_value_1;
332     exception_tb = exception_keeper_tb_1;
333     exception_lineno = exception_keeper_lineno_1;
334  
335     goto function_exception_exit;
336     // End of try: 231     // End of try:
337 232
338     // Return statement must have exited already. 233     // Return statement must have exited already.
339     NUITKA_CANNOT_GET_HERE( __main__$$$function_1_calledRepeatedly ); 234     NUITKA_CANNOT_GET_HERE( __main__$$$function_1_calledRepeatedly );
340     return NULL; 235     return NULL;
341 236
t 342 function_exception_exit: t
343     assert( exception_type );
344     RESTORE_ERROR_OCCURRED( exception_type, exception_value, exception_tb );
345  
346     return NULL;
347 237
348 function_return_exit: 238 function_return_exit:
349    // Function cleanup code if any. 239    // Function cleanup code if any.
350 240
351 241