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-131798: JIT: Narrow the return type of `_BINARY_OP_SUBSCR_STR_INT` to `str` by tomasr8 · Pull Request #132153 · python/cpython

Conversation

@tomasr8

@tomasr8 tomasr8 commented Apr 6, 2025 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

I tested this by finding another instruction which contains a unicode guard, in this case BINARY_OP_ADD_UNICODE and checking that the guard is removed if one of the operands is the result of _BINARY_OP_SUBSCR_STR_INT. Let me know if there's a better way to test this!

I also noticed that some other uops like _BINARY_OP_ADD_UNICODE check if the operands are constants. Should we add it here as well? I don't know if we gain much from that though, code like 'foo'[0] is not very common.

  • Issue: Better uop coverage in the JIT optimizer #131798

Sorry, something went wrong.

Uh oh!

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

All reactions
tomasr8 added 2 commits April 6, 2025 13:15
@tomasr8
Narrow the return type of _BINARY_OP_SUBSCR_STR_INT
f7cddcc
@tomasr8
Add news entry
b821b8b
@tomasr8
tomasr8 requested a review from Fidget-Spinner as a code owner April 6, 2025 11:28
@bedevere-app bedevere-app Bot added the awaiting review label Apr 6, 2025
@bedevere-app bedevere-app Bot mentioned this pull request Apr 6, 2025
Better uop coverage in the JIT optimizer #131798
Open
@Fidget-Spinner

Fidget-Spinner commented Apr 6, 2025

Copy link
Copy Markdown
Member

I also noticed that some other uops like _BINARY_OP_ADD_UNICODE check if the operands are constants. Should we add it here as well? I don't know if we gain much from that though, code like 'foo'[0] is not very common.

The constant checking is sort of a relic. We don't even do anything with it. So it's fine to leave it out for now.

tomasr8 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

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

Fidget-Spinner
Fidget-Spinner approved these changes Apr 6, 2025
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Apr 6, 2025
@python-cla-bot

python-cla-bot Bot commented Apr 6, 2025

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

All reactions

Sorry, something went wrong.

Uh oh!

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

@tomasr8
tomasr8 requested a review from brandtbucher April 6, 2025 17:26
@brandtbucher

brandtbucher commented Apr 8, 2025 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member

I don't know if we gain much from that though, code like 'foo'[0] is not very common.

Just a quick note on this: "constant" here means anything the JIT knows to be a constant value at runtime, not just things that are statically constant in the source. So it could be something like MODULE_GLOBAL[len(foo) - 1], for instance.

The constant checking is sort of a relic. We don't even do anything with it.

I disagree, constant symbols are pretty powerful, and we should be using them more. For example, knowing constant values currently allows us to entirely remove conditional branches, type version checks, etc. @savannahostrowski also added the new _POP_TWO_LOAD_CONST_INLINE_BORROW instruction (and is in the process of using it in the remaining _BINARY_OP_* and _COMPARE_OP_* uops, which allows us to remove these operations entirely when the result is immortal).

I agree that it's probably not worth adding to this uop specifically (at least not without some examples of real-world code it would optimize), but I do think that tracking constant values in general is a good thing.

All reactions

Sorry, something went wrong.

Uh oh!

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

brandtbucher
brandtbucher approved these changes Apr 8, 2025
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.

Looks good. Want to tidy up the test before I merge?

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Lib/test/test_capi/test_opt.py Resolved

Uh oh!

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

@brandtbucher brandtbucher self-assigned this Apr 8, 2025
@brandtbucher brandtbucher added performance Performance or resource usage interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-JIT labels Apr 8, 2025
@tomasr8 @brandtbucher
Improve test
f6eb00c
Co-authored-by: Brandt Bucher <[email protected]>
@tomasr8

tomasr8 commented Apr 8, 2025

Copy link
Copy Markdown
Member Author

Thanks for the clarification about the meaning of constants in the JIT! That's an important distinction to make for sure.

All reactions

Sorry, something went wrong.

Uh oh!

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

@brandtbucher
brandtbucher merged commit 71009cb into python:main Apr 8, 2025
@bedevere-app bedevere-app Bot removed the awaiting merge label Apr 8, 2025
@tomasr8
tomasr8 deleted the jit-narrow-binary-subscr branch April 8, 2025 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@Fidget-Spinner Fidget-Spinner Fidget-Spinner approved these changes
@brandtbucher brandtbucher brandtbucher approved these changes

Uh oh!

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

Assignees

@brandtbucher brandtbucher

Labels

interpreter-core (Objects, Python, Grammar, and Parser dirs) performance Performance or resource usage topic-JIT

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.

3 participants

@tomasr8 @Fidget-Spinner @brandtbucher
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.