Optimize replace_first, replace_last, and truncate#523
Conversation
- Leverage the string.Concat with ReadOnlySpan<char> on .NET Core 3.0 and above - see https://learn.microsoft.com/en-us/dotnet/api/system.string.concat?view=netcore-3.1#system-string-concat(system-readonlyspan((system-char))-system-readonlyspan((system-char)))
|
Could you please add the benchmark to the PR? |
|
That's a bit of a problem, since the benchmark project is not multi targeted, I copy-pasted the implementation twice just to evaluate it. The code is not good to be merged. |
|
I cleaned up the benchmarks and pushed them. I think they're good to verify the benefits, but should probably not merge them into the |
|
I don't see the point of keeping these benchmarks. And I don't like the fact that the old implementation is in them. My preference is to not have them here. You used them to prove the new implementation is better, good job, that's sufficient. I don't expect someone else to reuse them. We could have a set of benchmarks for all current implementations the day we start tracking it. |
|
Of course he add them to prove it's better ;), if that's sufficient @danielmpetrov please remove them, then we could merge Thanks a lot for your contribution |
This reverts commit d0451cb.
Leverage the
string.ConcatwithReadOnlySpan<char>- see https://learn.microsoft.com/en-us/dotnet/api/system.string.concat?view=netcore-3.1#system-string-concat(system-readonlyspan((system-char))-system-readonlyspan((system-char))), to remove extra allocations. Since the overload was added in .NET Core 3.0, the optimization can only be applied thereafter (unless we shim the method).The following scenarios were benchmarked for
replace_firstandreplace_lastThe following scenarios were benchmarked for
truncate