perf: intern identifier field names + eq fast path in field lookup - #1117
Draft
He-Pin wants to merge 1 commit into
Draft
perf: intern identifier field names + eq fast path in field lookup#1117He-Pin wants to merge 1 commit into
He-Pin wants to merge 1 commit into
Conversation
2 tasks
He-Pin
marked this pull request as draft
August 12, 2026 05:35
Motivation: Object field lookup is the hottest path in sjsonnet evaluation. Every field access (containsKey, containsVisibleKey, valueRaw) compares String keys char-by-char via .equals, which is wasteful when the same field names repeat across objects (common in K8s manifests, stdlib). Modification: - Parser routes identifier field names (fieldname rule and Expr.Select) through internedStrings, sharing String instances across repeated parses - String-literal field names are interned in the fieldname rule as well, with the same >1024 length guard as constructString to avoid memory bloat from pathologically large field names - Val.Obj field lookup hot loops use reference equality (eq) before .equals, eliminating char-by-char comparison for interned keys - 5 lookup sites patched: containsKey (2), containsVisibleKey (1), valueRaw (2) Result: ParserBenchmark.main: 1.462 -> 1.378 ms/op (-5.7%); MainBenchmark.main within noise. All 424 tests pass. Zero behavioral change -- eq is strictly a fast path before the existing .equals fallback (a eq b implies a.equals(b)).
He-Pin
force-pushed
the
perf/intern-field-eq-fastpath
branch
from
August 13, 2026 11:57
b5f7e33 to
2dd7e5f
Compare
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.
Motivation
Object field lookup is the hottest path in sjsonnet evaluation. Every field access (
containsKey,containsVisibleKey,valueRaw) compares String keys char-by-char via.equals, which is wasteful when the same field names repeat across objects (common in K8s manifests, stdlib).Modification
internedStrings, sharing String instances across repeated parsesVal.Objfield lookup hot loops use reference equality (eq) before.equals, eliminating char-by-char comparison for interned keyscontainsKey(2),containsVisibleKey(1),valueRaw(2)Result
JMH config:
-f 2 -wi 5 -i 10 -w 1 -r 1(2 forks × 10 measurement iterations)All 424 tests pass. Zero behavioral change —
eqis strictly a fast path before the existing.equalsfallback.Test plan
./mill 'sjsonnet.jvm[_]'.test— all pass./mill bench.runJmh ".*MainBenchmark.*"— no regression./mill bench.runJmh ".*ParserBenchmark.*"— 5.7% improvement