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-146381: Constant-fold frozendict subscript lookups via REPLACE_OPCODE_IF_EVALUATES_PURE by corona10 · Pull Request #146490 · python/cpython

Conversation

@corona10

@corona10 corona10 commented Mar 26, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Member
  • Issue: Fold _BINARY_OP_SUBSCR_DICT for promoted frozendict constants #146381

Sorry, something went wrong.

Uh oh!

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

All reactions
corona10 added 2 commits March 27, 2026 05:31
@corona10
pythongh-146381: Fold frozendict subscript via _BINARY_OP_SUBSCR_FROZ…
098ac8b
…EN_DICT
@corona10
nit
91ce6fd
@corona10
corona10 requested review from Fidget-Spinner, markshannon, savannahostrowski and tomasr8 as code owners March 26, 2026 20:32
@bedevere-app bedevere-app Bot mentioned this pull request Mar 26, 2026
Fold _BINARY_OP_SUBSCR_DICT for promoted frozendict constants #146381
Closed
@bedevere-app bedevere-app Bot added the awaiting core review label Mar 26, 2026
@corona10
nit
b4d3d49
@corona10 corona10 added the skip news label Mar 26, 2026
@corona10

corona10 commented Mar 26, 2026

Copy link
Copy Markdown
Member Author

@Fidget-Spinner
I added _BINARY_OP_SUBSCR_FROZEN_DICT as a lowered uop for frozendict lookups. When the optimizer sees _BINARY_OP_SUBSCR_DICT with a frozendict operand, it replaces it with _BINARY_OP_SUBSCR_FROZEN_DICT, then folds the result to a constant via sym_frozendict_getitem if both dict and key are known constants.

All reactions

Sorry, something went wrong.

Uh oh!

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

@corona10

corona10 commented Mar 26, 2026

Copy link
Copy Markdown
Member Author

main

['_START_EXECUTOR', '_MAKE_WARM', '_SET_IP', '_CHECK_PERIODIC', '_CHECK_VALIDITY', '_ITER_CHECK_RANGE', '_GUARD_NOT_EXHAUSTED_RANGE', '_ITER_NEXT_RANGE', '_SET_IP', '_SWAP_FAST_2', '_SPILL_OR_RELOAD', '_POP_TOP', '_CHECK_VALIDITY', '_GUARD_GLOBALS_VERSION', '_LOAD_CONST_INLINE', '_LOAD_CONST_INLINE_BORROW', '_SET_IP', '_BINARY_OP_SUBSCR_DICT', '_POP_TOP_NOP', '_SPILL_OR_RELOAD', '_POP_TOP', '_CHECK_VALIDITY', '_LOAD_CONST_INLINE_BORROW', '_GUARD_NOS_INT', '_COMPARE_OP_INT', '_POP_TOP_NOP', '_POP_TOP_INT', '_GUARD_BIT_IS_SET_POP_5', '_LOAD_FAST_BORROW_1', '_LOAD_CONST_INLINE_BORROW', '_GUARD_NOS_INT', '_BINARY_OP_ADD_INT', '_POP_TOP_NOP', '_POP_TOP_NOP', '_SWAP_FAST_1', '_POP_TOP_INT', '_JUMP_TO_TOP', '_DEOPT', '_ERROR_POP_N', '_DEOPT', '_EXIT_TRACE', '_EXIT_TRACE', '_ERROR_POP_N', '_DEOPT', '_ERROR_POP_N', '_DEOPT', '_EXIT_TRACE', '_EXIT_TRACE', '_EXIT_TRACE']

PR

['_START_EXECUTOR', '_MAKE_WARM', '_SET_IP', '_CHECK_PERIODIC', '_CHECK_VALIDITY', '_ITER_CHECK_RANGE', '_GUARD_NOT_EXHAUSTED_RANGE', '_ITER_NEXT_RANGE', '_SET_IP', '_SWAP_FAST_2', '_SPILL_OR_RELOAD', '_POP_TOP', '_CHECK_VALIDITY', '_GUARD_GLOBALS_VERSION', '_LOAD_CONST_INLINE', '_LOAD_CONST_INLINE_BORROW', '_SET_IP', '_BINARY_OP_SUBSCR_FROZEN_DICT', '_POP_TOP_NOP', '_SPILL_OR_RELOAD', '_POP_TOP', '_CHECK_VALIDITY', '_LOAD_CONST_INLINE_BORROW', '_INSERT_2_LOAD_CONST_INLINE_BORROW', '_POP_TOP_NOP', '_POP_TOP_INT', '_SET_IP', '_POP_TOP', '_CHECK_VALIDITY', '_LOAD_FAST_BORROW_1', '_LOAD_CONST_INLINE_BORROW', '_GUARD_NOS_INT', '_BINARY_OP_ADD_INT', '_POP_TOP_NOP', '_POP_TOP_NOP', '_SWAP_FAST_1', '_POP_TOP_INT', '_JUMP_TO_TOP', '_DEOPT', '_ERROR_POP_N', '_DEOPT', '_EXIT_TRACE', '_EXIT_TRACE', '_ERROR_POP_N', '_DEOPT', '_ERROR_POP_N', '_DEOPT', '_DEOPT', '_EXIT_TRACE']

