Draft
Conversation
Owner
Author
|
inlining TryGet does not eliminate allocs. An alternative is to make TryGet an extension method, and in the extension method use the ICache comparer to do the check, then call GetAltLookup where the inlining trick works. |
Owner
Author
|
Tested both LRU and LFU end to end:
|
Owner
Author
|
Also tried this (including forcing the return type to always be the same struct), but does not devirtualize on .NET 10: [MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool TryGetAlternateLookup<TAlternateKey>([MaybeNullWhen(false)] out IAlternateLookup<TAlternateKey, K, V> lookup)
where TAlternateKey : notnull, allows ref struct
{
AlternateLookup<TAlternateKey> alt = AlternateLookup<TAlternateKey>.Empty;
if (this.dictionary.IsCompatibleKey<TAlternateKey, K, I>())
{
alt = new AlternateLookup<TAlternateKey>(this);
lookup = alt;
return true;
}
lookup = alt;
return false;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public (bool, IAlternateLookup<TAlternateKey, K, V>)TryGetAlternateLookup2<TAlternateKey>()
where TAlternateKey : notnull, allows ref struct
{
if (this.dictionary.IsCompatibleKey<TAlternateKey, K, I>())
{
return (true, new AlternateLookup<TAlternateKey>(this));
}
return (false, AlternateLookup<TAlternateKey>.Empty);
} |
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.
Inlining GetAlternateLookup eliminates the heap allocation for the AlternateLookup struct on .NET 10:
From https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-10/runtime