In our project these 2 methods are very hot. They are near-optimal algorithmically but implementation
wasn't efficient due to use of convenient abstractions and JIT in netframework4.7.2 being not very sophisticated.
(dotnet7 optimizes original code a lot better, but due to various reasons we can't migrate to it yet).
List of micro-optimizations in no particular order:
ReadOnlyArray<> now returns values by reference
It means it can't implement IReadOnlyList<> interface anymore. But it wasn't used through interface anywhere anyway
GenerationalDictionary<> now accesses hash-table cells by reference
GenerationalDictionary.GetOrAdd() method added which replaces 2 calls to TryGetValue()+Add()
Automaton.Builder now manages its dynamically growing arrays on its own instead of using List<>.
This reduces indirection and allows to access elements by reference
Automaton.Transition.ElementDistribution is not Option anymore. Boxing of
element distribution into Option<> was not optimized out by JIT.
New API is a little less safe (because this property can be used only for non-epsilon transitions) but more efficient.
Transition.OptionalElementDistribution property was added for non-performance critical parts of the code.
StringManipulator is now a struct (value type). It allows to monomorphize generic class and inline calls to its methods.
With classes (reference types) calls had to be dynamically dispatched.
Automaton.Product() and TransducerBase.ProjectSource() were rewritten without use of StateCollection, State
and ReadOnlyArraySegment<> types. These types provided convinient APIs but JIT was not ablet to eliminate
their overhead.
This PR speeds up methods mentioned in PR title by about 30%.
In our project these 2 methods are very hot. They are near-optimal algorithmically but implementation wasn't efficient due to use of convenient abstractions and JIT in netframework4.7.2 being not very sophisticated. (dotnet7 optimizes original code a lot better, but due to various reasons we can't migrate to it yet).
List of micro-optimizations in no particular order:
This PR speeds up methods mentioned in PR title by about 30%.