3 ms·
IIRC escape analysis in HotSpot won’t actually allocate the whole object on the stack. It’ll explode the object into its sub fields and store them in registers
by vips7L 3y ago
IIRC escape analysis in HotSpot won’t actually allocate the whole object on the stack. It’ll explode the object into its sub fields and store them in registers or spill them into the stack if register pressure is high.
- astrange 3y agoThis is a common optimization in any compiler, not just HotSpot. Although it's more important and more extensive in the JVM where almost everything is a heap allocation, yes. (Although the technical term isn't "escape analysis"; that just covers analysis, not resulting optimization.) I've noticed Microsoft seems to think ordinary compiler optimizations are deep magic they're very proud of not implementing. Do they just not have good enough compiler people?
- vips7L 3y ago> Although the technical term isn't "escape analysis"; that just covers analysis, not resulting optimization. Yeah I meant scalar replacement!
- neonsunset 3y ago> I've noticed Microsoft seems to think ordinary compiler optimizations are deep magic they're very proud of not implementing. Do they just not have good enough compiler people? What in our discussion has prompted you to respond with an ad-hominem attack?
- astrange 3y agoThat's not an attack, unless you designed .NET, in which case I'm of course referring to your recruiters and not you. Anyway, it's the part about how C# doesn't need to implement scalar replacement because it has structs. Do it anyway, it's good! But I've also noticed (reading some .NET developer blog post I couldn't find for you now) them talking about how they couldn't do inlining because it would take too long and be too slow, so they put some very simple heuristics that did not look like a good trade off. Inlining of course is often very beneficial and can decrease code size.
- neonsunset 3y agoWell, this kind of attitude is just sad. Rather than imagining issues .NET has without verifying them first and then complaining, I'd like to suggest to spot check assumptions with Godbolt[0] which would be a good start (it can't show DynamicPGO, NativeAOT-specific and some other opts but is still fairly illustrative). A more comprehensive view of produced asm can be acquired with [DisassemblyDiagnoser] attribute when running code with BenchmarkDotNet [1] (in the Java world a similar solution is called JMH). [0] https://godbolt.org/ https://godbolt.org/ [1] https://benchmarkdotnet.org/articles/guides/getting-started.html https://benchmarkdotnet.org/articles/guides/getting-started....