Open stephentoub opened 1 year ago
Would tries be useful in some situations for strings? Should we consider doing reflection emit code gen in some circumstances?
After I saw that routing in ASP.NET Core uses reflection emitted Trie, I also spent some time attempting to implement an alternative to stringly-keyed ASCII FrozenDictionary
in a similar way. After lots of attempts, I no longer think it's possible for Tree structures to be faster than Hash based data structures in general purpose use-cases. However the IL-Emit Trie did indeed come out faster than the FrozenDictionary
in my small experiments.
It's something we'll consider for .NET 9.
Is it being considered for .NET 9?
It's something we'll consider for .NET 9.
Is it being considered for .NET 9?
Unlikely at this point.
Any chance of considering adding something like:
FrozenSortedSet<T>
FrozenSortedDictionary<T>
IEnumerable<T>.ToFrozenSortedSet<T>
IEnumerable<T>.ToFrozenSortedDictionary<T>
?Perhaps via analogous methods such as those for .ToImmutableSortedDictionary/Set()
Any chance of considering adding something like:
FrozenSortedSet<T>
FrozenSortedDictionary<T>
IEnumerable<T>.ToFrozenSortedSet<T>
IEnumerable<T>.ToFrozenSortedDictionary<T>
?Perhaps via analogous methods such as those for
.ToImmutableSortedDictionary/Set()
What functionality are you hoping for here? Specifically just that the exposed Items and Key/Value arrays are sorted and that enumerating happens in that order as well?
@stephentoub exactly.
I have a ConcurrentDictionary that I accumulate into and then need to read from ordered by key, as quickly as possibile (using this for some UDP traffic re-ordering, the dictionary is a ConcurrentDictionary<long, (int packetOffset, int packetLength)>
, that keeps track of offsets in a Memory<byte>
buffer... linear, I know, but I'm not expert enough to know how to do this with a ring buffer with pooled memory alocations avoiding GC... any ideas on this?).
Right now I'm using .ToImmutableSortedDictionary()
, but from what I've understood, a FrozenDictionary would be quicker to enumerate.
What functionality are you hoping for here? Specifically just that the exposed Items and Key/Value arrays are sorted and that enumerating happens in that order as well?
@stephentoub exactly.
Thanks. In that case, I don't think this warrants or necessitates new types. We could just have the creation of a FrozenDictionary/Set sort the arrays at construction, either using a type's built-in notion of ordering (via IComparable) which could be done without any API additions, or via an extra overload that accepts a Comparer to use for that purpose.
In that case, I don't think this warrants or necessitates new types. We could just have the creation of a FrozenDictionary/Set sort the arrays at construction
That would definitely work, thanks for the feedback @stephentoub .
https://github.com/dotnet/runtime/pull/77799 adds new FrozenDictionary and FrozenSet types. These are in decent shape but not yet ready to ship. Several follow-ups are required:
ImmutableArray<>
. This is to enable access to the data as aReadOnlySpan<>
, indexibility, via refs, and with very fast enumeration. This does, however, place a requirement on implementations that they either store the keys/values/items separately and in contiguous memory or that implementations maintain a second copy of the data that does so. If we'd be willing to give up on theReadOnlySpan<>
and indexing capabilities, these types should instead be changed to someFrozenEnumerable<>
-like type that would allow different implementations to vary how the data was stored.