Reduce allocations and duplication in attribute resolution - #816
Open
Nafis8709 wants to merge 1 commit into
Open
Reduce allocations and duplication in attribute resolution#816Nafis8709 wants to merge 1 commit into
Nafis8709 wants to merge 1 commit into
Conversation
…t-path allocations in attribute resolution
ebussieres
force-pushed
the
refactor/optimize-attribute-resolution
branch
from
July 22, 2026 16:46
b410f22 to
24789b6
Compare
Member
|
AI stuff I presume ? |
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.
Problem
DefaultAttributeResolverandMemberCacheUtilssit on the attribute-resolution path thatruns on every
{{ object.property }}access during rendering, so small inefficiencies hereare multiplied across every attribute in every template. Four issues live in this path:
getArgumentTypes()returnsnew Class<?>[0]on every no-argument access — the commoncase (
{{ user.name }}) — allocating a throwaway empty array each time.MemberCacheKeyis a non-static inner class that never uses its enclosing instance, soevery key stored in the cache silently holds a reference to the outer
MemberCacheUtils.reflect()contains three near-identical blocks trying theget/is/hasprefixes.findMethod()mixes the "perfect match" and "greedy match" strategies in one long method.Change
getArgumentTypes()returns a sharedEMPTY_ARGUMENT_TYPESconstant for the no-argument case instead of allocating each time.
MemberCacheKeyis nowstatic, removing the implicit outerreference from every cached key.
get/is/haslookups collapse into a single loop over aprefix array, tried in the same order as before.
findMethod()is split intofindPerfectMatch()andfindGreedyMatch().verifyUnsafeMethod()is still called at the same point, so matching and access validationare unchanged.
Non-breaking: the public API of
DefaultAttributeResolveris unchanged, and methodmatching order and results are identical. These are pure refactorings.
Tests
mvn clean test -pl pebble -am— tests, 0 failures, 0 errors.