Skip to content

UID2-7105: parse salt files line-by-line to avoid String[] buffer#618

Open
mcollins-ttd wants to merge 1 commit into
mainfrom
mkc-UID2-7105-reduce-salt-provider-memory
Open

UID2-7105: parse salt files line-by-line to avoid String[] buffer#618
mcollins-ttd wants to merge 1 commit into
mainfrom
mkc-UID2-7105-reduce-salt-provider-memory

Conversation

@mcollins-ttd

Copy link
Copy Markdown
Contributor

Why

RotatingSaltProvider.readInputStream called reader.lines().toArray(String[]::new) before parsing, which materialised the entire salt file as a String[] of ~1M objects. For a 99 MB snapshot this creates ~147 MB of temporary strings on the heap simultaneously with the ~180 MB SaltEntry[] being built — a ~327 MB peak per snapshot load that is pure overhead.

EncryptedRotatingSaltProvider had a related issue: it called saltFileParser.parseFile(decrypted, size) which internally calls String.split("\n"), creating another large String[] from the already-decrypted string.

What changed

  • Added SaltFileParser.parseLines(BufferedReader, Integer) — reads line-by-line from the reader, parsing directly into a pre-sized SaltEntry[] with no intermediate array.
  • RotatingSaltProvider.readInputStream now calls parseLines directly instead of toArray + parseFileLines.
  • EncryptedRotatingSaltProvider.readInputStream wraps the decrypted string in a StringReader/BufferedReader and calls parseLines, avoiding the split("\n") allocation.
  • Existing parseFile/parseFileLines methods 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

  • Added SaltFileParserTest.parseLinesMatchesParseFile to verify parseLines produces identical output to parseFile for the same input.
  • All existing SaltFileParserTest, RotatingSaltProviderTest, and EncryptedRotatingSaltProviderTest tests pass (13 total, 0 failures).

Part of UID2-7105.

🤖 Generated with Claude Code

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>
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