Skip to content

Return memory right after large parses instead of holding it - #567

Merged
AJenbo merged 1 commit into
PHPantom-dev:mainfrom
stubbedev:stabilize-parse-memory
Nov 12, 2026
Merged

AJenbo merged 1 commit into
PHPantom-dev:mainfrom
stubbedev:stabilize-parse-memory

Conversation

@stubbedev

@stubbedev stubbedev commented Nov 12, 2026 •

Copy link
Copy Markdown
Contributor

Checklist

If applicable:

  • I have updated CHANGELOG.md
  • I have updated the documentation (README.md, docs/, examples/)
  • I have updated the config schema (config-schema.json)
  • I have added/updated tests to cover my changes
  • If I used AI tools, I have reviewed what they produced and can explain
    the changes and why they are needed.
  • I have read through any AI-generated text, especially documentation,
    the changelog, and other user-facing content, and removed or corrected
    anything inaccurate, unclear, or unnecessary.

The memory benchmark for a WordPress plugin swung between about 75,
90 and 160 MiB from one run to the next, failing unrelated PRs. Two
things kept the memory of a large transient parse resident after the
work that needed it was done, and the benchmark sampled at a moment
that landed before or after they let go.

mimalloc keeps the pages a thread frees in that thread's own heap and
returns them only when the same thread next calls into the allocator.
The first hover in the scenario parses the 6 MB wordpress-stubs.php on
a blocking-pool thread, which then parks; its freed pages stayed
resident until Tokio reaped the idle thread ten seconds later. Every
blocking task now ends with mi_collect(false) on its own thread, which
costs around 10 µs per request.

The thread-local parse arena keeps its last chunk on reset, and blink
sizes each chunk to everything the arena held before it, so that one
parse left its thread holding a 24 MiB chunk until the thread exited.
Sources over 512 KiB now parse in a throwaway arena; the syscalls the
reuse saves are noise next to parsing a file that size.

With both, the scenario settles at 79-88 MiB at the benchmark's sample
point and stays there, where before it read 116-123 MiB locally and
dropped to 65-81 MiB only after the idle threads exited.
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@AJenbo
AJenbo merged commit 552e7bc into PHPantom-dev:main Nov 12, 2026
21 checks passed
@AJenbo

AJenbo commented Nov 12, 2026

Copy link
Copy Markdown
Contributor

Thanks

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.

3 participants