Document Actions
08/05/2005
AdapterLookup C optimizations
Recently i have created branch in Zope3 repository for checkin in AdapterLookup optimizations, ie rewriting it in C for speed up as many applications will be doing lots of lookup requests, so this part is quite crucial.
You can take a look at it here:
http://svn.zope.org/Zope3/branches/alienoid-adapter_lookup_coptimizations/

For the moment all methods(namely lookup, lookup1, adapter_hook, queryAdapter, subscriptions, subscribers, queryMultiAdapter) are implemented and pass tests, of course code is far from ideal, but i'm trying and waiting for
Jim Fulton to come back from holidays and take a look at my attempt to make world better or better to say faster :)

Here are benchmarks with 'timeit' i have on my P4 2.4Gh 1Gb RAM, run 3 times for Python and C versions. All developments and tests under linux of course :)

Python version:
==========
2.189   registry.lookup([IR1], IP2, '')
2.199   registry.lookup([IR2], IP2, '')
2.067   registry.lookup([zope.interface.implementedBy(C2)], IP2, '')
4.418   registry.lookup([IR1, IQ], IP2, '')
2.377   registry.lookup1(IR2, IP1)
3.528   registry.queryAdapter(x, IP1)
3.271   registry.adapter_hook(IP1, x)
6.128   registry.queryMultiAdapter((x, q), IM)
2.467   registry.subscriptions([IR1], IP2)
2.472   registry.subscriptions([IR2], IP1)
3.445   registry.subscriptions([IR1, IQ], IP2)
5.385   registry.subscribers((x, q), IM)
201.965163946 - total elapsed
--------------------------------------------------
2.194   registry.lookup([IR1], IP2, '')
2.197   registry.lookup([IR2], IP2, '')
2.071   registry.lookup([zope.interface.implementedBy(C2)], IP2, '')
4.389   registry.lookup([IR1, IQ], IP2, '')
2.414   registry.lookup1(IR2, IP1)
3.563   registry.queryAdapter(x, IP1)
3.295   registry.adapter_hook(IP1, x)
6.148   registry.queryMultiAdapter((x, q), IM)
2.475   registry.subscriptions([IR1], IP2)
2.467   registry.subscriptions([IR2], IP1)
3.440   registry.subscriptions([IR1, IQ], IP2)
5.375   registry.subscribers((x, q), IM)
201.607703924 - total elapsed
------------------------------------------------
2.230   registry.lookup([IR1], IP2, '')
2.220   registry.lookup([IR2], IP2, '')
2.091   registry.lookup([zope.interface.implementedBy(C2)], IP2, '')
4.453   registry.lookup([IR1, IQ], IP2, '')
2.400   registry.lookup1(IR2, IP1)
3.517   registry.queryAdapter(x, IP1)
3.300   registry.adapter_hook(IP1, x)
6.198   registry.queryMultiAdapter((x, q), IM)
2.505   registry.subscriptions([IR1], IP2)
2.490   registry.subscriptions([IR2], IP1)
3.464   registry.subscriptions([IR1, IQ], IP2)
5.404   registry.subscribers((x, q), IM)
202.900254011 - total elapsed


C Version
==========

1.655   registry.lookup([IR1], IP2, '')
1.658   registry.lookup([IR2], IP2, '')
1.706   registry.lookup([zope.interface.implementedBy(C2)], IP2, '')
3.078   registry.lookup([IR1, IQ], IP2, '')
1.798   registry.lookup1(IR2, IP1)
2.646   registry.queryAdapter(x, IP1)
2.542   registry.adapter_hook(IP1, x)
4.676   registry.queryMultiAdapter((x, q), IM)
1.792   registry.subscriptions([IR1], IP2)
1.785   registry.subscriptions([IR2], IP1)
2.777   registry.subscriptions([IR1, IQ], IP2)
3.948   registry.subscribers((x, q), IM)
152.926780939 - total elapsed
----------------------------------------------
1.673   registry.lookup([IR1], IP2, '')
1.674   registry.lookup([IR2], IP2, '')
1.683   registry.lookup([zope.interface.implementedBy(C2)], IP2, '')
3.101   registry.lookup([IR1, IQ], IP2, '')
1.778   registry.lookup1(IR2, IP1)
2.633   registry.queryAdapter(x, IP1)
2.522   registry.adapter_hook(IP1, x)
4.625   registry.queryMultiAdapter((x, q), IM)
1.808   registry.subscriptions([IR1], IP2)
1.799   registry.subscriptions([IR2], IP1)
2.786   registry.subscriptions([IR1, IQ], IP2)
3.861   registry.subscribers((x, q), IM)
151.658464193 - total elapsed
----------------------------------------------
1.690   registry.lookup([IR1], IP2, '')
1.690   registry.lookup([IR2], IP2, '')
1.709   registry.lookup([zope.interface.implementedBy(C2)], IP2, '')
3.114   registry.lookup([IR1, IQ], IP2, '')
1.806   registry.lookup1(IR2, IP1)
2.641   registry.queryAdapter(x, IP1)
2.567   registry.adapter_hook(IP1, x)
4.700   registry.queryMultiAdapter((x, q), IM)
1.821   registry.subscriptions([IR1], IP2)
1.821   registry.subscriptions([IR2], IP1)
2.812   registry.subscriptions([IR1, IQ], IP2)
3.953   registry.subscribers((x, q), IM)
153.785687923 - total elapsed

So, speedup by my estimation is ~20-26% for different methods.
It may vary in future but this is how it is currently at my side.

Benchmark script is attached.
Posted by Ruslan Spivak @ 08/05/2005 09:49 AM. - Categories: zope3 -  0 comments
Last modified: 01/31/2005 06:39 PM

Nuxeo Bloggers: Log in!
Nuxeo - Indesko - Nuxeo 5 Project
All content is copyrighted by their author.
CPSSkins is Copyright © 2003-2006 by Jean-Marc Orliaguet. | CPS is Copyright © 2002-2006 by Nuxeo SAS.