Skip to content
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

Merged
merged 18 commits into from
Jun 2, 2023
Merged

GH-104584: Optimizer API #105100

merged 18 commits into from
Jun 2, 2023

Conversation

markshannon
Copy link
Member

@markshannon markshannon commented May 30, 2023

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.

Copy link
Member

@Fidget-Spinner Fidget-Spinner left a 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.

Python/optimizer.c Outdated Show resolved Hide resolved
Python/optimizer.c Outdated Show resolved Hide resolved
Python/optimizer.c Outdated Show resolved Hide resolved
Python/optimizer.c Outdated Show resolved Hide resolved
Python/optimizer.c Outdated Show resolved Hide resolved
Python/optimizer.c Outdated Show resolved Hide resolved
Python/optimizer.c Outdated Show resolved Hide resolved
Copy link
Member

@brandtbucher brandtbucher left a 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:

Lib/opcode.py Show resolved Hide resolved
Include/cpython/code.h Outdated Show resolved Hide resolved
Include/cpython/code.h Outdated Show resolved Hide resolved
Python/ceval_macros.h Show resolved Hide resolved
Python/bytecodes.c Show resolved Hide resolved
Python/optimizer.c Show resolved Hide resolved
Python/optimizer.c Outdated Show resolved Hide resolved
Python/optimizer.c Outdated Show resolved Hide resolved
Python/optimizer.c Outdated Show resolved Hide resolved
Python/optimizer.c Outdated Show resolved Hide resolved
Python/bytecodes.c Show resolved Hide resolved
Python/optimizer.c Show resolved Hide resolved
Python/optimizer.c Outdated Show resolved Hide resolved
Comment on lines +2121 to +2129
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);
Copy link
Member

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?

Python/optimizer.c Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants