4 ms·
That's called profile-guided optimisation and most good optimising compilers do it. Not a particularly good example, however the JVM can do it in a slightly dif
by mhh__ 10y ago
That's called profile-guided optimisation and most good optimising compilers do it. Not a particularly good example, however the JVM can do it in a slightly different way because doing PGO on every build/test or in the wild is prohibitively annoying (e.g. The JVM can do it for each time it runs, rather than when the compiler is told to)
- jorgemf 10y agoYou cannot do it before compiling the final executable, you have to do it while running. You can simulate the profiling but you will get the best results when you profile while executing. And I guess it is easier to do profiling in high level language than in low level. Another example is to unroll loops. Probably you know more than my about optimization, but I think the idea is clear here. It is easier to get better gains with high level code and profiling in real time, than with low level code and simulating the profiling.
- mike_hearn 10y agoPGO in C++ is in practice only rarely used, due to the difficulty of setting it up and incorporating it into the build cycle. As a consequence compiler writers rarely focus on it and C++ is designed on the assumption that optimisation is always done statically. So there's a kind of feedback loop there. Java is designed on the assumption that JITC is available and JVM designers focus more on PGO as a result.
- DannyBee 10y ago"PGO in C++ is in practice only rarely used, due to the difficulty of setting it up and incorporating it into the build cycle." This is pretty much false these days. Most folks who care about it use it. You were right 10 years ago. At this point, there are enough companies where 10% perf is tens or hundreds of millions of dollars, and so the world changed. "As a consequence compiler writers rarely focus on it and C++ is designed on the assumption that optimisation is always done statically." Also false as a consequence of the above :) "Java is designed on the assumption that JITC is available and JVM designers focus more on PGO as a result. " But they have less time to perform any of the expensive opts pgo enables. so ...
- mike_hearn 10y agoI'm sure Google does these days, though when I was there PGO wasn't widely used. But even Chrome only started using PGO late last year (15% speed boost!), and Chrome is one of the most intensively optimised apps out there. So I think it's fair to say that most C++ apps built by mere mortal companies probably still don't use it. But I'd be keen to see data showing I'm wrong. Perhaps MSVC++ or LLVM leaves some trace of PGO behind in the binary, and a Windows/Mac machine with lots of apps installed could be scanned to get an idea (for desktop usage at least).
- chubot 10y agoI just saw that Python's Makefile has support for PGO builds: https://github.com/python/cpython/blob/master/Makefile.pre.in#L479 https://github.com/python/cpython/blob/master/Makefile.pre.i... Not sure when it was added, but Python 2.7 has it. It's not clear to me how to tell if say my Ubuntu binary is built with PGO, but it's something I'm looking into.
- DannyBee 10y ago"I'm sure Google does these days, though when I was there PGO wasn't widely used". Yes it was. Maybe you didn't know, but it was. "and Chrome is one of the most intensively optimised apps out there. " This isn't really true actually. So if that's your counter-argument, ... "So I think it's fair to say that most C++ apps built by mere mortal companies probably still don't use it" No, it isn't :) Really. So far you've cited one example of someone being late to the party. " But I'd be keen to see data showing I'm wrong." What form do you want it to take?
- zamalek 10y agoAOT PGO is fantastic tech! However, it can only optimize for the profile that you set up for it. Deploy it on a million machines with a million use cases and some of them aren't going to match up with your profile. In these cases it may very well degrade performance. So you might try to profile scenarios that hit all codepoints equally, by doing so you would defeat the purpose of PGO (and likely nullify it). JIT PGO is adaptive to the workload that the process is experiencing. It is likely impossible to achieve this with AOT compilation.
- DannyBee 10y ago"JIT PGO is adaptive to the workload that the process is experiencing. It is likely impossible to achieve this with AOT compilation. " Of course it's not :) You just generate different binaries for each use case. Truthfully, the "million machines/million use cases" story is pretty non-realistic these days (except in the above case!) Most people run mostly-specialized services for mostly-specialized use-cases. This is because it's necessary for performance in practice anyway.