-
-
Notifications
You must be signed in to change notification settings - Fork 31.5k
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Replace _Py_IDENTIFIER() with statically initialized objects. #90699
Comments
This would involve the following:
As part of this, we would also do the following:
(Note that there are several hundred uses of Pros:
Cons:
Note that with a basic partial implementation (GH-30928) I'm seeing a 1% improvement in performance (see faster-cpython/ideas#230). |
## Background ##
The solution involved using a static variable defined, using Over the last decade a number of changes were made, including recent changes to make the identifiers per-interpreter and to use a centralized cache. [1] afe55bb |
This change is going to break projects in the wild. Yes, people use the _Py_IDENTIFIER(), _PyUnicode_FromId() and other "Id" variant of many functions in 3rd party projects. Is it possible to keep runtime initialization if this API is used by 3rd party code? |
If necessary, we can keep _Py_IDENTIFIER() (and the functions). Regardless, we can stop using it internally. |
FYI, I've posted to python-dev for feedback before proceeding: https://mail.python.org/archives/list/python-dev@python.org/thread/DNMZAMB4M6RVR76RDZMUK2WRLI6KAAYS/ |
Sorry if off topic, but I noticed that CPython doesn't deprecate macros in code, while with gcc/clang it's possible to show compiler warnings for them using some pragma magic: $ gcc a.c
a.c: In function 'main':
a.c:29:13: warning: Deprecated pre-processor symbol
29 | PySomethingDeprecated (0);
| ^~~~~~~~~~~~~~~~~~
a.c:30:13: warning: Deprecated pre-processor symbol: replace with "SomethingCompletelyDifferent"
30 | PySomethingDeprecated2 (42);
| ^~~~~~~~~~~~~~~~~~~~ Here is how glib implements this for example: https://gist.github.com/lazka/4749c74249a3918a059d944040aca4a3 Maybe that makes getting rid of them easier in the long run? |
On Fri, Feb 11, 2022 at 1:36 AM Christoph Reiter <report@bugs.python.org> wrote:
That's a good question. We do have Py_DEPRECATED() (in FWIW, here are other explanations of how to deprecate macros: |
With core code sorted out, stdlib and 3rd party extension modules are left to sort out. I see the following possibilities:
|
(from #31376 (comment)) [corona10]
I think it's fine to use the one issue. There are only 26 modules with |
Great! and thank you for all your efforts :) |
ctypes and datetime are similar cases which already use internal C API so I'll change it to use |
I'm okay with that, though ideally we would use public API as much as possible and limit |
practicality beats purity :) We can of course reconsider this when these modules will be ported to multiphase heap types. |
PR #99067 removes the remaining. |
FYI, once #99067 is merged, I'll disable using |
We will address Programs/_testembed.c in the issue/PR where we remove |
Thanks for doing all that work, @kumaraditya303! |
We can close this once gh-99210 lands. |
This side of things is done. We can create a new issue about maybe getting rid of |
Thanks to everyone! @ericsnowcurrently: It would be nice to update the c analyzer tool as a lot of globals are removed as part of this. |
Interned strings were added in pythonGH-99012
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
_Py_IDENTIFIER
usage from_json
module #98956_Py_IDENTIFIER
usage from_curses
module #98957_Py_IDENTIFIER
usage from_asyncio
module #99010_Py_IDENTIFIER
usage from_elementtree
module #99012_Py_IDENTIFIER
usage from_ctypes
#99054_Py_IDENTIFIER
stdlib usage #99067_Py_IDENTIFIER
in core code #99210_testcapimodule.c
#99236The text was updated successfully, but these errors were encountered: