perf: remove cache and use IReadOnlyList<Attribute>#4310
perf: remove cache and use IReadOnlyList<Attribute>#4310thomhurst merged 3 commits intothomhurst:mainfrom
IReadOnlyList<Attribute>#4310Conversation
SummaryRemoves lazy-initialized attribute caching and replaces it with a direct Critical Issues1. Missing snapshot test updates ⛔ Required action:
The following files need to be updated based on the grep results:
Suggestions1. Documentation update 💡 2. Verify dual-mode compliance ✅
No action needed here - the implementation looks correct. Verdict |
|
Can we keep the method so we don't break the API |
Sure |
|
If I need to avoid changing the API how should I pass in the collection, should I keep it a property or pass it in via the constructor? |
|
I think constructor makes sense - And is available to us earlier then too |
91238e2 to
4ca710b
Compare
|
I've changed the existing constructor so there is no longer a parameterless one, not sure if this is breaking. I did think of keeping the paramterless contructor in addition to this, adding a debug check to ensure that the |
|
Technically a breaking change but user's shouldn't really be new'ing up that class themselves so it's okay imo. You will probably need to run the TUnit.PublicAPI tests and update the snaps |
4ca710b to
13fc951
Compare
|
Still getting the Sourcy errors so I manually edited the snapshots, hopefully I got i right 😄 |
Public API Snapshot FixThe public API snapshot tests are failing. I've updated the To incorporate the fix, you can either:
The changes update 4 snapshot files for the |
SummaryRemoves lazy initialization of attributes cache, instead passing attributes directly to TestDetails constructor to reduce memory allocation. Critical IssuesLine 68 in TUnit.Core/TestDetails.cs: The XML documentation comment was accidentally converted to a regular comment. - /// <summary>
+ // <summary>This should remain as SuggestionsNone - the performance optimization approach is sound. The change eliminates the Verdict |
Update verified snapshots to match current PublicApiGenerator output after constructor signature change from TestDetails() to TestDetails(IReadOnlyList<Attribute> allAttributes). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Change `// <summary>` back to `/// <summary>` for proper XML documentation generation. Also removed outdated cache reference from the comment since attributes are now passed directly. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
bdacdd1 to
bab3e47
Compare
SummaryRemoves lazy initialization cache from TestDetails and passes attributes list directly to constructor, saving ~10MB+ of memory. Critical IssuesNone found ✅ SuggestionsNone - the implementation is clean and all call sites are correctly updated. TUnit Rules Compliance✅ Dual-mode implementation: Not required - this change is in the unified code path after metadata collection. Code ReviewThe changes correctly:
The performance improvement is measurable (~10MB reduction) and the approach is sound - since attributes are already computed at all call sites, eliminating the lazy wrapper is pure overhead reduction. Verdict✅ APPROVE - Clean performance optimization with all rules satisfied and call sites properly updated. |
SummaryThis PR removes lazy initialization of the attributes cache, instead passing attributes directly to the TestDetails constructor to reduce memory allocation (saves ~10MB). Critical IssuesNone found ✅ Suggestions1. Update interface documentation 💡 /// <summary>
/// Gets all attributes as a flattened collection.
- /// Cached after first access for performance.
/// </summary>This is minor since the implementation documentation in Previous Review Status✅ XML documentation issue resolved - The documentation now correctly uses All previous critical issues have been addressed. Verdict✅ APPROVE - No critical issues. The performance optimization is well-implemented and all previous review feedback has been addressed. |
Instead of creating a lazy initalizer, pass in the list of
Attributes. Removed the methodGetAllAttributesand added the propertyAllAttributesSee #4303
Tricky to track the savings but this saves at least 10MB, maybe more.
Before
After