UID2-7105: parse salt files line-by-line to avoid String[] buffer#618
Open
mcollins-ttd wants to merge 1 commit into
Open
UID2-7105: parse salt files line-by-line to avoid String[] buffer#618mcollins-ttd wants to merge 1 commit into
mcollins-ttd wants to merge 1 commit into
Conversation
Replace reader.lines().toArray(String[]::new) in readInputStream with a
streaming BufferedReader approach via a new SaltFileParser.parseLines method.
Eliminates the ~147 MB intermediate String[] allocated per snapshot load.
EncryptedRotatingSaltProvider also updated to use parseLines via StringReader,
avoiding the split("\n") allocation in the old parseFile path.
Co-Authored-By: Claude Sonnet 4.6 <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.
Why
RotatingSaltProvider.readInputStreamcalledreader.lines().toArray(String[]::new)before parsing, which materialised the entire salt file as aString[]of ~1M objects. For a 99 MB snapshot this creates ~147 MB of temporary strings on the heap simultaneously with the ~180 MBSaltEntry[]being built — a ~327 MB peak per snapshot load that is pure overhead.EncryptedRotatingSaltProviderhad a related issue: it calledsaltFileParser.parseFile(decrypted, size)which internally callsString.split("\n"), creating another largeString[]from the already-decrypted string.What changed
SaltFileParser.parseLines(BufferedReader, Integer)— reads line-by-line from the reader, parsing directly into a pre-sizedSaltEntry[]with no intermediate array.RotatingSaltProvider.readInputStreamnow callsparseLinesdirectly instead oftoArray+parseFileLines.EncryptedRotatingSaltProvider.readInputStreamwraps the decrypted string in aStringReader/BufferedReaderand callsparseLines, avoiding thesplit("\n")allocation.parseFile/parseFileLinesmethods are unchanged (other callers unaffected).Memory impact
Per snapshot load: peak drops from ~327 MB to ~180 MB (the
SaltEntry[]itself, which is irreducible). With 2 snapshots, worst-case overlap drops from ~507 MB to ~360 MB.Testing
SaltFileParserTest.parseLinesMatchesParseFileto verifyparseLinesproduces identical output toparseFilefor the same input.SaltFileParserTest,RotatingSaltProviderTest, andEncryptedRotatingSaltProviderTesttests pass (13 total, 0 failures).Part of UID2-7105.
🤖 Generated with Claude Code