Skip to content

Conversation

@TimothyMakkison
Copy link
Contributor

@TimothyMakkison TimothyMakkison commented Jan 19, 2026

Defer initialisation of Queue in DedicatedThreadExecutor

I tried this with List<Task> _taskQueue and didn't see an improvement, presumably it will always contain at least one object so deferring is useless.

Before

image

After

image

@thomhurst
Copy link
Owner

Summary

Defers Queue allocation in DedicatedThreadSynchronizationContext to reduce memory allocations when the work queue is never used.

Critical Issues

None found ✅

Suggestions

None - this is a solid performance optimization that aligns with TUnit's "Performance First" principle. The lazy initialization pattern is correctly implemented with proper null checks and thread-safe initialization under the existing lock.

Verdict

APPROVE - No critical issues

The change demonstrates:

  • Reduced allocations in hot path (aligns with CRITICAL RULE And assertion conditions #4)
  • Thread-safe lazy initialization
  • Proper null handling in ProcessPendingWork
  • Measurable performance improvement shown in benchmarks

@TimothyMakkison
Copy link
Contributor Author

Is the modular pipelines check broken? #4508 is also failing because of a weak refernce check failiure in NET framework

@thomhurst
Copy link
Owner

Is the modular pipelines check broken? #4508 is also failing because of a weak refernce check failiure in NET framework

I think it's a flaky test that I need to look into

@thomhurst thomhurst merged commit 651d2bc into thomhurst:main Jan 19, 2026
8 of 10 checks passed
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