Ensure all structs that implement an interface used as a type constraint implement all methods - #2013
Merged
Merged
Conversation
…ctions fully implement all interfaces that that form those type constraints
TedHartMS
requested review from
badrishc and
Copilot
and removed request for
Copilot
August 3, 2026 18:03
badrishc
approved these changes
Aug 3, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the earlier “avoid boxing via default interface methods (DIMs) on structs under generic constraints” work by adding concrete struct implementations for interface members that were previously relying on DIMs. This ensures constrained generic calls bind to the struct methods/properties (no boxing) across Tsavorite core, Garnet, and associated tests/benchmarks.
Changes:
- Added explicit struct implementations of
IRecordTriggersmembers (no-ops/defaults) in core and test trigger structs to avoid DIM dispatch/boxing underTRecordTriggers : IRecordTriggers. - Added explicit implementations for
ISourceLogRecord.PhysicalAddressandIKey.IsEmptyinLogRecord/DiskLogRecord(andIsEmptyin various test/benchmarkIKeystructs) to avoid DIM dispatch/boxing underTKey : IKey/TSourceLogRecord : ISourceLogRecord. - Added a no-op
OnDisposeDiskRecordimplementation inGarnetRecordTriggersto avoid DIM dispatch/boxing for disk-record disposal paths.
Reviewed changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| libs/storage/Tsavorite/cs/src/core/Index/StoreFunctions/IRecordTriggers.cs | Adds explicit no-op implementations in default trigger structs to prevent DIM-based boxing under TRecordTriggers. |
| libs/storage/Tsavorite/cs/src/core/Allocator/LogRecord.cs | Implements ISourceLogRecord.PhysicalAddress and IKey.IsEmpty directly on LogRecord. |
| libs/storage/Tsavorite/cs/src/core/Allocator/DiskLogRecord.cs | Implements ISourceLogRecord.PhysicalAddress and IKey.IsEmpty directly on DiskLogRecord. |
| libs/server/Storage/Functions/GarnetRecordTriggers.cs | Adds explicit no-op OnDisposeDiskRecord to avoid DIM dispatch/boxing. |
| libs/server/Resp/MGetReadArgBatch.cs | Keeps IReadArgBatch DIM-avoidance explicit implementations; minor formatting/comment adjustment. |
| libs/storage/Tsavorite/cs/test/TestTypes.cs | Adds IKey.IsEmpty implementation on test key structs. |
| libs/storage/Tsavorite/cs/test/TestSpanByteKey.cs | Adds IKey.IsEmpty implementation on test span-byte key. |
| libs/storage/Tsavorite/cs/test/test.session/ReadAddressTests.cs | Adds IKey.IsEmpty implementation on a local test key struct. |
| libs/storage/Tsavorite/cs/test/test.recordops/RecordLifecycleTests.cs | Adds explicit no-op/default IRecordTriggers members to avoid DIM boxing in tests. |
| libs/storage/Tsavorite/cs/test/test.recordops/DeleteDisposeTests.cs | Adds explicit no-op/default IRecordTriggers members to avoid DIM boxing in tests. |
| libs/storage/Tsavorite/cs/test/RecoveryTestTypes.cs | Adds IKey.IsEmpty implementation on recovery test key. |
| libs/storage/Tsavorite/cs/test/RecordTriggersExtTests.cs | Adds explicit no-op IRecordTriggers members to avoid DIM boxing in tests. |
| libs/storage/Tsavorite/cs/test/ObjectTestTypes.cs | Adds IKey.IsEmpty implementation on object test key. |
| libs/storage/Tsavorite/cs/benchmark/YCSB.benchmark/KeySpanByte.cs | Adds IKey.IsEmpty implementation for benchmark keys. |
| libs/storage/Tsavorite/cs/benchmark/YCSB.benchmark/FixedLengthKey.cs | Adds IKey.IsEmpty implementation for benchmark keys. |
| libs/storage/Tsavorite/cs/benchmark/KV.benchmark/KvKey.cs | Adds IKey.IsEmpty implementation for benchmark keys. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
IsEmptyproperty.The most important changes are:
Performance improvements through explicit interface implementations:
Explicitly implemented default interface methods (DIMs) for
IRecordTriggersand 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
PhysicalAddressexplicitly inLogRecordandDiskLogRecordto avoid boxing when accessed throughISourceLogRecord. [1] [2]Key interface consistency:
IsEmptyproperty (always returningfalse) to allIKeystructs 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:
These changes collectively improve runtime efficiency and code clarity by ensuring interface methods are resolved to struct implementations without incurring boxing costs.