Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Improve encoding performance #10124
This is low-risk stop gap measure to improve encoding performance because of we may not have enough time to improve the test coverage (dotnet/corefx#16334) and refactor to code to use corefxlab high-performance encoding routines for 2.0.
The change is to avoid passing the key loop control variables by ref to the invalid character fallback routines. Taking address of a variable prevents RuyJIT from enregistering it.
Results: UTF8 decoding 1k of ASCII characters is 1.65x faster, similar for other affected codepaths.
The analysis to prove that the address taken does not escape gets complex fast. The JIT does a little bit of it today, the C/C++ optimizing backends do some more of it; but you never want to take address of your perf critical loop control locals in any case and you need to structure your code accordingly.
The encoding fallback implementation is pretty poorly structured. I hope we will get a chance to refactor it as part of aligning the implementation with the corefxlab one. The fallback support were not in the code when I have fine tuned the encoding originally. They were added together with the ref on the perf critical locals later by somebody who did not know what he is doing.