Improve linker performance by avoiding IndexOf - #90721
Conversation
|
Tagging subscribers to 'linkable-framework': @eerhardt, @vitek-karas, @LakshanF, @sbomer, @joperezr, @marek-safar Issue DetailsFixes #90717 @sbomer @vitek-karas These edits are done online as I currently don't have a local fork of runtime. In case this needed more changes or refactoring, would you be able to take it over?
|
| for (int i = firstInstr; i <= lastInstr; i++) { | ||
| if (instructions[i] == target) { | ||
| return true; | ||
| } | ||
| } |
There was a problem hiding this comment.
This loop will have maximum of three iterations. This is a lot better than IndexOf which will search through the whole instructions collection which can have thousands of elements.
There was a problem hiding this comment.
Should we even bother with the lookup then?
Can we measure this - if the lookup doesn't bring interesting perf wins I would vote for keeping it simple and just do the linear search over the known possible range (that should be really fast).
There was a problem hiding this comment.
@vitek-karas I'm not sure about the logic and wanted to avoid potentially changing the meaning of the code, e.g, I have no idea if the dictionary lookup could yield a different result than the loop. So, I wanted to make a change that is clear it doesn't change the code semantics, and at the same time is more performant.
Regarding measuring this, I currently don't have the dotnet/runtime cloned locally to try something (the changes in this PR are done through GitHub UI actually). But I think the performance trace is quite clear this lookup is problematic, and it also the change should hopefully be making sense as a performance improvement. Yet, I understand that measuring would still be a good idea to at least know how much improvement this is. But unfortunately, I'm not able to do it right now. If necessary, would someone from the team be able to do it?
|
CI failure is looking unrelated to the change here: |
|
failures are known (and resoved) |
Fixes #90717
@sbomer @vitek-karas These edits are done online as I currently don't have a local fork of runtime. In case this needed more changes or refactoring, would you be able to take it over?