[WIP] Performance improvements to Span.Slice#23665
[WIP] Performance improvements to Span.Slice#23665GrabYourPitchforks wants to merge 1 commit intodotnet:masterfrom
Conversation
|
/cc @dotnet/jit-contrib as FYI, @stephentoub, @jkotas |
|
How hard is this to fix it in the JIT? |
|
The managed changes are very straightforward - use unsigned instead of signed integers when performing byref arithmetic. A shift-F12 on Edit for clarification: We can't just do a search-and-replace on the managed side since there are valid scenarios where a caller might have wanted to use signed byref arithmetic. But my gut tells me that the majority of call sites only ever pass non-negative values and would be eligible candidates to call the unsigned API over the signed API. |
|
I have looked at the asm delta for |
|
@jkotas - I also hacked the JIT to eliminate the |
|
I don't think there is an easy fix in the jit. There are a bunch of inter-related issues we should tackle in a coordinated fashion:
|
|
Looks like this isn't needed since per Andy's comments there are tracking issues that will improve the JIT all-around. Closing this. |
This updates
Span<T>.SliceandReadOnlySpan<T>.Sliceto zero-extend rather than sign-extend the index when computing the new base address. It's a proof of concept demonstrating the performance gains we can get from addressing https://github.com/dotnet/coreclr/issues/23666. I hacked together a prototype that performsmovelimination in all cases, then re-introduced this PR and reran the benchmarks to come up with the following results.I didn't change the other overloads of
Slicebecause I couldn't create a benchmark that clearly demonstrated a perf win.