Skip to content

refactor: optimize internal string building#5914

Open
KoreaNirsa wants to merge 1 commit intospring-projects:mainfrom
KoreaNirsa:refactor/optimize-string-building
Open

refactor: optimize internal string building#5914
KoreaNirsa wants to merge 1 commit intospring-projects:mainfrom
KoreaNirsa:refactor/optimize-string-building

Conversation

@KoreaNirsa
Copy link
Copy Markdown
Contributor

Summary

This PR optimizes a couple of internal string-building paths without changing existing behavior

  • Replace per-byte String.format("%02x", b) usage in JdkSha256HexIdGenerator with Java 17 HexFormat
  • Replace string concatenation via stream reduce in MiniMaxApi#getTextContent with Collectors.joining()
  • Add a regression test to verify that the SHA-256 based document ID remains stable

Performance benefit

String.format("%02x", b) is relatively expensive for byte-by-byte hex encoding because it goes through formatter parsing and formatting machinery on every byte. HexFormat is purpose-built for byte-to-hex conversion and avoids that repeated formatting overhead

Similarly, string concatenation inside reduce creates intermediate String instances as the stream is accumulated Collectors.joining() uses a mutable accumulation strategy internally, which avoids repeated intermediate concatenations and is the idiomatic collector for joining stream elements

Signed-off-by: KoreaNirsa <islandtim@naver.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