Skip to content

Conversation

@TimothyMakkison
Copy link
Contributor

Pass action into StartNew eliminating allocation of Func<TResult> and associated closure

Before

image

After

image

@thomhurst
Copy link
Owner

Summary

Eliminates closure and Func allocation in DedicatedThreadExecutor by passing action as a parameter to StartNew instead of capturing it.

Critical Issues

None found ✅

Suggestions

None - this is a clean performance optimization with measurable benefit in a hot path.

Verdict

APPROVE - No critical issues

The static lambda + parameter passing approach correctly eliminates the closure allocation while maintaining the same behavior. The cast back to Func<ValueTask> is safe since we're passing the original typed parameter through StartNew's object state parameter.

@thomhurst thomhurst enabled auto-merge (squash) January 17, 2026 00:13
auto-merge was automatically disabled January 17, 2026 01:12

Head branch was pushed to by a user without write access

@thomhurst thomhurst enabled auto-merge (squash) January 17, 2026 01:16
@thomhurst thomhurst merged commit e6e1525 into thomhurst:main Jan 17, 2026
9 of 10 checks passed
This was referenced Jan 19, 2026
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.

2 participants