[Zope-CMF] Re: [Performance] "listFilteredActionsFor" unnecessarily
expensive
Tres Seaver
tseaver at zope.com
Wed Apr 6 11:14:36 EDT 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Florent Guillaume wrote:
> Dieter Maurer <dieter at handshake.de> wrote:
>
>>In our regular profiles, "listFilteredActionsFor" belongs to
>>the top consumers of CPU time.
>>
>>Recently, I found the main culprit (in CMF 1.4):
>>
>> It is the completely unnecessary:
>>
>> if not action in catlist:
>>
>>In our case, "listFilteredActionsFor" spends about 70 percent
>>of its complete time in the checking of "action in catlist".
>>
>>How in hell should the same action be defined more than once
>>such that we need to prevent such a case by an explicit check --
>>especially by such an expensive one?
>>
>>A comment before the line indicates that the author intended
>>to check by identity. But, of course, "action in catlist"
>>does *NOT* check by identity but by equality.
>>
>>
>>I propose to remove the check altogether...
>
>
> +1.
>
> The three lines above could be reduced to one using .setdefault() too.
We could also use a 'seen' dictionary:
key = (category, action.id)
if key not in seen:
seen[key] = 1
....
Tres.
- --
===============================================================
Tres Seaver tseaver at zope.com
Zope Corporation "Zope Dealers" http://www.zope.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFCU/zcGqWXf00rNCgRAucmAJ99O136uSaCVPP5oywsSPpuXiw77wCfcCuw
HXKo7WZbt5d/h4u6m1uthfM=
=8Elp
-----END PGP SIGNATURE-----
More information about the Zope-CMF
mailing list