Skip to content

Reduce fixed allocations in middleware pipeline terminal paths - #56

Merged
dombrovsky merged 1 commit into
mainfrom
perf/reduce-terminal-pipeline-allocations
Oct 25, 2026
Merged

dombrovsky merged 1 commit into
mainfrom
perf/reduce-terminal-pipeline-allocations

Conversation

@dombrovsky

Copy link
Copy Markdown
Owner

Middleware dispatch creates continuation closures even when no matching middleware remains. Split terminal dispatch from the methods that capture continuation state, and remove the terminal context object used only to read back the supplied cancellation token.

Activity tracking, continuation validation, cancellation propagation, and disposal behavior remain in place. This is a small allocation optimization; it does not remove the per-layer ownership wrappers responsible for most of the regression against 1.0.0.

BenchmarkDotNet 0.15.8 on .NET 10.0.13 measured about 128 fewer bytes per operation with middleware:

Layers Before After
0 512 B 512 B
1 1,790 B 1,663 B
2 2,415 B 2,287 B
4 3,664 B 3,536 B
8 6,160 B 6,031 B

Timing measurements were noisy, so no latency improvement is claimed.

Validation:

  • Solution restore/build, whitespace verification, and IDE0161 namespace verification completed successfully.
  • 86 focused lifetime, middleware, execution-token, cancellation, and disposal tests passed on each of .NET 8 and .NET 10.
  • All extension test suites passed on both runtimes.
  • The full core suite was not green: 8 failures on .NET 8 and 7 on .NET 10, including cancellation and timing-sensitive tests. Cancellation failures also reproduced on the untouched baseline; the disposal timeout assertion passed in the focused rerun. These failures are left outside this optimization's scope.

@dombrovsky
dombrovsky merged commit 36a1b62 into main Oct 25, 2026
9 checks passed
@dombrovsky
dombrovsky deleted the perf/reduce-terminal-pipeline-allocations branch October 25, 2026 23:20
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