-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
gh-116772: Cache getenv
result in optimizer.c
to reduce calls
#126439
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Python/optimizer.c
Outdated
static int uop_optimize_initialized = 0; | ||
static int uop_optimize_flag = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't thread safe or subinterpreter safe. You might want to store the value in a PyThreadState
/ PyInterpreterState
in pylifecycle.c
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I gave it a try, but it didn’t work out in the end. I guess I don’t have enough experience yet. I'm really sorry, I might not be able to handle this on my own. Maybe someone else could take it, or maybe you could help improve what I have so far :(
@mdboom did you have a change planned for this? |
No, I don't have a plan. Thanks to @Wulian233 for taking this on. |
initialize_uops_optimize_flag(void) { | ||
if (!uops_optimize_initialized) { | ||
PyInterpreterState *interp = _PyInterpreterState_GET(); | ||
char *env_var = Py_GETENV("PYTHON_UOPS_OPTIMIZE"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you please do this instead at where we check for PYTHON_JIT
? So in pylifecycle.c
.
Set the thread state/interp state there as well.
This is my first time PR for part C, which looks like it might be a small improvement, hopefully I'm not doing anything wrong🙂
About 0.5% faster? (from issue)
getenv
on every optimization run #116772