Skip to content

internal: schedule buffer to release later instead of leaking - #6344

Closed
Person-93 wants to merge 3 commits into
PyO3:mainfrom
Person-93:fix-leak-pybuffer
Closed

internal: schedule buffer to release later instead of leaking#6344
Person-93 wants to merge 3 commits into
PyO3:mainfrom
Person-93:fix-leak-pybuffer

Conversation

@Person-93

Copy link
Copy Markdown
Contributor

If a buffer is dropped during gc traversal, use Py_AddPendingCall to release it later instead of leaking it.

Hopefully this can also unblock #6261.

@codspeed-hq

codspeed-hq Bot commented Aug 22, 2026

Copy link
Copy Markdown

Merging this PR will improve performance by 17.61%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 3 improved benchmarks
✅ 138 untouched benchmarks
⏩ 6 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation extract_i128_small_pos 2.6 µs 2.2 µs +18.16%
Simulation extract_i128_zero 2.6 µs 2.2 µs +17.63%
Simulation extract_i128_small_neg 2.7 µs 2.3 µs +17.04%

Tip

Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.


Comparing Person-93:fix-leak-pybuffer (b409b76) with main (34f08c3)

Open in CodSpeed

Footnotes

  1. 6 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

@davidhewitt davidhewitt 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.

Crafty solution! I'm a little wary about Py_AddPendingCall being safe to call from within GC traverse, I think it should be possible to write a test so we can verify.

I would also be quite happy with getting #6330 done and ultimately declaring GC traversal functions unsafe to implement and completely throw away any check from this Drop impl.

@Person-93

Copy link
Copy Markdown
Contributor Author

I'm a little wary about Py_AddPendingCall being safe to call from within GC traverse

I think you're right about this.

@Person-93 Person-93 closed this Aug 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants