FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-131798: JIT: Narrow the return type of `_BINARY_OP_SUBSCR_STR_INT` to `str` by tomasr8 · Pull Request #132153 · python/cpython · GitHub

Repository navigation

gh-131798: JIT: Narrow the return type of _BINARY_OP_SUBSCR_STR_INT to str - #132153

Merged
brandtbucher merged 3 commits into
python:mainfrom
tomasr8:jit-narrow-binary-subscr
Apr 8, 2025
Merged

brandtbucher merged 3 commits into
python:mainfrom
tomasr8:jit-narrow-binary-subscr

Conversation

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

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.

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.

python-cla-bot Bot commented Apr 6, 2025

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

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

brandtbucher commented Apr 8, 2025 •
edited
Loading

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.

brandtbucher left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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

Comment thread Lib/test/test_capi/test_opt.py Outdated
brandtbucher self-assigned this Apr 8, 2025
brandtbucher added performance Performance or resource usage interpreter-core (Objects, Python, Grammar, and Parser dirs) topic-JIT labels Apr 8, 2025
Co-authored-by: Brandt Bucher <brandtbucher@gmail.com>

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.

brandtbucher merged commit 71009cb into python:main Apr 8, 2025
tomasr8 deleted the jit-narrow-binary-subscr branch April 8, 2025 15:50
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants


Back | FazBrowse Home | New Git URL