3 ms·
Looking further into it (I really want my program to run faster!), looks like 7 produces unoptimized code. Could it be that it decided for me that I want fast
by EVa5I7bHFq9mnYK 4y ago
Looking further into it (I really want my program to run faster!), looks like 7 produces unoptimized code. Could it be that it decided for me that I want faster startup vs faster code? Can I force it to turn optimizations on somehow?
- neonsunset 4y agoIf you do only a couple of iterations it will not optimize it. Loops can be now optimized in-flight thanks to on-stack replacement feature which should help with startup time and also allow to apply Tier-1 compilation with more optimizations should the loop become hot (e.g. can't elide static initialization checks if you go straight to full optimized without Tier 0 -> Tier 1). To get more representative data it is best to either use BenchmarkDotNet or profile code close to real life case.
- EVa5I7bHFq9mnYK 4y agoI see. So I just inserted <TieredCompilation>false</TieredCompilation> into project file and it fixed it. Runs as fast as 6.
- neonsunset 4y agoPlease do not use this. JIT is designed with tiered compilation in mind for a long time. I cannot stress this enough, the number in the above comment is not representative. Using this setting is highly discouraged. Please use BenchmarkDotNet to get accurate numbers!
- EVa5I7bHFq9mnYK 4y agomy program's main purpose is not running benchmarks)
- neonsunset 4y agoThere is no doubt but if you would like to accurately compare a part of your code on 6 vs 7 then the best practice is to use BDN with [SimleJob(RuntimeMoniker.Net60)] and [SimleJob(RuntimeMoniker.Net70)]. Make sure to set project to multi-target both versions. That way you will see actual difference, feel free to also add [MemoryDiagnoser] and [DisassemblyDiagnoser(exportCombinedDisassemblyReport: true)].
- andyayers 4y agoFeel free to open an issue for this over at github.com/dotnet/runtime, if you have code you can share.