imports and python locking
Neal Becker
ndbecker2 at gmail.com
Thu Jul 21 15:59:48 BST 2005
Martin Pool wrote:
> Some benchmarking on bzr's hashcache showed a downside to our current
> policy of doing imports in inner scopes.
>
> Every import statement results in a builtin_import call, which needs to
> take and release a lock protecting the module table. This is done by
> semaphores (sem_post, etc) by default. On Linux, for some reason I
> don't understand yet, this always causes a system call to release the
> futex, even though I would think it's not necessary. In any case for
> 'bzr st' this can take up to 40% of the time.
>
> This is compiled out on python built --without-threads, and it would be
> kind of neat to run that for applications that don't use threads, but
> that's not really in our scope here.
>
> Practically, I think we should change the practice to generally doing
> imports at the top level of the module, except that the top-level code
> should only import modules when they're needed for the selected command.
>
> Another approach is to use something like the attached hook to defer
> imports.
>
What distro are you testing on? Is this a modern glibc with nptl?
More information about the bazaar
mailing list