GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||
GeezerVison is showing github.com — gh-100227: Move the Dict of Interned Strings to PyInterpreterState by ericsnowcurrently · Pull Request #102339 · python/cpython Conversation
|
|
When you're done making the requested changes, leave the comment: |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Thanks for the feedback. I want to be sure we're in agreement before I proceed on this.
Are you talking about process-global or something else? Process-global is problematic for interpreter isolation, especially under a per-interpreter GIL. Non-immortal str objects must not be shared between interpreters, which means many strings that are currently interned must either be made immortal or not be interned. Making the interned dict per-interpreter solves this.
All immortal strings are still interned in each interpreter. However, non-immortal string instances are necessarily unique to a single interpreter and consequently interning them to just that interpreter is still correct. The trade-off here is that we incur an extra CPU cost to startup for subinterpreters (due to the static strings) and an extra memory/CPU cost when the same (non-static) string is interned in additional interpreters. I expect there is a more efficient way to solve this, but that doesn't mean we can't go with a less efficient approach (as I've proposed) in the meantime. Note that, most importantly, there is no impact to the status quo for the main interpreter in either case. That matters since the vast majority of Python usage does not involve subinterpreters currently.
Such a lock must also guard reads since they might race with mutation. That leads to a larger performance impact. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I'll see it by next weekend. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
BTW, benchmarks show no significant change in performance. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Hmm, I am thinking of the opposite, make it mandatory that all interned strings are immortal. If we guarantee this then we don't need to make it per interpreter, the main interpreter will clear the interned table at runtime finalization. This has other benefits that it fits out current mental model that an interned string is a process wide global unique string and shared across interpreter as it is currently done.
Yeah, all of this is for subinterpreters. This is how with immortal objects, I think this should happen:
To me this seems much simpler to understand and implement. I feel we should table this for now until immortal objects are implemented in main branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
I see what you're saying. Furthermore, this wouldn't be so big a deal since you can't [normally] intern a string directly from Python code, so it isn't a huge number of strings that get interned. I'll let this stew in my brain for a day or two and get back to this. Thanks for explaining! |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
This does mean that, under a per-interpreter GIL, we'd need a granular global for any use of the interned dict, but that's okay. It also means that we'd have to ensure resizing is done with the main interpreter's obmalloc state, but that is manageable. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
@kumaraditya303, does gh-102858 seem like what you had in mind? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I'm closing this in favor of gh-102925, which keeps the interned strings dict global. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…ted Interpreters (pythongh-102925)" This reverts commit 87be8d9.
|
The keep-it-global approach has turned out to be quite complex. We can look into that further, but in the meantime I'm planning on going with the simpler approach here. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…ate (pythongh-102339) We can revisit the options for keeping it global later, if desired. For now the approach seems quite complex, so we've gone with the simpler isolation solution in the meantime. python#100227
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.