On Wednesday 15 August 2007 04:26:31 Michael Bayer wrote: > On Aug 14, 2007, at 4:35 PM, Michael Bayer wrote: > > On Aug 14, 2007, at 12:38 PM, svilen wrote: > >> ------- > >> orm.attribute > >> AttributeManager.init_attr(): > >> the saving this one eventualy does is too small, compared to > >> a property call of ._state. > > > > i havent benched this in a while but my recollection is that the > > AttributeError raise is *much* slower than pre-calling this > > method. a single function call is always faster than an exception > > throw. > > > > however, i see that the exception throw is being suppressed also > > with a hasattr() being called every time....im not sure why thats > > that way now so i might change it back to throwing > > AttributeError. > > the results are in, running test/prof/masseagerload.py. this test > is very heavy on creating new instances from mapper rows, which is > where the initialization of _state comes in. > > no init_attr(), detect missing with AttributeError > Profiled target 'masseagerload', wall time: 0.59 seconds > Profile report for target 'masseagerload' (masseagerload.prof) > 57039 function calls (55962 primitive calls) in 0.489 CPU seconds > > init_attr(), detect missing with AttributeError > Profiled target 'masseagerload', wall time: 0.53 seconds > 57549 function calls (56472 primitive calls) in 0.426 CPU seconds > > init_attr(), detect missing with hasattr > Profiled target 'masseagerload', wall time: 0.56 seconds > 57549 function calls (56472 primitive calls) in 0.431 CPU seconds > > no init_attr(), detect missing with hasattr > Profiled target 'masseagerload', wall time: 0.49 seconds > 57039 function calls (55962 primitive calls) in 0.390 CPU seconds > > im not exactly sure why the "hasattr()" call, being present and > then removed, doesnt change the number of function calls. anyway, > the times vary a little bit but the "hasattr" call, even though its > called many more times than the AttributeError gets raised, is > slightly faster than raising AttributeError. so no AttributeError, > and I like getting rid of init_attr() very much so its out in > r3313.
heh. First, the init_attr as it was, has never worked - it sets up a private __sa_attr_state, while what is used is plain non-private _sa_attr_state attribute (note starting underscores). Second, i went to r3312, let init_attr() set a _state as plain dict and removed _state as property. The difference plain-dict/property (in favor of plain dict) is like 2-3%. property: loaded 10 items each with 500 subitems 523034 function calls (512957 primitive calls) in 2.556 CPU s loaded 30 items each with 500 subitems 1564374 function calls (1534297 primitive calls) in 7.796 CPU s loaded 16 items each with 1500 subitems 2499436 function calls (2451359 primitive calls) in 12.518 CPU s plain dict: loaded 10 items each with 500 subitems 513014 function calls (502937 primitive calls) in 2.525 CPU s loaded 30 items each with 500 subitems 1534314 function calls (1504237 primitive calls) in 7.623 CPU s loaded 16 items each with 1500 subitems 2451404 function calls (2403327 primitive calls) in 12.196 CPU s up to you --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---