Repository navigation
Return memory right after large parses instead of holding it - #567
Merged
Merged
Conversation
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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
|
Thanks |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Checklist
If applicable:
CHANGELOG.mdREADME.md,docs/,examples/)config-schema.json)the changes and why they are needed.
the changelog, and other user-facing content, and removed or corrected
anything inaccurate, unclear, or unnecessary.