Conversation
…data - Cache introspected properties, accessible accessor methods and the default constructor per type and CollectionSamplingMode in the new TypeModel (Properties.getTypeModel), instead of re-introspecting up to six times per generated instance. - Cache the resolved generic collection element type per read method in ReflectionUtil.getCollectionType. - Reuse the cached default constructor in Sample instead of probing type.getConstructor() twice per auto-sampled object. - Add a JMH benchmark (SampleGenerationBenchmark) measuring flat bean generation, auto-sampling of an object graph and the configuration API including the field selector. JMH results (JDK 21, avgt, us/op): - flatBean: 1.483 -> 1.235 (-17%) - objectGraphWithAutoSampling: 16.293 -> 11.688 (-28%) - configureAndCreateFlatBean: 2.513 -> 1.874 (-25%) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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
This PR removes repeated reflection work from the sample generation hot path:
CollectionSamplingModein the new package-privateTypeModel(seeProperties.getTypeModel). Previously,Sample.newInstance()re-ran introspection and property filtering up to six times per generated instance - and recursively for every auto-sampled object in the graph.ReflectionUtil.getCollectionTypecaches the resolved collection element type per read method instead of resolvinggetGenericReturnType()on every call.type.getConstructor()twice per generated object, andsetAccessible(true)is no longer invoked on every single property write.Behavioral notes:
Properties.getPropertiesnow returns an unmodifiable set; the only mutating caller (Sample.getNotHitFields) copies it first.SampleException/ReflectionExceptionas before).InvocationSensorproxy class cache.TypeModel, following the existing pattern for internal classes with defensive code paths.Benchmark
Adds a JMH benchmark (
SampleGenerationBenchmark, test scope) covering flat bean generation, auto-sampling of an object graph (nested beans, collections, enum, map) and the configuration API including the field selector. Run it with:Measured before/after on this branch (JDK 21, average time, 1 fork, 3 warmup + 5 measurement iterations):
All 50 runnable unit tests pass; formatter validation and the JaCoCo coverage rules pass as well.
🤖 Generated with Claude Code