Skip to content

perf: cache attribute factory results on TestMetadata#4679

Merged
thomhurst merged 1 commit intomainfrom
perf/cache-attribute-factory
Feb 6, 2026
Merged

perf: cache attribute factory results on TestMetadata#4679
thomhurst merged 1 commit intomainfrom
perf/cache-attribute-factory

Conversation

@thomhurst
Copy link
Owner

Summary

  • Add `GetOrCreateAttributes()` method to `TestMetadata` that lazily caches the attribute array on first call
  • `AttributeFactory` was being invoked multiple times per test during building (checking for ClassConstructor, creating test details, initializing attributes, etc.)
  • Now it runs once and subsequent calls return the cached array, avoiding redundant attribute instantiation
  • Public API addition (new method on `TestMetadata`), verified snapshot files updated

Test plan

  • Verify attribute-based features still work (ClassConstructor, Skip, Repeat, etc.)
  • Verify dynamic test attributes work correctly
  • Run public API snapshot tests
  • Run full engine test suite

🤖 Generated with Claude Code

@claude
Copy link
Contributor

claude bot commented Feb 6, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

This is a clean performance optimization that adds lazy caching for test attributes. The implementation correctly uses the null-coalescing assignment operator (??=) to cache the attribute array on first access, and all call sites throughout the codebase have been systematically updated to use the new GetOrCreateAttributes() method. The change aligns well with CLAUDE.md's "Performance First" principle (Rule 4) by caching reflection results, and the snapshot test files have been properly updated to reflect the new public API.

Add GetOrCreateAttributes() that lazily caches the attribute array on
first call. AttributeFactory was being invoked multiple times per test
during building — now it runs once and subsequent calls return the cached
array, avoiding redundant attribute instantiation.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant