4 ms·
Wait, ignore soundness? How does that work/provide advantage?
by pvg 7y ago
Wait, ignore soundness? How does that work/provide advantage?
- zlynx 7y agoA function could be compiled assuming the passed argument is always 2. All of the code for other values is just left out. As long as the compiled code has a check for values that are not 2 this code works great. It isn't correct though. At least, that's my interpretation.
- pvg 7y agoMaybe I'm getting tripped up in the terminology here but to me this case is still a JIT jittin' - you look at runtime data and decide it's worth it to crank out a special case optimization for the input of 2. You produce that that optimization, which is sound along with a check to make sure it is applied only in the special case. You get to defer other optimization. The advantage here still seems to come from the runtimeness of things rather than from being clever about soundness and there's really no guessing about soundness. So perhaps that's not it.
- chrisseaton 7y ago> to me this case is still a JIT jittin' I think the point is that some JITs never do this kind of optimisation - they just produce the same code an AOT compiler would, but at runtime. Such as the .NET JIT.
- pvg 7y agoI don't think that's the point the comment I'm replying to is making, or at least, it's not the point I'm asking about. Edit: Your example in the other comment about the locks is the sort of thing I'm asking about. There, an optimization is made which is sound under some specific conditions and then unmade when those conditions change.
- marvy 7y agoI think that is indeed the point pron was making, or at least similar. You can't actually ignore soundness, but JVMs sometimes go farther than I'd expect. (Example: don't check for null, just handle SIGBUS if null is "very rare")
- pvg 7y agoYes, on re-reading the thread again it might be entirely (or almost) about language. As in, it's really something along the lines of 'The power of the JIT approach comes from runtime information and dynamism. But you can also be a 'just' a JIT without making use of any of that'. And I'm getting stuck on 'secret weapon [...] soundness' and imagining some unfathomable-to-mortals ninja something.
- pjmlp 7y agoI guess you need to update your knowledge regarding the several .NET JITs in use.
- chrisseaton 7y agoAs I cautioned in another comment > (or did, last time I checked) Do implementations of .NET JITs now do speculative optimisations or dynamic compilation? They didn't see the need for it for about 15 years.
- pjmlp 7y ago15 years ago there weren't RyuJIT which replaced the JIT you learned from, MDIL (Windows 8/8.1), .NET Native (UWP), IL2CPP (Unity), and the research ones from Singularity and Midori. In what concerns the need for it, they have been trying to make C# more relevant for the kinds of C++ workloads and getting among the first places at TechEmpower. So .NET has been getting Modula-3 like low level handling of value types within a GC environment, RyuJIT is now tiered, supports SIMD and some automatic vectorization. .NET Framework 4.6 got the first version of what is the .NET way of doing AppCDS. There are a couple of blog posts regarding RyuJIT improvements with each release after its introduction.
- chrisseaton 7y agoSo which of these implementations does speculation? I remember when RyuJIT came out it still wasn't speculative - has that now changed? If you read the blog posts, they always talk about speculation being something they may try in the future. I've not seen anything where they say they went ahead and implemented it.
- pjmlp 7y agoHere is some information Background JIT overview, which is a kind of PGO for the .NET Frameworok https://msdn.microsoft.com/en-us/magazine/mt683795.aspx https://msdn.microsoft.com/en-us/magazine/mt683795.aspx And I think this goes into line with what you are discussing, https://github.com/dotnet/coreclr/pull/21270 https://github.com/dotnet/coreclr/pull/21270 I also agree that many things remain to be done in line with what Graal is capable of.
- ddragon 7y agoFor example a JIT compiler can, based on the runtime information + inference, discard multiple branches of a function that are effectively pointless and possibly even just inline the results if given those inputs the function is deterministic. Of course, the function it compiled will actually not work with any different but still valid arguments, but that's not really trouble since the JIT compiler will simply evaluate that the already compiled version won't work for those as the function is called and compile a new version of the function for the new types just before. A pure ahead-of-time compiler wouldn't be able to optimize so aggressively since it would lead to an exponential explosion of possible inputs combinations most of which will very likely never happen.
- pvg 7y agoI put it in a bit more detail in a sibling comment but to me, there's no 'guessing about soundness and being wrong' in that particular scenario.
- ddragon 7y agoI guess it depends on the perspective and interpretation of soundness. If a JIT-compiler AoT compiles your entire program but infers that your function that implements logic that works for every number (as you defined it using the Number interface within the rules of it's type system) will only use 32 bits integers, then it will compile code that effectively does not hold up to the property that was established. The fact that it will stop execution the moment it reaches an invalid path and correct it doesn't change that.
- pvg 7y agoIt could be and that would be uninteresting. But it's not hard to come up with a (contrived, limit-casey) optimization approach that does actually make guesses about soundness. Let's say you wanted to optimize a short instruction sequence with a small domain of inputs. You could try to generate all (or at least, zillions) of similarly-sized possible instruction sequences and check them for soundness and performance. Now you're really making soundness guesses. Do real JITs actually make that sort of soundness guess (not that kind of attempt at optimization, obviously)?