8000 perf: Eliminate Stream allocations in Env getters by kawasima · Pull Request #87 · enkan/enkan · GitHub
[go: up one dir, main page]

Skip to content
< 8000 /div>

perf: Eliminate Stream allocations in Env getters - #87

Merged
kawasima merged 1 commit into
developfrom
perf/env-eliminate-stream-alloc
Mar 8, 2026
Merged

kawasima merged 1 commit into
developfrom
perf/env-eliminate-stream-alloc

Conversation

@kawasima
@kawasima kawasima commented Mar 8, 2026
Copy link
Copy Markdown
Collaborator

Summary

  • Replace Stream.of(...).map(...).filter(...).findFirst().orElse(...) with direct envMap.get(normalizeKey(name)) lookup in all four typed getters (getString, getInt, getLong, getBoolean)
  • Remove now-unused import java.util.stream.Stream and import java.util.Objects
  • Behaviour is identical: same key normalization, same default-value semantics, NumberFormatException still propagates from getInt/getLong

Closes #86

Test plan

  • mvn test -pl enkan-core — all 8 existing EnvTest tests pass

🤖 Generated with Claude Code

Replace Stream.of(...).map(...).filter(...).findFirst().orElse(...)
with a direct envMap.get(normalizeKey(name)) lookup in all four typed
getters (getString, getInt, getLong, getBoolean). Removes per-call
Stream/Spliterator/Optional allocations. Behaviour is identical.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Copilot AI left a comment
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This is a targeted performance improvement that eliminates unnecessary Stream allocations in Env's four typed getter methods (getString, getInt, getLong, getBoolean). Previously, each call created a Stream/Spliterator object pipeline for what is effectively a single key lookup. The replacement is a direct envMap.get(normalizeKey(name)) call with a null check, preserving identical behavior while reducing per-call allocations.

Changes:

  • Replaced Stream.of(...).map(...).filter(...).findFirst().orElse(...) pipelines in all four typed getters with direct map lookups and null-conditional expressions
  • Removed the now-unused import java.util.stream.Stream

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@kawasima
kawasima merged commit 63d4b65 into develop Mar 8, 2026
4 checks passed
@kawasima
kawasima deleted the perf/env-eliminate-stream-alloc branch March 8, 2026 09:32
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.

2 participants

0