Skip to content

Fix memory leak in overload resolution#3089

Draft
samschlegel wants to merge 1 commit intofacebook:mainfrom
samschlegel:fix-overload-memory-leak
Draft

Fix memory leak in overload resolution#3089
samschlegel wants to merge 1 commit intofacebook:mainfrom
samschlegel:fix-overload-memory-leak

Conversation

@samschlegel
Copy link
Copy Markdown

@samschlegel samschlegel commented Apr 9, 2026

Summary

Replace fresh partial variable allocation with snapshot/restore during overload evaluation.

The freshen_partial_vars approach created new solver variables for every overload candidate. I think these accumulated in the solver's variable map and were never freed, causing unbounded memory growth in certain codebases (e.g. 90MB -> 49GB on a play_scraper repro.) This isn't reproducible on numpy or other large projects, so the specific trigger is unclear.

Instead, snapshot partial var state before evaluating overloads and restore after each attempt. This prevents losing overloads from pinning partial vars without allocating new variables.

Fixes #3088

Test Plan [WIP]

  • Run cargo tests
  • Run test.py
  • Understand underlying cause
  • Minimize repro example
  • Get a failing test working

@meta-cla
Copy link
Copy Markdown

meta-cla bot commented Apr 9, 2026

Hi @samschlegel!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@github-actions github-actions bot added the size/s label Apr 9, 2026
Summary:
Replace fresh partial variable allocation with snapshot/restore during
overload evaluation.

The freshen_partial_vars approach created new solver variables for every
overload candidate. These accumulated in the solver's variable map and
were never freed, causing unbounded memory growth in certain codebases
(e.g. 90MB -> 49GB on a play_scraper repro, though not reproducible on
numpy or other large projects — the specific trigger is unclear).

Instead, snapshot partial var state before evaluating overloads and
restore after each attempt. This prevents losing overloads from pinning
partial vars without allocating new variables.
@samschlegel samschlegel force-pushed the fix-overload-memory-leak branch from 3506e8f to b623698 Compare April 10, 2026 00:24
@github-actions github-actions bot added size/s and removed size/s labels Apr 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory leak/possible non-termination since ce9397372

1 participant