Share projection metadata read across factory instances - #3520
Open
zanarellidev wants to merge 1 commit into
Open
Share projection metadata read across factory instances#3520zanarellidev wants to merge 1 commit into
zanarellidev wants to merge 1 commit into
Conversation
DefaultProjectionInformation.PropertyDescriptorSource.getMetadata() performed a fresh ASM MetadataReader classpath read of a projection interface's class file on every construction, and ProxyProjectionFactory.projectionInformationCache is per-instance. Two independent ProxyProjectionFactory/SpelAwareProxyProjectionFactory instances resolving the same projection type each paid their own class file read, with no sharing. In reactive applications this shows up as a Blockhound-flagged blocking file read on the event loop. Add a shared, type-keyed ConcurrentReferenceHashMap (weak keys) cache for the metadata read, below the per-factory layer. Closes spring-projects#3513 Signed-off-by: zanarelli <zanarelli.dev@gmail.com>
mp911de
force-pushed
the
main
branch
4 times, most recently
from
August 5, 2026 14:13
adb1c6d to
0ba14c1
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.
mvn test/mvn package; matched the surrounding file's existing style by hand instead of running the IDE formatter directly.)Closes #3513.
DefaultProjectionInformation.PropertyDescriptorSource.getMetadata()performed a fresh ASMMetadataReaderclasspath read of a projection interface's.classfile on every construction,and
ProxyProjectionFactory.projectionInformationCacheis per-instance. Two independentProxyProjectionFactory/SpelAwareProxyProjectionFactoryinstances resolving the same projectiontype each paid their own class-file read, with no sharing. In reactive applications this is the
blocking-I/O-on-event-loop Blockhound violation described in the issue.
This PR adds a shared, type-keyed
ConcurrentReferenceHashMap(weak keys) cache for the metadataread, below the per-factory layer, matching the approach the reporter proposed in #3513.
ProjectionMetadataCachingProbeTestsreproduces the issue without needing R2DBC/Blockhound: ituses a custom child-first
ClassLoaderthat counts real.classresource reads, and confirms twoindependent factory instances resolving the same projection type only trigger one read after this
fix (previously two).