[Python-ideas] Keep free list of popular iterator objects

Tim Peters tim.peters at gmail.com
Sun Sep 15 21:18:19 CEST 2013


[ Kyle Fisher]
> ...
> Even if the iterator freelist isn't in first-level cache, I'm almost certain
> it would exist within last-level cache.  Do you know what the cost of
> fetching from this is compared to grabbing a lock like the current
> _Py_Malloc does?

It's infinitely more expensive than grabbing a lock ;-)  As Antoine
noted earlier in this thread, while obmalloc.c is sprinkled with
LOCK() and UNLOCK() macros, they all expand  to "nothing" - obmalloc.c
doesn't actually grab any locks (it relies on the GIL to serialize
threads).

For example, LOCK is defined thusly:

#define LOCK()          SIMPLELOCK_LOCK(_malloc_lock)

and above that there's:

#define SIMPLELOCK_LOCK(lock)   /* acquire released lock */

Just FYI ;-)


More information about the Python-ideas mailing list