All reactions

Sorry, something went wrong.

Uh oh!

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

Fidget-Spinner
Fidget-Spinner reviewed Mar 27, 2026
View reviewed changes
Comment thread Include/internal/pycore_optimizer.h Outdated
extern PyTypeObject *_Py_uop_sym_get_type(JitOptRef sym);
extern JitOptRef _Py_uop_sym_new_tuple(JitOptContext *ctx, int size, JitOptRef *args);
extern JitOptRef _Py_uop_sym_tuple_getitem(JitOptContext *ctx, JitOptRef sym, Py_ssize_t item);
extern JitOptRef _Py_uop_sym_frozendict_getitem(JitOptContext *ctx, JitOptRef sym, JitOptRef key);

@Fidget-Spinner Fidget-Spinner Mar 27, 2026

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 don't think we need this function.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Python/optimizer_symbols.c Outdated
return _Py_uop_sym_new_not_null(ctx);
}

JitOptRef

@Fidget-Spinner Fidget-Spinner Mar 27, 2026

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.

Same here, we don't need this function.

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Python/optimizer_bytecodes.c Outdated
Comment on lines +490 to +491
REPLACE_OP(this_instr, _BINARY_OP_SUBSCR_FROZEN_DICT, oparg, 0);
res = sym_frozendict_getitem(ctx, dict_st, sub_st);

@Fidget-Spinner Fidget-Spinner Mar 27, 2026 •
edited
Loading

Uh oh!

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

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.

Suggested change
REPLACE_OP(this_instr, _BINARY_OP_SUBSCR_FROZEN_DICT, oparg, 0);
res = sym_frozendict_getitem(ctx, dict_st, sub_st);
REPLACE_OPCODE_IF_EVALUATES_PURE(dict_st, sub_st, res);

Check out what is the generated code in executor_cases.c.h after this :).

Sorry, something went wrong.

Uh oh!

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

All reactions
Comment thread Python/optimizer_bytecodes.c Outdated
Comment on lines 495 to 500
op(_BINARY_OP_SUBSCR_FROZEN_DICT, (dict_st, sub_st -- res, ds, ss)) {
res = sym_new_not_null(ctx);
ds = dict_st;
ss = sub_st;
REPLACE_OPCODE_IF_EVALUATES_PURE(dict_st, sub_st, res);
}

@Fidget-Spinner Fidget-Spinner Mar 27, 2026

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.

This can be removed.

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 Outdated
self.assertEqual(res, TIER2_THRESHOLD)
self.assertIsNotNone(ex)
uops = get_opnames(ex)
self.assertIn("_BINARY_OP_SUBSCR_FROZEN_DICT", uops)

@Fidget-Spinner Fidget-Spinner Mar 27, 2026 •
edited
Loading

Uh oh!

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

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.

After the correct replacement, this should just become POP_TOP_LOAD_CONST...

Sorry, something went wrong.

Uh oh!

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

corona10 reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@corona10
Address code review
484fc7b
@corona10

corona10 commented Mar 27, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Member Author

@Fidget-Spinner
I've addressed your code review.
uops are optimized very well! Awesome :)

