You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Avoid temporary arrays in singleton tuple binding - #7583
Singleton reference-tuple binding copied every row into an element array just to distinguish a null element from a null row. Inspect ITuple.Length and the singleton element directly instead. Keep the existing extraction fallback for targets without ITuple, and leave mutable-element reconstruction unchanged.
Allocation measurements on .NET 10.0.403, macOS arm64, Release, using a cached delegate to ShouldFlattenErasedTuple, pre-created rows/metadata, 10,000 warmup calls and 100,000 measured calls (GC.GetAllocatedBytesForCurrentThread):
Row / target
Before B/call
After B/call
Reference singleton null / reference
32
0
Reference singleton string / reference
32
0
Value singleton null / reference
32
0
Value singleton string / reference
32
0
Mutable struct in reference singleton / reference
56
24
Mutable struct in value singleton / value
56
56
Empty nullable mutable in value singleton / value
32
32
Flattening decisions were unchanged for every measured case. No target-classification cache was added. The netstandard2.0 fallback retains its existing behavior and allocation profile.
Validation: DataSourceHelpersTests (9 tests, including null/non-null allocation regressions); PreservedGenericTupleTests (20), GenericMutableTupleInitializerTests (10), and GenericTupleDataSourceTests (1), each in generated and reflection discovery on net10.0. Release Core builds pass for net10.0 and netstandard2.0. Existing build warnings were reported on #7410.
Native AOT: Release publish for osx-arm64 succeeded; the published executable passed PreservedGenericTupleTests (20) and GenericMutableTupleInitializerTests (10). Existing publish diagnostics were reported on #7493.
Rebased onto main after #7603 merged. Its STA snapshot corrections are already upstream, so this PR now changes only the tuple helper and its allocation regression tests. The earlier diagnostic AOT run 41900939879 passed, including Windows engine tests; #7554 remains a separate intermittent-hang investigation.
Summary by CodeRabbit
Bug Fixes
Corrected how singleton reference tuples containing null are handled when tuple data is flattened, so null-valued elements are not mistaken for a different tuple shape.
Performance
Reduced allocations when determining how singleton reference tuples should be handled; repeated decisions now allocate no memory.
Tests
Updated generated test snapshots to reflect reduced repeat counts and current test locations.
Review was skipped as selected files did not have any reviewable changes.
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 08e3601e-5987-4d20-9dfa-1cdfd45e218b
Commits
Reviewing files that changed from the base of the PR and between ed7f580 and b17c4b7.
You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.
Use the checkbox below for a quick retry:
Trigger review
No actionable comments were generated in the recent review.
Walkthrough
The singleton reference-tuple null check now uses ITuple on supported runtimes instead of unwrapping the tuple into an array. A new test checks null and non-null tuple decisions and verifies zero allocations across 100 warmed calls. STA verified snapshots reduce repeat counts and update generated source line numbers.
Changes: Singleton tuple null check
Layer / File(s)
Summary
Tuple decision and allocation test src/TUnit.Core/Helpers/DataSourceHelpers.cs, tests/TUnit.UnitTests/DataSourceHelpersTests.cs
ShouldFlattenErasedTuple uses IsSingletonTupleContainingNull. The helper checks ITuple on supported runtimes and uses UnwrapTupleAot otherwise. The test checks null and non-null singleton reference tuples and verifies zero allocations across 100 warmed calls.
STA generated snapshots
Layer / File(s)
Summary
STA snapshot metadata updates tests/TUnit.Core.SourceGenerator.Tests/STAThreadTests.Test.*.verified.txt
The verified snapshots change repeat counts from 100 to 10 and update generated source line numbers. The .NET 8, .NET 9, and .NET 10 snapshots add a UTF-8 BOM.
thomhurst/TUnit#7402 — The issue describes a singleton reference tuple containing null being passed as a null row in source-generated mode. This PR changes the singleton tuple null decision, but the supplied context does not confirm whether it fixes that generated-path behavior.
Possibly related PRs
thomhurst/TUnit#7548 — It introduced ShouldFlattenErasedTuple; this PR changes how that helper detects a null element.
Suggested labels:PATCH
Merge Risk: Minimal · previous review 37414
The tuple allocation optimization and STA snapshot updates are ready to merge based on the supplied evidence.
Pre-merge checks: 4 · 1
Failed checks: 1 warning
Check name
Status
Explanation
Resolution
Docstring Coverage
Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documenta…
Write docstrings for the functions missing them to satisfy the coverage threshold.
Passed checks: 4 passed
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title "Avoid temporary arrays in singleton tuple binding" matches the main change in the changeset. The raw summary shows that ShouldFlattenErasedTuple now uses IsSingletonTupleContainingNull, whi…
Linked Issues check
Directly linked issue [#7552] asks that singleton reference-tuple null detection avoid a temporary element array. At the current head, ShouldFlattenErasedTuple calls the new IsSingletonTupleContaining…
Out of Scope Changes check
The whole-PR diff now uses merge base e6c7dee and head 37414b1. It changes three areas. (1) src/TUnit.Core/Helpers/DataSourceHelpers.cs adds IsSingletonTupleContainingNull and uses it in the System.…
Full details: Title check
Explanation
The title "Avoid temporary arrays in singleton tuple binding" matches the main change in the changeset. The raw summary shows that ShouldFlattenErasedTuple now uses IsSingletonTupleContainingNull, which inspects ITuple directly and avoids extracting elements into a temporary array to detect a null element. The added test asserts zero-byte allocation for the singleton reference-tuple decision. The title is concise, specific, and free of file lists or vague terms. A teammate scanning history would understand the primary change.
Full details: Linked Issues check
Explanation
Directly linked issue [#7552] asks that singleton reference-tuple null detection avoid a temporary element array. At the current head, ShouldFlattenErasedTuple calls the new IsSingletonTupleContainingNull helper in src/TUnit.Core/Helpers/DataSourceHelpers.cs for the System.Tuple`1 guard. On net5+ and netcoreapp3.0+, the helper casts to ITuple, returns tuple.Length == 1 && tuple[0] is null, and does not copy the row. Other targets and the netstandard2.0 build keep the UnwrapTupleAot(value) is [null] fallback, so the decision result matches the previous logic. RequiresFlattenedTupleBinding and mutable-element reconstruction are unchanged in the whole-PR diff. The regression test SingletonReferenceTupleDecision_DoesNotAllocateElementArray covers null and non-null elements and checks zero allocation over warmed calls. The PR reports before-and-after measurements, tuple suite runs in generated and reflection discovery, and a Native AOT publish. This reviewer did not rerun those suites or the measurements. The change since the previous review is a rebase onto main and STAThreadTests snapshot refresh. It does not alter the helper. No parent-context or non-coding requirements apply.
Full details: Out of Scope Changes check
Explanation
The whole-PR diff now uses merge base e6c7dee and head 37414b1. It changes three areas. (1) src/TUnit.Core/Helpers/DataSourceHelpers.cs adds IsSingletonTupleContainingNull and uses it in the System.Tuple1 guard. This directly implements [#7552]. (2) tests/TUnit.UnitTests/DataSourceHelpersTests.cs adds one allocation regression test for the same decision. This supports [#7552]. (3) Four STAThreadTests verified snapshots (net10.0, net8.0, net9.0, net4.7) change RepeatAttribute values from 100 to 10 and update lineNumber values by five lines. The net4.7 snapshot diff confirms this pattern. These snapshot changes are not an objective of [#7552]. They align the snapshots with the STAThreadTests source change from #7594, which is already in main after the rebase. The PR description discloses this as CI maintenance and does not claim it fixes #7554`. The snapshot changes do not alter runtime behavior. The change summary also mentions a UTF-8 byte-order mark in some snapshot files. This detail is not in the PR description, but it affects only verified test fixture bytes. No unrelated runtime behavior change is visible.
Full details: Docstring Coverage
Explanation
Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 3 functions across 2 files. (4 skipped: 4 unsupported.)
Resolution
Write docstrings for the functions missing them to satisfy the coverage threshold.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
A tuple rests, its null kept whole No spare array is made to test One hundred calls leave bytes unmoved The snapshots count ten rounds instead A rabbit checks the lines, then hops away
Recent review info
Run configuration
Source mode: Auto
Repository: Unavailable
Branch: Unavailable
File: No configuration file from this repository applied
Commit: Unavailable
Layers: Organization UI
Review profile: CHILL
Plan: Advanced
Run ID: 0f0b3da3-2773-4296-8afe-cf629474b301
Commits
Reviewing files that changed from the base of the PR and between f1b538d and 37414b1.
Included review availability: This review used your included allowance. Your plan provides up to 8 included reviews per hour; 4 remain after this review.
The change replaces the UnwrapTupleAot(tuple) is [null] array copy with an ITuple.Length == 1 && tuple[0] is null check. I read the diff and the surrounding code but did not build or run the tests.
Correctness: The result matches the old check, because a singleton whose only element is null is still the case that returns false. The netstandard2.0 build keeps the old fallback. So does any target that isn't an ITuple. The required System.Runtime.CompilerServices using is already in the file.
AOT and trimming:ITuple is an interface call and needs no reflection, so it is safe for AOT and trimming.
Test: The new test warms up, then measures GC.GetAllocatedBytesForCurrentThread and expects 0 bytes over 100 calls. This is stable in Release. In Debug or with tiered JIT it could pick up a stray allocation, but the warmup loop should cover that. If it ever flakes, loosen the assertion to a small bound or compare against a baseline.
Minor, optional:#if NET5_0_OR_GREATER || NETCOREAPP3_0_OR_GREATER is redundant, since NET5_0_OR_GREATER also covers netcoreapp3.0+ only for net5+. Check which symbol the other ITuple guards in this file use and match it.
Nice, focused allocation fix with measurements in the description.
Reviewed all review surfaces for head 75ae5cb: Claude and Codex are positive, Greptile has no actionable findings, and there are no inline threads. Claude's optional preprocessor suggestion needs no change: the new guard matches the existing ITuple guards in DataSourceHelpers.cs (lines 173, 195, 529, and 550 at this head).
Marking ready to start CI and the ready-for-review Claude run. Auto-merge can be armed after that Claude run succeeds and its review is read, provided the head remains unchanged and no new blocking findings appear.
I read the diff and the PR conversation. I did not build or run the tests.
Correctness:IsSingletonTupleContainingNull uses ITuple.Length == 1 && tuple[0] is null. That gives the same answer as the old UnwrapTupleAot(tuple) is [null], without the temporary array. Targets that aren't ITuple, and netstandard2.0, still go through the old path.
AOT and trimming:ITuple is an interface call with no reflection, so this is safe.
Test: The test checks both the null and non-null singleton cases, with a warmup before measuring. A zero-byte assertion on GetAllocatedBytesForCurrentThread can flake under Debug or tiered JIT. The 100-iteration warmup should absorb that. If it ever flakes, compare against a small bound instead.
Earlier feedback: The earlier optional note about the #if guard was already answered. The author says it matches the other ITuple guards in the file. No other open threads or findings.
The change is small and focused, and the PR description includes before and after allocation numbers.
The earlier wait has cleared: #7603 merged as a85bb69, and AOT run 41900939879 completed successfully, including Windows engine tests. Refreshed #7583 onto current origin/main and pushed ed7f580. The snapshot commit dropped automatically because its corrections are upstream; the remaining diff is only the tuple helper and allocation regression tests.
Validation after rebase: Release net10.0 DataSourceHelpersTests passed 9/9; git diff --check passed. Existing build diagnostics remain tracked by #7410/#7412. Engine tests were not run locally, per repository instructions; fresh hosted CI must validate this head. Prior reviews were positive with no inline threads; the optional matching preprocessor guard has already been dispositioned. Fresh automatic reviews are required before auto-merge can be armed.
Resolution routes checked: #7552 still needs this optimization, so neither issue closure nor superseding/closing this PR is appropriate. #7603 is already merged and needs no further work. #7554 remains a separate intermittent-hang investigation, but there is no reason to keep this PR parked behind a completed diagnostic run. This unit pushed a fresh base rather than repeating unchanged CI or deferring again.
The change replaces UnwrapTupleAot(tuple) is [null] with IsSingletonTupleContainingNull. On modern TFMs it checks ITuple.Length == 1 && tuple[0] is null directly, so no element array is allocated. Targets without ITuple keep the old fallback.
Correctness: the new check gives the same result as the old pattern, because [null] means length 1 with a null element. System.Runtime.CompilerServices is already imported, and ITuple is already used elsewhere in the file under the same #if guard.
Tests: the new allocation regression test covers both the null and non-null singleton cases. Its zero-byte assertion depends on JIT warmup, and the 100-iteration warmup should handle that. If it ever flakes on tiered JIT, raise the warmup count or run it on an already-warmed path.
Nit: the #if NET5_0_OR_GREATER || NETCOREAPP3_0_OR_GREATER guard is redundant, since the second condition covers the first. Use whichever form the neighbouring code uses so the file stays consistent.
Nothing blocking. The PR description's AOT validation and before/after numbers are reassuring.
Pushed 37414b1 to repair the deterministic STAThreadTests snapshot failures in .NET run 41878526531. Main #7594 changed Repeat(100) to Repeat(10) and added five source lines without updating the generated metadata snapshots. Reviewed and refreshed all four TFM snapshots. The net472 and net10 outputs exactly match the Windows and Ubuntu received artifacts (ignoring UTF-8 BOM).
Validation: focused Release STAThreadTests generator snapshot test passed for net10.0. net8.0 and net9.0 compiled test binaries also passed with DOTNET_ROLL_FORWARD=Major on the installed .NET 10 runtime; this checks execution under .NET 10, not native .NET 8/9 runtime behavior. git diff --check passed. No engine suite ran locally. Existing restore diagnostics are tracked by #7412.
The earlier blocker is stale: #7584 merged and run 41860407100 completed. The separate Windows reflection hang nevertheless recurred after #7594 in current-head AOT run 41878526596 and main run 41878194086. Took #7554's lock and inspected the new hosted analysis rather than repeating a failed run: native stacks now identify Windows loader/console initialization and shutdown waits; detailed findings and next investigation are recorded on #7554 (#7554 (comment)). No undiagnosed test rerun, timeout increase, skipped test, human gate, or on-hold label was introduced. #7583 still needs that hang fixed before merging.
Reviewed every review surface: current prior head had positive Claude/Codex verdicts and no inline threads. Optional preprocessor feedback is already dispositioned. This pushed snapshot repair needs fresh automatic reviews and CI before auto-merge; it is a pushed fix rather than another deferral. No evidence supports closing or superseding the tuple-allocation change or its #7552 issue.
The change is small and correct. IsSingletonTupleContainingNull checks ITuple.Length == 1 && tuple[0] is null, which gives the same answer as the old UnwrapTupleAot(value) is [null]. It no longer allocates a temporary array on that path. Because the guard is #if NET5_0_OR_GREATER || NETCOREAPP3_0_OR_GREATER, the netstandard2.0 build keeps the old behaviour. Closes #7552.
Same results as before:UnwrapTupleAot already used ITuple on these targets, so the result is the same for reference and value singletons, for non-tuples and for null rows.
Tests: the allocation regression tests for null and non-null rows are a good addition. They can be flaky across runtimes or tiered JIT, so make sure they warm up and compare against a small threshold, not an exact byte count.
Optional cleanup: this file now has several #if NET5_0_OR_GREATER || NETCOREAPP3_0_OR_GREATER blocks, each doing value is ITuple. If this area is touched again, one internal TryGetITuple helper would remove that repetition. It isn't needed for this PR.
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
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.
Singleton reference-tuple binding copied every row into an element array just to distinguish a null element from a null row. Inspect
ITuple.Lengthand the singleton element directly instead. Keep the existing extraction fallback for targets withoutITuple, and leave mutable-element reconstruction unchanged.Closes #7552
Allocation measurements on .NET 10.0.403, macOS arm64, Release, using a cached delegate to
ShouldFlattenErasedTuple, pre-created rows/metadata, 10,000 warmup calls and 100,000 measured calls (GC.GetAllocatedBytesForCurrentThread):Flattening decisions were unchanged for every measured case. No target-classification cache was added. The netstandard2.0 fallback retains its existing behavior and allocation profile.
Validation:
DataSourceHelpersTests(9 tests, including null/non-null allocation regressions);PreservedGenericTupleTests(20),GenericMutableTupleInitializerTests(10), andGenericTupleDataSourceTests(1), each in generated and reflection discovery on net10.0. Release Core builds pass for net10.0 and netstandard2.0. Existing build warnings were reported on #7410.Native AOT: Release publish for osx-arm64 succeeded; the published executable passed
PreservedGenericTupleTests(20) andGenericMutableTupleInitializerTests(10). Existing publish diagnostics were reported on #7493.Rebased onto main after #7603 merged. Its STA snapshot corrections are already upstream, so this PR now changes only the tuple helper and its allocation regression tests. The earlier diagnostic AOT run 41900939879 passed, including Windows engine tests; #7554 remains a separate intermittent-hang investigation.
Summary by CodeRabbit
nullare handled when tuple data is flattened, so null-valued elements are not mistaken for a different tuple shape.