Skip to content

Conversation

@TimothyMakkison
Copy link
Contributor

Small change, Lock is slightly faster that using object, but the main advantage is that it declares intent.

@thomhurst
Copy link
Owner

Summary

This PR replaces object lock instances with the modern Lock type for improved performance and clearer intent across 5 files in the TUnit.Core and TUnit.Engine projects.

Critical Issues

None found

Analysis

The changes are straightforward and appropriate.

What was changed:

  • TUnit.Core/Tracking/ObjectTracker.cs:24
  • TUnit.Engine/Scheduling/ConstraintKeyScheduler.cs:42, 133
  • TUnit.Engine/Services/AfterHookPairTracker.cs:20-21
  • TUnit.Engine/Services/BeforeHookTaskCache.cs:17-18
  • TUnit.Engine/Services/TestDependencyResolver.cs:20

TUnit Rules Compliance:

  • Performance First: The Lock type provides better performance than object for locking, aligning with TUnit's performance-first principle. These changes are in hot paths.
  • AOT Compatible: Lock is fully AOT-compatible.
  • Multi-targeting Support: The Polyfill package (v9.7.3) provides System.Threading.Lock polyfill for older target frameworks.
  • No dual-mode concerns: Changes are only in TUnit.Engine and TUnit.Core, not in source generators.
  • No snapshot updates needed: No source generator output or public API changes.

Verdict

APPROVE - Clean performance improvement with no issues. The change aligns perfectly with TUnit's Performance First and use modern features principles.

@thomhurst thomhurst merged commit 25a2321 into thomhurst:main Jan 17, 2026
9 of 10 checks passed
This was referenced Jan 18, 2026
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