This issue tracker has been migrated to GitHub ,
and is currently read-only.
For more information,
see the GitHub FAQs in the Python's Developer Guide.
Created on 2021年09月15日 17:42 by eric.snow, last changed 2022年04月11日 14:59 by admin.
| Messages (9) | |||
|---|---|---|---|
| msg401863 - (view) | Author: Eric Snow (eric.snow) * (Python committer) | Date: 2021年09月15日 17:42 | |
When looking up a frozen modules, we loop over the array of frozen modules until we find a match (or don't). See find_frozen() in Python/import.c. The frozen importer sits right after the builtin importer and right before the file-based importer. This means the import system does that frozen module lookup every time import happens (where it isn't a builtin module), even if it's a source module. |
|||
| msg401864 - (view) | Author: Eric Snow (eric.snow) * (Python committer) | Date: 2021年09月15日 17:44 | |
Realistically, I doubt this will ever be a problem. The list of frozen modules is fairly small and the loop in the C code is a lightweight. So it isn't that big of a deal relative to the other costs involved in import. Even if the number of frozen modules grows dramatically, it's unlikely to be a problem. So we should probably close this. Mostly I opened this so folks with the same observations could find it. I'll close the issue in a few days in case I missed something. |
|||
| msg402198 - (view) | Author: Raymond Hettinger (rhettinger) * (Python committer) | Date: 2021年09月20日 06:55 | |
If you close this out, consider adding a prominent comment so that the issue will be on the minds of people looking at this code. |
|||
| msg402232 - (view) | Author: Eric Snow (eric.snow) * (Python committer) | Date: 2021年09月20日 14:11 | |
On Mon, Sep 20, 2021 at 12:55 AM Raymond Hettinger <report@bugs.python.org> wrote: > If you close this out, consider adding a prominent comment so that the issue will be on the minds of people looking at this code. Good idea! |
|||
| msg402431 - (view) | Author: Dong-hee Na (corona10) * (Python committer) | Date: 2021年09月22日 13:12 | |
I thought about the Trie implementation for this case. But as Eric said, it can be overkilling for this time. |
|||
| msg402433 - (view) | Author: Marc-Andre Lemburg (lemburg) * (Python committer) | Date: 2021年09月22日 13:22 | |
Perhaps a frozen dict could be used instead of the linear search. This could then also be made available as sys.frozen_modules for inspection by applications and tools such as debuggers or introspection tools trying to find source code (and potentially failing at this). Not urgent, though. |
|||
| msg402447 - (view) | Author: Eric Snow (eric.snow) * (Python committer) | Date: 2021年09月22日 15:43 | |
On Wed, Sep 22, 2021 at 7:12 AM Dong-hee Na <report@bugs.python.org> wrote: > I thought about the Trie implementation for this case. On Wed, Sep 22, 2021 at 7:22 AM Marc-Andre Lemburg <report@bugs.python.org> wrote: > Perhaps a frozen dict could be used instead of the linear search. > > This could then also be made available as sys.frozen_modules for inspection by applications and tools such as debuggers or introspection tools trying to find source code (and potentially failing at this). Both are worth exploring later. FWIW, I was also considering _Py_hashtable_t (from Include/internal/pycore_hashtable.h). |
|||
| msg402505 - (view) | Author: Steve Dower (steve.dower) * (Python committer) | Date: 2021年09月23日 16:21 | |
Could we add a compile-time requirement (most likely checked in tests, rather than at build) that _PyImport_FrozenModules be sorted? Then we can at least bail out of the loop early, and one day someone could make it a binary search. |
|||
| msg402552 - (view) | Author: Dong-hee Na (corona10) * (Python committer) | Date: 2021年09月24日 10:59 | |
> Then we can at least bail out of the loop early, and one day someone could make it a binary search. I like this idea if we can guarantee the order :) |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:59:50 | admin | set | github: 89376 |
| 2021年09月24日 10:59:10 | corona10 | set | messages: + msg402552 |
| 2021年09月23日 16:21:43 | steve.dower | set | nosy:
+ steve.dower messages: + msg402505 |
| 2021年09月22日 15:43:36 | eric.snow | set | messages: + msg402447 |
| 2021年09月22日 13:22:03 | lemburg | set | nosy:
+ lemburg messages: + msg402433 |
| 2021年09月22日 13:12:34 | corona10 | set | nosy:
+ corona10 messages: + msg402431 |
| 2021年09月20日 14:11:16 | eric.snow | set | messages: + msg402232 |
| 2021年09月20日 06:55:56 | rhettinger | set | status: pending -> open nosy: + rhettinger messages: + msg402198 |
| 2021年09月15日 17:44:16 | eric.snow | set | status: open -> pending messages: + msg401864 |
| 2021年09月15日 17:42:12 | eric.snow | create | |