['_START_EXECUTOR', '_MAKE_WARM', '_SET_IP', '_CHECK_PERIODIC', '_CHECK_VALIDITY', '_ITER_CHECK_RANGE', '_GUARD_NOT_EXHAUSTED_RANGE', '_ITER_NEXT_RANGE', '_SET_IP', '_SWAP_FAST_2', '_SPILL_OR_RELOAD', '_POP_TOP', '_CHECK_VALIDITY', '_GUARD_GLOBALS_VERSION', '_LOAD_CONST_INLINE', '_LOAD_CONST_INLINE_BORROW', '_SET_IP', '_INSERT_2_LOAD_CONST_INLINE_BORROW', '_POP_TOP_NOP', '_SPILL_OR_RELOAD', '_POP_TOP', '_CHECK_VALIDITY', '_LOAD_CONST_INLINE_BORROW', '_INSERT_2_LOAD_CONST_INLINE_BORROW', '_POP_TOP_NOP', '_POP_TOP_INT', '_SET_IP', '_POP_TOP', '_CHECK_VALIDITY', '_LOAD_FAST_BORROW_1', '_LOAD_CONST_INLINE_BORROW', '_GUARD_NOS_INT', '_BINARY_OP_ADD_INT', '_POP_TOP_NOP', '_POP_TOP_NOP', '_SWAP_FAST_1', '_POP_TOP_INT', '_JUMP_TO_TOP', '_DEOPT', '_ERROR_POP_N', '_DEOPT', '_EXIT_TRACE', '_EXIT_TRACE', '_ERROR_POP_N', '_DEOPT', '_DEOPT', '_DEOPT', '_EXIT_TRACE']

Fidget-Spinner 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.

@corona10 corona10 changed the title gh-146381: Fold frozendict subscript via _BINARY_OP_SUBSCR_FROZEN_DICT gh-146381: Constant-fold frozendict subscript lookups via REPLACE_OPCODE_IF_EVALUATES_PURE Mar 27, 2026
@corona10
corona10 requested a review from Fidget-Spinner March 27, 2026 16:26
Fidget-Spinner
Fidget-Spinner approved these changes Mar 27, 2026
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.

The power of the JIT optimizer :).

Sorry, something went wrong.

Uh oh!

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

All reactions
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting core review labels Mar 27, 2026
@corona10
corona10 merged commit 5992238 into python:main Mar 28, 2026
71 checks passed

Uh oh!

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

@bedevere-app bedevere-app Bot removed the awaiting merge label Mar 28, 2026
@corona10
corona10 deleted the gh-146381-jit branch March 28, 2026 00:49
@bedevere-bot

bedevere-bot commented Mar 28, 2026

Copy link
Copy Markdown

⚠️⚠️⚠️ Buildbot failure ⚠️⚠️⚠️

Hi! The buildbot AMD64 Windows PGO NoGIL Tailcall 3.x (tier-1) has failed when building commit 5992238.

What do you need to do:

  1. Don't panic.
  2. Check the buildbot page in the devguide if you don't know what the buildbots are or how they work.
  3. Go to the page of the buildbot that failed (https://buildbot.python.org/#/builders/1871/builds/270) and take a look at the build logs.
  4. Check if the failure is related to this commit (5992238) or if it is a false positive.
  5. If the failure is related to this commit, please, reflect that on the issue and make a new Pull Request with a fix.

You can take a look at the buildbot page here:

https://buildbot.python.org/#/builders/1871/builds/270

Failed tests:

  • test_profiling

Summary of the results of the build (if available):

==

Click to see traceback logs
Traceback (most recent call last):
  File "C:\bbarea\3.x.itamaro-win64-srv-22-aws.nogil.tailcall.pgo\build\Lib\test\test_profiling\test_sampling_profiler\test_advanced.py", line 169, in test_native_frames_enabled
    self.assertFalse(any(stack.endswith(";<native>") for stack in stacks))
    ~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError: True is not false
All reactions

Sorry, something went wrong.

Uh oh!

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

@corona10 corona10 mentioned this pull request Mar 28, 2026
gh-146381: Constant fold local frozendict subscript lookups via recording #146564
Closed
@pablogsal pablogsal mentioned this pull request Apr 4, 2026
gh-130273: Fix traceback color output with unicode characters #142529
Merged
clin1234 pushed a commit to clin1234/cpython that referenced this pull request Apr 16, 2026
@corona10 @clin1234
pythongh-146381: Constant-fold frozendict subscript lookups via REPLA…
708b5dd
…CE_OPCODE_IF_EVALUATES_PURE (pythongh-146490)
ljfp pushed a commit to ljfp/cpython that referenced this pull request Apr 25, 2026
@corona10 @ljfp
pythongh-146381: Constant-fold frozendict subscript lookups via REPLA…
9f6238c
…CE_OPCODE_IF_EVALUATES_PURE (pythongh-146490)
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
@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner
@tomasr8 tomasr8 Awaiting requested review from tomasr8 tomasr8 is a code owner
@savannahostrowski savannahostrowski Awaiting requested review from savannahostrowski

Uh oh!

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

Assignees

No one assigned

Labels

skip news

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

@corona10 @bedevere-bot @Fidget-Spinner
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.