Skip to content

fix(cli): return native allocator memory within 10 ms by default - #890

Merged
kvlonge merged 2 commits into
mainfrom
fix/mimalloc-purge-delay
Sep 30, 2026
Merged

kvlonge merged 2 commits into
mainfrom
fix/mimalloc-purge-delay

Conversation

@kvlonge

@kvlonge kvlonge commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Why

The mimalloc allocator from #889 (v3) keeps freed memory for up to 1,000 ms before returning it to the OS. On the 3,000-model inspection benchmark, sqb plan --json peak memory rose from about 890 MB to about 1,160 MB (1.26x) in every run. That exceeds the 1.25x release comparison limit and blocks the next release.

Changes

  • The CLI console-script entry point sets MIMALLOC_PURGE_DELAY=10 (mimalloc v2's default) before it imports the CLI, which loads the native extension. A value already set by the user is kept (os.environ.setdefault).
  • The Rust side cannot set the option because the workspace forbids unsafe, and the root package may not run code at import time.

Measured on main, plan peak RSS / compile --no-cache wall time:

  • 1,000 ms (current default): 1,094-1,165 MB / 8.0-8.1 s
  • 10 ms (this change): 950-1,017 MB / 8.2-8.4 s
  • 0 ms: ~906 MB / ~8.8 s
  • 0.126.5 (before mimalloc): 887-950 MB / ~10 s

Verification

  • New fresh-process integration test: importing the entry module does not load sqlbuild._native; running it sets the 10 ms default when unset and preserves a user value. Both cases fail without the fix.
  • make check-ci passes.
  • The release PR's performance comparison re-runs after merge.

@kvlonge
kvlonge enabled auto-merge (squash) September 30, 2026 19:48
@kvlonge
kvlonge merged commit e60652b into main Sep 30, 2026
21 checks passed
@kvlonge
kvlonge deleted the fix/mimalloc-purge-delay branch September 30, 2026 20:03
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.

1 participant