local namespace optimizations?
Is anyone opposed to me removing the stupid: _getattr = getattr _none = None marker = _marker local namespace """optimizations""" that are found in unrestrictedTraverse? Florent -- Florent Guillaume, Nuxeo (Paris, France) Director of R&D +33 1 40 33 71 59 http://nuxeo.com fg@nuxeo.com
--On 5. Juli 2006 18:56:25 +0200 Florent Guillaume <fg@nuxeo.com> wrote:
Is anyone opposed to me removing the stupid: _getattr = getattr _none = None marker = _marker local namespace """optimizations""" that are found in unrestrictedTraverse?
I am pretty sure that the complete Zope core is still full of those optimizations. -aj
On 5 Jul 2006, at 19:05, Andreas Jung wrote:
--On 5. Juli 2006 18:56:25 +0200 Florent Guillaume <fg@nuxeo.com> wrote:
Is anyone opposed to me removing the stupid: _getattr = getattr _none = None marker = _marker local namespace """optimizations""" that are found in unrestrictedTraverse?
I am pretty sure that the complete Zope core is still full of those optimizations.
Does that mean you're for or against it? Florent -- Florent Guillaume, Nuxeo (Paris, France) Director of R&D +33 1 40 33 71 59 http://nuxeo.com fg@nuxeo.com
--On 5. Juli 2006 19:11:16 +0200 Florent Guillaume <fg@nuxeo.com> wrote:
On 5 Jul 2006, at 19:05, Andreas Jung wrote:
--On 5. Juli 2006 18:56:25 +0200 Florent Guillaume <fg@nuxeo.com> wrote:
Is anyone opposed to me removing the stupid: _getattr = getattr _none = None marker = _marker local namespace """optimizations""" that are found in unrestrictedTraverse?
I am pretty sure that the complete Zope core is still full of those optimizations.
Does that mean you're for or against it?
For (of course) :-) -aj
On Wed, Jul 05, 2006 at 07:21:29PM +0200, Andreas Jung wrote: | >Does that mean you're for or against it? | > | | For (of course) :-) It has been demonstrated in other lists that global lookups are most of the time faster than local lookups in recent versions of python. -- Sidnei da Silva Enfold Systems http://enfoldsystems.com Fax +1 832 201 8856 Office +1 713 942 2377 Ext 214
--On 5. Juli 2006 16:45:21 -0300 Sidnei da Silva <sidnei@enfoldsystems.com> wrote:
On Wed, Jul 05, 2006 at 07:21:29PM +0200, Andreas Jung wrote: | > Does that mean you're for or against it? | > | | For (of course) :-)
It has been demonstrated in other lists that global lookups are most of the time faster than local lookups in recent versions of python.
I am *for* removing them. These culprits must go. -aj
Sidnei da Silva wrote at 2006-7-5 16:45 -0300:
... It has been demonstrated in other lists that global lookups are most of the time faster than local lookups in recent versions of python.
That would extremely surprise me: While global lookup was significantly optimized, it is still an lookup with a string as argument. For local lookup on the other hand, the compiler has turned the name into an index and at runtime, an indexed access it made. That is still faster. An a simple test shows that I am right:
i = 1 def f1(): # using global "i" directly ... x=0 ... for k in xrange(100): x += i ... def f2(): # using global "i" via local "_i" ... x=0; _i=i ... for k in xrange(100): x += _i ... from timeit import Timer t=Timer('__main__.f1()', 'import __main__') t.timeit() 33.647971153259277 t=Timer('__main__.f2()', 'import __main__') t.timeit() 28.818410873413086
I have seen timings which might be misinterpreted in the way you described above: def f(..., opt1=glob1): ... can be slower than directly using "glob1". The reason in this case is that handling optional arguments costs something which might eat the savings due to local access.
-- Sidnei da Silva Enfold Systems http://enfoldsystems.com Fax +1 832 201 8856 Office +1 713 942 2377 Ext 214
-- Dieter
On Wed, Jul 05, 2006 at 10:29:34PM +0200, dieter@handshake.de wrote: | That would extremely surprise me: | | While global lookup was significantly optimized, | it is still an lookup with a string as argument. | | For local lookup on the other hand, the compiler has | turned the name into an index and at runtime, an | indexed access it made. That is still faster. Hum. Hum. Wonder where my brain is. I wish I could find the email with the benchmarks to make me look less silly. -- Sidnei da Silva Enfold Systems http://enfoldsystems.com Fax +1 832 201 8856 Office +1 713 942 2377 Ext 214
...and then I find it. Phew :) http://article.gmane.org/gmane.comp.web.zope.devel/8925 -- Sidnei da Silva Enfold Systems http://enfoldsystems.com Fax +1 832 201 8856 Office +1 713 942 2377 Ext 214
Sidnei da Silva wrote at 2006-7-5 18:06 -0300:
...and then I find it. Phew :)
But you see that this post does not compare local versus global access but "cell reference in enclosing (!) scope" versus global access. As my example proves, "local access" (i.e. "cell reference in local scope") *IS* faster than global access.
-- Sidnei da Silva Enfold Systems http://enfoldsystems.com Fax +1 832 201 8856 Office +1 713 942 2377 Ext 214
-- Dieter
On Wed, Jul 05, 2006 at 11:30:19PM +0200, dieter@handshake.de wrote: | Sidnei da Silva wrote at 2006-7-5 18:06 -0300: | >...and then I find it. Phew :) | > | > http://article.gmane.org/gmane.comp.web.zope.devel/8925 | | But you see that this post does not compare local versus global | access but "cell reference in enclosing (!) scope" versus global access. | | As my example proves, "local access" (i.e. "cell reference in local scope") | *IS* faster than global access. Yup Yup. -- Sidnei da Silva Enfold Systems http://enfoldsystems.com Fax +1 832 201 8856 Office +1 713 942 2377 Ext 214
Florent Guillaume wrote:
Is anyone opposed to me removing the stupid: _getattr = getattr _none = None marker = _marker local namespace """optimizations""" that are found in unrestrictedTraverse?
I find these things rather confusing when looking at zope core code, and always wondered why they were there. In what sense are they optimisations? Tim
--On 5. Juli 2006 19:00:52 +0100 Tim Hicks <tim@sitefusion.co.uk> wrote:
Florent Guillaume wrote:
Is anyone opposed to me removing the stupid: _getattr = getattr _none = None marker = _marker local namespace """optimizations""" that are found in unrestrictedTraverse?
I find these things rather confusing when looking at zope core code, and always wondered why they were there. In what sense are they optimisations?
Evil tricks from the ancient Zope world. Such lookups were faster because the items were directly found in the local namespace so one saved time looking them up in the global namespace. -aj
Florent Guillaume wrote at 2006-7-5 18:56 +0200:
Is anyone opposed to me removing the stupid: _getattr = getattr _none = None marker = _marker local namespace """optimizations""" that are found in unrestrictedTraverse?
Why do you think they were stupid? They do save time -- although it probably does not dominate the total time. -- Dieter
dieter@handshake.de wrote:
Florent Guillaume wrote at 2006-7-5 18:56 +0200:
Is anyone opposed to me removing the stupid: _getattr = getattr _none = None marker = _marker local namespace """optimizations""" that are found in unrestrictedTraverse?
Why do you think they were stupid?
I call them stupid because they are micro-optimizations that are drowned in the rest of the traversal code and make things harder to read. _none vs None are exactly the same speed in my tests. _marker vs a global have a 0.05 microsecond difference on my machine _getattr vs getattr too. And if we "localize" those, why not localize aq_base as well, and guarded_getattr and securityManager.validate and nsParse and namespaceLookup... At least the current unrestrictedTraverse() code has grown sufficiently complex that it should be rebenched and re-optimize if needed, but it's already complex enough to not keep cruft in it if it's not justified. Florent
They do save time -- although it probably does not dominate the total time.
-- Florent Guillaume, Nuxeo (Paris, France) Director of R&D +33 1 40 33 71 59 http://nuxeo.com fg@nuxeo.com
participants (5)
-
Andreas Jung -
dieter@handshake.de -
Florent Guillaume -
Sidnei da Silva -
Tim Hicks