Skip to content

Reduce render argument allocations - #979

Closed
sebastienros wants to merge 1 commit into
mainfrom
sebros/reduce-render-scope-allocations
Closed

Reduce render argument allocations#979
sebastienros wants to merge 1 commit into
mainfrom
sebros/reduce-render-scope-allocations

Conversation

@sebastienros

@sebastienros sebastienros commented Aug 19, 2026

Copy link
Copy Markdown
Owner

The scope-management rewrite merged in #981 already removes the redundant render scope allocation. Named render arguments still allocate a temporary KeyValuePair[] on every execution, even though most calls pass only one or two arguments.

Approach

  • Keep one- and two-argument values inline without temporary arrays.
  • Rent cleared FluidValue[] storage only for three or more arguments and return it on both success and failure.
  • Continue evaluating every expression and Assigned callback in the caller scope before publishing any argument into the isolated render scope.
  • Add callback-order/error-cleanup coverage and a focused two-argument BenchmarkDotNet case.

Benchmark

BenchmarkDotNet 0.15.8, .NET 10.0.11 Arm64, Apple M4 Pro, in-process toolchain, 3 warmup and 5 measurement iterations:

Shape origin/main This change Difference
Two named render arguments 207.2 ns / 744 B 212.1 ns / 688 B -56 B (-7.5%)

The timing confidence intervals overlap (198.3-216.1 ns baseline and 207.8-216.5 ns after), so this is treated as allocation-neutral throughput rather than a speed improvement. A pool-only two-argument version measured 218.5 ns / 688 B; inline storage was retained for the common case, with pooling reserved for larger argument sets.

Validation

  • Targeted interpreted and compiled render tests: 3 passed in each mode
  • dotnet test --no-restore: 2,750 passed, 20 skipped, 0 failed
  • dotnet test --no-restore /p:Compiled=true: 2,750 passed, 20 skipped, 0 failed
  • Release build of Fluid: netstandard2.0, net8.0, net9.0, and net10.0 with no warnings or errors

This PR now targets main directly because #981 merged the preceding scope-management layer.

Store the common one- and two-argument render cases inline and use cleared pooled storage for larger argument sets while preserving caller-side evaluation and callback ordering. Add focused callback cleanup coverage and a two-argument benchmark.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>

Copilot-Session: ed283205-128c-47d0-874c-2f48e363bdf8
@sebastienros
sebastienros changed the base branch from sebros/flush-outer-render-boundary to main August 19, 2026 03:39
@sebastienros
sebastienros force-pushed the sebros/reduce-render-scope-allocations branch from a61c782 to caaeb4f Compare August 19, 2026 03:39
@sebastienros sebastienros changed the title Reduce render scope allocations Reduce render argument allocations Aug 19, 2026
@sebastienros

Copy link
Copy Markdown
Owner Author

Closing because this performance work is investigatory only; commit caaeb4f remains available on the branch for traceability.

@sebastienros
sebastienros deleted the sebros/reduce-render-scope-allocations branch August 19, 2026 04:22
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