Skip to content

Ensure all structs that implement an interface used as a type constraint implement all methods - #2013

Open
TedHartMS wants to merge 3 commits into
mainfrom
tedhar/struct-constraint
Open

Ensure all structs that implement an interface used as a type constraint implement all methods#2013
TedHartMS wants to merge 3 commits into
mainfrom
tedhar/struct-constraint

Conversation

@TedHartMS

Copy link
Copy Markdown
Contributor

This pull request extends the fix in PR #1988 to eliminate unnecessary boxing by explicitly implementing interface members—particularly default interface methods (DIMs)—in key structs and record trigger implementations. By directly implementing these members, calls through generic constraints will resolve to the struct's own methods, improving performance and avoiding the overhead of boxing. Additionally, all key structs now explicitly implement the IsEmpty property.

The most important changes are:

Performance improvements through explicit interface implementations:

  • Explicitly implemented default interface methods (DIMs) for IRecordTriggers and related interfaces in various structs (e.g., OnDispose, OnFlush, OnEvict, OnDiskRead, OnRecovery, OnCheckpoint, PostCopyToTail, OnTruncate) to ensure generic constraint calls resolve without boxing, both in production and test code. [1] [2] [3] [4] [5] [6] [7]

  • Implemented PhysicalAddress explicitly in LogRecord and DiskLogRecord to avoid boxing when accessed through ISourceLogRecord. [1] [2]

Key interface consistency:

  • Added an explicit implementation of the IsEmpty property (always returning false) to all IKey structs in both production and test code, ensuring interface contract consistency and avoiding default interface dispatch. [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11]

Code clarity and documentation:

  • Added or updated comments to clarify the rationale for explicit interface implementations, highlighting the avoidance of boxing and improved performance. [1] [2] [3] [4]

These changes collectively improve runtime efficiency and code clarity by ensuring interface methods are resolved to struct implementations without incurring boxing costs.

@TedHartMS
TedHartMS requested review from badrishc and Copilot and removed request for Copilot August 3, 2026 18:03
@TedHartMS TedHartMS changed the title Tedhar/struct constraint Ensure all structs that implement an interface used as a type constraint implement all methods Aug 3, 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