perf: replace anonymous Member classes with concrete ExprFieldMember/MethodFieldMember#756
Merged
stephenamar-db merged 1 commit intomasterfrom Apr 11, 2026
Merged
Conversation
Collaborator
Author
…MethodFieldMember Every field in visitMemberList previously created an anonymous Val.Obj.Member subclass, generating N distinct classes per object expression. This pollutes the JIT profile with megamorphic dispatch at invoke() call sites. Replace with two concrete classes (ExprFieldMember, MethodFieldMember) and a shared ObjectScopeFactory. All fields from the same object literal share one factory which encapsulates the scope-caching logic (previously in the makeNewScope/createNewScope closures). Benefits: - Monomorphic dispatch at Member.invoke() -> better JIT inlining - Explicit fields instead of synthetic closure captures - Scope caching preserved via shared ObjectScopeFactory - One factory allocation per object replaces N closure allocations
c021e1d to
0bf1602
Compare
Contributor
|
We need more pattern-driven AST transformation, too. |
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.
Summary
Val.Obj.Membersubclasses invisitMemberListwith concreteExprFieldMemberandMethodFieldMemberclasses, giving the JIT a monomorphic type at everyinvoke()call site for better inlining.makeNewScope/createNewScopeclosures) into anObjectScopeFactoryclass. All fields from the same object literal share one factory, preserving per-object scope caching while eliminating per-field closure allocations.Benchmark results
JMH regression suite (
bench.runRegressions), JDK 21.0.10, single fork, 1 warmup + 1 measurement iteration (10s):No regressions observed (remaining benchmarks within noise).
Test plan
./mill 'sjsonnet.jvm[3.3.7]'.test— all tests pass./mill __.checkFormat— formatting verified