Repository navigation
perf(native): give memory back when idle and cut the profiler journal's footprint - #89
Draft
rubnogueira wants to merge 2 commits into
Draft
rubnogueira wants to merge 2 commits into
rubnogueira wants to merge 2 commits into
Conversation
A full collection alone leaves the freed pages and the caches the engine rebuilds on demand where they were, about 45 MB on a long chat thread. After the collection the default collector now calls `Bun.shrink()`, which hands them back. Node's `--expose-gc` path is unchanged.
The 4 MiB foreground profiler journal ring is allocated zeroed, so it is resident only as far as entries are recorded. Nothing outside the host's hang detection reads it, so an app that does not use that holds about 4 MB less.
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.
Summary
An app that sits idle on a long thread kept memory it no longer needed.
collectGarbageWhenIdle()ran a full collection, but under Bun that leaves the freed pages and the caches the engine rebuilds on demand in place. The profiler's foreground journal also held a 4 MiB ring resident from startup, for apps that never read it.In t3's GPUI app on a long chat thread, resident memory went from about 414 MB to about 368 MB with both changes.
Changes
collectGarbageWhenIdle()shrinks under Bun. After the full collection the default collector callsBun.shrink(), which hands the freed pages and rebuildable engine caches back. That is about 45 MB on a long thread. WithoutBun.shrinkit collects as before, and the Node--expose-gcpath is unchanged. The README paragraph and the unreleased changeset describe the new behaviour.zedto the lazily resident profiler journal. The ring is now allocated zeroed, so it is resident only as far as entries are recorded. Nothing outside the host's hang detection reads it, so an app that does not use that holds about 4 MB less. The code change is in perf(gpui): keep the profiler journal ring out of memory until it is written zed#11. This PR moves thezedpin to its head (74bdb01) and adds a patch changeset for@gpuix/native.Merge order
Merge remorses/zed#11 first. The
zedpin points at its head, which only exists on that PR's branch until it lands.Test plan
vitest run js/__tests__/idle-gc.test.tsinpackages/native: 6 pass, 2 of them new (shrink is called after the forced collection, and is skipped whenBun.shrinkis absent).tsc --noEmitinpackages/native: clean.cargo check --features test-supportinpackages/native, on this branch withzedat74bdb01: succeeds, with only the existing dead-code warnings.bun run buildinpackages/native(release addon, ESM and CJS loaders,tsc): succeeds, and the new addon loads under Bun.vitest runinpackages/react: 536 pass.vitest run js/__tests__inpackages/native: 16 pass, 1 fails.package.test.ts › bundles both public adapters for the browserneedspackages/native/wasm/, whichbun run build:webgenerates and which was not built here.--features profiler,test-support) run in the zed PR.Written with Claude Sonnet 5.5 in Cursor.