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-144540: Eliminate `_MAKE_HEAP_FUNCTION` for owned references by Sacul0457 · Pull Request #146320 · python/cpython

Conversation

@Sacul0457

@Sacul0457 Sacul0457 commented Mar 23, 2026 •
edited by bedevere-app Bot
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

If the reference of the returned object is not borrowed, we remove the _MAKE_HEAP_FUNCTION. Hence I ended up changing the test_make_heap_safe_optimized_owned test to test that _MAKE_HEAP_FUNCTION is no longer in the trace as the value returned is not a borrowed reference.

Also, for a "return of a return", given the inner function returns a borrowed reference, the double _MAKE_HEAP_FUNCTION is reduced to just 1 :)

  44 OPTIMIZED: _MAKE_HEAP_SAFE_r11 (0, target=3, operand0=0, operand1=0)
  45 OPTIMIZED: _RETURN_VALUE_r11 (0, target=3, operand0=0, operand1=0)
  46 OPTIMIZED: _CHECK_VALIDITY_r11 (0, jump_target=71, operand0=0, operand1=0)
  47 OPTIMIZED: _SET_IP_r11 (0, target=10, operand0=0x1b5f9947d24, operand1=0)
  48 OPTIMIZED: _RETURN_VALUE_r11 (0, target=10, operand0=0, operand1=0)

I hope I didn't misunderstand the issue...

  • Issue: Optimize reference tracking and eliminate branching during returns and yields #144540

Sorry, something went wrong.

Uh oh!

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

All reactions
@Sacul0457
optimize _MAKE_HEAP_FUNCTION for owned references
d5e9fdb
@Sacul0457
Sacul0457 requested review from Fidget-Spinner, markshannon, savannahostrowski and tomasr8 as code owners March 23, 2026 07:48
@bedevere-app bedevere-app Bot mentioned this pull request Mar 23, 2026
Optimize reference tracking and eliminate branching during returns and yields #144540
Open
@bedevere-app bedevere-app Bot added the awaiting review label Mar 23, 2026
@cocolato

cocolato commented Mar 23, 2026

Copy link
Copy Markdown
Member

I think this might be a problem because in creation functions such as sym_new_not_null and sym_new_unknown, :

cpython/Python/optimizer_symbols.c

Lines 690 to 709 in fb8d8d9

JitOptRef
_Py_uop_sym_new_unknown(JitOptContext *ctx)
{
JitOptSymbol *res = sym_new(ctx);
if (res == NULL) {
return out_of_space_ref(ctx);
}
return PyJitRef_Wrap(res);
}
JitOptRef
_Py_uop_sym_new_not_null(JitOptContext *ctx)
{
JitOptSymbol *res = sym_new(ctx);
if (res == NULL) {
return out_of_space_ref(ctx);
}
res->tag = JIT_SYM_NON_NULL_TAG;
return PyJitRef_Wrap(res);
}

PyJitRef_Wrap produces a ref with tag = 0.
This means that tag = 0 is the default state, indicating “we have no specific information about borrowing/ownership,” rather than “definitely owned.” Only those explicitly marked with tag = 1 via PyJitRef_Borrow() are “known to be borrowed.”

All reactions

Sorry, something went wrong.

Uh oh!

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

@cocolato

cocolato commented Mar 23, 2026

Copy link
Copy Markdown
Member

Mark also reminded me in the last PR: #144414 (review).

All reactions

Sorry, something went wrong.

Uh oh!

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

@Fidget-Spinner

Fidget-Spinner commented Mar 23, 2026

Copy link
Copy Markdown
Member

Hmm Mark is indeed right. However, currently the only place that can generate borrowed references are LOAD_FAST_BORROW. I suspect we need to create a new tag bit for this to work.

We only support good perf on 64 bit systems right now. I propose we drop the 32 bit Windows support so that we have 3 tag bits to use and can support "unknown" references.

cocolato 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.

@cocolato

cocolato commented Mar 23, 2026

Copy link
Copy Markdown
Member

I propose we drop the 32 bit Windows support so that we have 3 tag bits to use and can support "unknown" references.

I also don’t think it’s necessary to maintain the performance of legacy systems

All reactions

Sorry, something went wrong.

Uh oh!

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

@Sacul0457

Sacul0457 commented Mar 23, 2026

Copy link
Copy Markdown
Contributor Author

I guess I'll mark this PR as draft for now until that is in?

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.

@Sacul0457
Sacul0457 marked this pull request as draft March 23, 2026 12:00
@bedevere-app bedevere-app Bot removed the awaiting review label Mar 23, 2026
@github-actions

github-actions Bot commented May 8, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

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

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@markshannon markshannon Awaiting requested review from markshannon markshannon is a code owner
@tomasr8 tomasr8 Awaiting requested review from tomasr8 tomasr8 is a code owner
@Fidget-Spinner Fidget-Spinner Awaiting requested review from Fidget-Spinner Fidget-Spinner 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

stale Stale PR or inactive for long period of time.

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

@Sacul0457 @cocolato @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.