Skip to content

Conversation

@TimothyMakkison
Copy link
Contributor

Convert AfterHookExecutionFlags to struct,

Before

image

After

image

@thomhurst
Copy link
Owner

Summary

Converts AfterHookExecutionFlags from a reference type (class) to a value type (struct) for performance optimization.

Critical Issues

None found ✅

Suggestions

Performance consideration: The struct is instantiated in DecrementAndCheckAfterHooks (line 58) which is called for every test completion - a hot path. The conversion to struct is good, but consider whether the three bool properties could be represented more efficiently:

  • Current: 3 bools = 3 bytes (likely padded to 4+ bytes)
  • Alternative: Single byte with flags = 1 byte

Example:

[Flags]
internal enum AfterHookExecutionFlags : byte
{
    None = 0,
    ShouldExecuteAfterClass = 1 << 0,
    ShouldExecuteAfterAssembly = 1 << 1,
    ShouldExecuteAfterTestSession = 1 << 2
}

This would reduce allocation size by ~75% in a hot path. However, if the current approach is clearer and the perf difference is negligible in benchmarks, the readability benefit may outweigh the micro-optimization.

Verdict

APPROVE - No critical issues

@thomhurst thomhurst merged commit ffbe92d into thomhurst:main Jan 21, 2026
7 of 10 checks passed
This was referenced Jan 25, 2026
This was referenced Jan 26, 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