Skip to content

Windows: getenv keeps one buffer per variable and value (#3364) - #3466

Merged
ehartford merged 1 commit into
mainfrom
getenv-once
Nov 19, 2026
Merged

ehartford merged 1 commit into
mainfrom
getenv-once

Conversation

@ehartford

Copy link
Copy Markdown
Contributor

Part of #3364: the fix, not yet measured on Windows. The issue stays open until a Windows compiler built with it is measured.

The leak. On Windows every successful rt_getenv mapped a fresh region for the value (rt_mmap(len + 1): at least one committed, written page) and never freed it. The compiler reads WITH_FILE_PREFIX_MAP on every source-path canonicalisation, about a million times when it compiles itself: 4.5 GB. Measured on the win10 VM: the same compile commits 3.9 GB without that variable set and 8.5 GB with it; macOS, which returns a pointer into environ, uses 1.6 GB either way.

The fix. One buffer per variable and value, in a fixed table with its own lock (rt_getenv runs under the allocator lock, so it takes neither the allocator nor its lock). A repeat read is compared in UTF-16 against the copy kept beside the value, so it maps and converts nothing. A changed value gets a new buffer and the old one stays mapped for whoever still holds it; a full table (512 variables) leaves a value uncached, which is correct and costs what every read cost before. Same change in rt/windows_aarch64.w.

What it does not do yet. src/ is linked with the pinned seed's runtime, so the compiler's own memory falls at the next seed pin. Programs built by the tree's compiler get it at once.

Both Windows runtime bundles build on the Mac (rt-bundle-windows_x86_64). Battery green on the branch tip.

…ead a million times no longer costs a page per read (#3364)
@ehartford
ehartford marked this pull request as draft November 19, 2026 15:46
@ehartford
ehartford marked this pull request as ready for review November 19, 2026 17:22
@ehartford

Copy link
Copy Markdown
Contributor Author

Windows x86_64 lane on this branch (run 44558564030): every test target passed with the new runtime; the run's only failure is unit-return-review: fatal: bad revision 'origin/main', which is the lane's checkout on a dispatched branch and not this change.

@ehartford
ehartford merged commit fee89ea into main Nov 19, 2026
1 check failed
@ehartford
ehartford deleted the getenv-once branch November 19, 2026 17:22
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