perf: precompute and cache field metadata per class (closes #77)#78
Merged
perf: precompute and cache field metadata per class (closes #77)#78
Conversation
Introduces ClassMetadataCache and FieldDescriptor so that annotation scanning, FormatContext/FormatInstructions building, setter resolution, and formatter instantiation happen at most once per class rather than on every load() and export() call. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Move helper instances (AnnotationScanner, FormatInstructionsBuilder, RepeatingFieldSupport) from ClassMetadataCache singleton fields to local variables inside build(), eliminating shared mutable state between concurrent builds of different classes - Mark FormatContext.offset/dataType/formatter fields as final, enforcing immutability at the type level for objects cached and shared across threads - Mark ByTypeFormatter.context as final for the same reason No behavioral change; all 381 tests pass. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
…Impl Adds two test classes covering four scenarios: TestClassMetadataCacheConcurrency: - Same-class concurrent access: 20 threads verified to receive the identical cached List<FieldDescriptor> instance (proves single build, no duplicate work) - Different-class concurrent builds: interleaved access to MyRecord, MultibleFieldsRecord, and RepeatingFieldRecord verified to produce the correct per-class descriptor counts with no cross-contamination TestFixedFormatManagerConcurrency: - Concurrent load(): 20 threads parse the same record string and each get a correctly-populated POJO (stringData, booleanData, integerData, longData) - Concurrent export(): 20 threads serialise the same pre-built MyRecord and each get the correct fixed-width string Regression verification: replacing computeIfAbsent with a racy put/get caused sameConcurrentAccessReturnsSameListInstance to fail, confirming the test detects the class of race condition it was written to guard against. Co-Authored-By: Claude Sonnet 4.6 <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
ClassMetadataCacheandFieldDescriptorso annotation scanning,FormatContext/FormatInstructionsbuilding, setter resolution, and formatter instantiation happen at most once per class — not on everyload()/export()callFormatContextfields andByTypeFormatter.contextare nowfinalTest plan
TestClassMetadataCache— unit tests: correct descriptor count, non-null metadata,@Fieldsexpansion, repeating/nested-record handling, custom-formatter flagTestClassMetadataCacheConcurrency— 20-thread tests: same-class access returns identical list instance; different-class concurrent builds produce correct per-class counts; no cross-contaminationTestFixedFormatManagerConcurrency— 20-thread tests: concurrentload()returns correctly-populated POJOs; concurrentexport()returns correct record strings🤖 Generated with Claude Code