Repository navigation
SNOMED CT: hold each loaded edition once, not twice (use cache sections in place) - #329
Merged
grahamegrieve merged 1 commit intoNov 1, 2026
Conversation
…opying them Each structure copied its section of the cache file (Buffer.from), while the factory's shared data kept the reader's views of the file, so the whole file buffer stayed alive too: every loaded edition took twice its file size (sct_intl_20250201: 1.64 GB of ArrayBuffers for an 822 MB file). Sections of a file loaded by SnomedFileReader are now used in place. Nothing writes to a loaded structure; buffers from anywhere else are still copied. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Each loaded SNOMED CT edition currently takes twice its file size in RAM. This change makes it take its size once, with no behaviour change.
Cause
In
tx/sct/structures.js:SnomedFileReader.load()reads the whole.cachefile into one Buffer.SnomedStrings,SnomedConceptList,SnomedDescriptions,SnomedRelationshipList, …) copies its section withBuffer.from(buffer).So each edition is held once as the file Buffer and once as the per-structure copies.
Measured
process.memoryUsage().arrayBuffers, loading the SNOMED CT editions from tx.fhir.org's source list:The ratio is exactly 2× for 1, 3 and 9 editions, and a heap snapshot shows no other SNOMED CT retainer of any size. Loading is a little faster too, since nothing is copied.
For context, the IG Publisher transcripts on build.fhir.org (
qa-tx.html) show tx.fhir.org aborting 1,583 calls on 29 Oct with "server memory usage (23.6 GB) exceeds safe threshold (98% of 24.0 GB limit)". In our replays of that traffic, SNOMED CT was about 12 GB of main's ~15 GB anonymous RSS.Change
A
WeakSetrecords the ArrayBuffers thatSnomedFileReaderloaded. Each structure constructor now callsadopt(buffer):Nothing writes to a loaded structure; the builders allocate their own buffers. 1 file, +22 / −10.
Testing
tests/cs/cs-snomed.test.js(41 tests) passes. So do the ECL, search, subsumption, MRCM and expression-grammar suites (206 passed; 25 skipped because they need data not present here).A separate, optional follow-up could memory-map the cache files (about 15 GB → 3 GB anonymous RSS, same warm latency). It needs an optional native dependency, so it's not in this PR.
🤖 Generated with Claude Code