-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
GH-104584: Optimizer API #105100
GH-104584: Optimizer API #105100
Conversation
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.
Looks good in general. Probably needs a test with buildbots though.
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.
Cool! Just a small flurry of questions, comments, and nits:
Misc/NEWS.d/next/C API/2023-05-25-15-44-48.gh-issue-104584.cSAoRh.rst
Outdated
Show resolved
Hide resolved
here[1].cache += (1 << OPTIMIZER_BITS_IN_COUNTER); | ||
if (here[1].cache > tstate->interp->optimizer_backedge_threshold) { | ||
OBJECT_STAT_INC(optimization_attempts); | ||
frame = _PyOptimizer_BackEdge(frame, here, next_instr, stack_pointer); | ||
if (frame == NULL) { | ||
frame = cframe.current_frame; | ||
goto error; | ||
} | ||
here[1].cache &= ((1 << OPTIMIZER_BITS_IN_COUNTER) -1); |
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'm a bit confused about how an optimizer would actually make use of these four bits. The optimizer only gets invoked when its threshold is met, and when the optimizer is invoked, it is required to return an executor (returning NULL
signals an exception). The executor will generally be per-hotspot, and can have as much custom state in it as the optimizer wants.
I guess the use case might be that sometimes an optimizer will choose to set a shared no-op executor for some reason (so if it's shared, it can't store per-hotspot state in it), but still want to store some per-hotspot state?
Only supports back edges. Adding hooks for resumption points (the
RESUME
instruction) is for a later PR.Performance for an earlier version was mostly noise.
In theory we could turn off the check by using adaptive bytecode, but as we will want an always-on optimizer for tier 2, there seems little advantage to doing so.