GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GH-104584: Optimizer API by markshannon · Pull Request #105100 · python/cpython

Conversation

@markshannon

@markshannon markshannon commented May 30, 2023 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

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.

  • Issue: Pluggable optimizer API #104584

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
markshannon added 15 commits May 22, 2023 10:54
@markshannon
Optimizer API. Work in progress.
099d919
@markshannon
Add plugin optimizer API.
c991ccb
@markshannon
Executors are responsible for checking the eval breaker.
c342f26
@markshannon
Rename optimize.c to optimizer.c
e2d74f3
@markshannon
Let the optimizer choose the thresholds
6dcd1d5
@markshannon
Tidy up
4b145a8
@markshannon
Make VM responsible for linking in executors. Add test.
df91062
@markshannon
Remove dead code
96715b3
@markshannon
Completely turn off optimization when clearing interpreter.
8801b57
@markshannon
Remove unused function declaration.
5b89fb5
@markshannon
Add news
4b70ee7
@markshannon
Address code review.
1e9822b
@markshannon
More precise type for C Api function.
037a2bc
@markshannon
Merge branch 'main' into optimizer-api
736f7f0
@markshannon
Add static symbols to list.
977800e
@markshannon
markshannon requested review from a team, brettcannon, encukou, ericsnowcurrently, ncoghlan and warsaw as code owners May 30, 2023 16:17
@bedevere-bot bedevere-bot added the awaiting core review label May 30, 2023
@bedevere-bot bedevere-bot mentioned this pull request May 30, 2023
Pluggable optimizer API #104584
Closed
@markshannon
markshannon requested review from brandtbucher and removed request for a team, brettcannon, encukou, ericsnowcurrently, ncoghlan and warsaw May 30, 2023 16:26
@markshannon
markshannon requested a review from Fidget-Spinner May 30, 2023 16:26
Fidget-Spinner
Fidget-Spinner reviewed May 30, 2023
View reviewed changes

@Fidget-Spinner Fidget-Spinner left a comment

Copy link
Copy Markdown
Member

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.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Python/optimizer.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/optimizer.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/optimizer.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/optimizer.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/optimizer.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/optimizer.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Eclips4
Eclips4 reviewed May 30, 2023
View reviewed changes
Comment thread Python/optimizer.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

brandtbucher
brandtbucher reviewed Jun 1, 2023
View reviewed changes

@brandtbucher brandtbucher left a comment

Copy link
Copy Markdown
Member

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:

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Lib/opcode.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Include/cpython/code.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Include/cpython/code.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/ceval_macros.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/bytecodes.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/optimizer.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/optimizer.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/optimizer.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/optimizer.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/optimizer.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

zooba
zooba reviewed Jun 1, 2023
View reviewed changes
Comment thread Include/internal/pycore_interp.h Resolved

Uh oh!

There was an error while loading. Please reload this page.

markshannon added 2 commits June 1, 2023 13:55
@markshannon
Address review comments.
2eeebba
@markshannon
Merge branch 'main' into optimizer-api
30d79a6
carljm
carljm reviewed Jun 1, 2023
View reviewed changes
Comment thread Misc/NEWS.d/next/C API/2023-05-25-15-44-48.gh-issue-104584.cSAoRh.rst Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/bytecodes.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/optimizer.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/optimizer.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread Python/bytecodes.c
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);

@carljm carljm Jun 1, 2023

Copy link
Copy Markdown
Member

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?

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread Python/optimizer.c Resolved

Uh oh!

There was an error while loading. Please reload this page.

@markshannon
Address review comments.
faff8a5
@markshannon
markshannon merged commit 4bfa01b into python:main Jun 2, 2023
@bedevere-bot bedevere-bot removed the awaiting core review label Jun 2, 2023
@Eclips4 Eclips4 mentioned this pull request Jun 3, 2023
test_capi fails if run with --forever argument #105273
Closed
@markshannon
markshannon deleted the optimizer-api branch September 26, 2023 12:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@carljm carljm carljm left review comments
@zooba zooba zooba left review comments
@Fidget-Spinner Fidget-Spinner Fidget-Spinner left review comments
@brandtbucher brandtbucher brandtbucher left review comments
@Eclips4 Eclips4 Eclips4 left review comments

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

7 participants

@markshannon @carljm @zooba @Fidget-Spinner @brandtbucher @Eclips4 @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.