Repository navigation
Windows: getenv keeps one buffer per variable and value (#3364) - #3466
Merged
Merged
Conversation
…ead a million times no longer costs a page per read (#3364)
ehartford
marked this pull request as draft
November 19, 2026 15:46
ehartford
marked this pull request as ready for review
November 19, 2026 17:22
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 |
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.
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_getenvmapped a fresh region for the value (rt_mmap(len + 1): at least one committed, written page) and never freed it. The compiler readsWITH_FILE_PREFIX_MAPon 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 intoenviron, uses 1.6 GB either way.The fix. One buffer per variable and value, in a fixed table with its own lock (
rt_getenvruns 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 inrt/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.