Closed drieseng closed 6 years ago
If this approach is ok, I'll speed up the Pattern(…)
overloads (that take an array) as well.
Where is the performance benefit coming from? Are there specific cases that are no longer copying, or is it from using Array.Clone?
I wonder why ToArray doesn't use Array.Clone internally if it is faster.
Where is the performance benefit coming from? Are there specific cases that are no longer copying, or is it from using Array.Clone? I wonder why ToArray doesn't use Array.Clone internally if it is faster.
The speedup comes from the fact that previously an array was passed to - for example - ParameterPartCore(…)
as an IEnumerable\ToArray<T>()
extension method was invoked. This one treats an array of T as an ICollection\
This was even done when we knew the array was empty, and as such no copy was necessary. Now the copy (clone) is done on the caller size, and the resulting array is then passed to ParameterPartCore(…)
as an array. There's no Linq involved in the array case, and no virtual dispatch.
In case of factory method that does not take an array or IEnumerable, we avoid the copy altogether. This explains why the (micro)benefit is bigger for - for example - the ParameterPart_Name benchmark.
Unrelated, but why doesn't the template for MatcherAzureBenchmarkBase combine multiple HTTP methods for a given endpoint in a single RouteEndpoint with a HttpMethodMetadata containing all HTTP methods for that endpoint? Wouldn't this be more representative?
Currently we have this:
...
Endpoints[138] = CreateEndpoint("/portalsettings/signin", "PUT");
Endpoints[139] = CreateEndpoint("/portalsettings/signin", "PATCH");
Endpoints[140] = CreateEndpoint("/portalsettings/signin", "GET");
...
Wouldn't this be more representative?
No not really. Typically these would be separate action methods.
Use
Array.Clone()
to copy arrays, and avoid copy on overloads that do not take an array as argument (but would previously result in aIEnumerable<TSource>.ToArray()
on an empty array).Before:
After: