73 points · by zdw · 5y ago · 50 comments
In a world where most code is JIT compiled on the target architecture and/or periodically re-compiled using the latest, optimized compiler once a new CPU comes out – sure.
But is that realistic? Maybe that would work for Android and iOS (with on-device and app store level compilation, respectively), but with Docker, we seem to be moving to the opposite direction again, and runtime hardware-based optimization makes a ton of sense there.
Why do and then un-do?
The reason is that we've not yet found a better way of making fast general purpose processors.The OOO (= out-of-order) approach with high-quality prediction (e.g. branch, value) to processor micro-architecture makes sense if you have to mask a lot of memory-access latency, which comes from data-dependent (= unpredictable) memory access. General purpose workloads have a lot of that. (If memory access patterns are more predictable, you'd probably run your workload on a GPU or TPU or DSP, or some other accelerator.) Compilers, whether ahead-of-time, or JIT, have not got enough information to schedule commands in a way that can mask memory latency the way an OOO scheduler inside a processor can. Stalling the pipeline because you are waiting for data to arrive from memory is disastrous for performance and to be avoided at all cost. Intel's Itanium was based on the premise that it is possible statically to schedule well enough, but that has been considered a failure for general workloads. Moreover, if you let a compiler schedule you need to have ISA extensions that allow you to communicate scheduling information to the processor which is not cost free (for example you may spend precious bits to encode scheduling order that you then cannot use for other things).
I suspect that the very last word has not been spoken in this discussion, but everything obvious to make dataflow competitive (and quite a lot more) has been tried, and failed.
Intel, quite infamously, tried to make "something better" work with several generations of Itanium and failed impressively against the reality that a sufficiently smart compiler cannot be made to work. You can't blame any of the big players for holding back - Intel, MS, and HP were "all in" on Itanium as the 64-bit future - if it could have been made to work, it would have been widely adopted.
At the same time, Transmeta was building a X86-on-VLIW, which, guess what, also failed to be a competitive product. Nvidia, of course, decided to pick up from where Transmeta left off to build what ended up being an aarch64-on-VLIW design. In both cases, the hope was that the low-level translation would allow the benefits of a VLIW architecture while avoiding the "sufficiently smart compiler is impossible" problem, and in both cases performance just wasn't good enough to be competitive.
It reminds me of how MIPS branching is wasted on nops:
https://electronics.stackexchange.com/questions/28444/mips-p...
"The trick in writing efficient code is to put in an instruction that will be useful as part of the loop that is being taken executed, but do no harm if the branch is not taken.
The MIPS designers were counting on compiler writers to write clever enough code generators to handle this efficiently. However many do not (including Microchips C32 compiler, based on GCC), and just put NOP's after every branch, wasting both code space and cycles"
There is no conspiracy here.
Spoiler: It didn't end well.
A system that AOTs and JITs and recompiles based on how the specific user actually uses the app and what it actually does on that specific device.
A new high level language that drops all pretense at imperativeness. Some combination of functional and reactive and other hip jargon where you lay down guidelines of what you need done with your assets, user inputs and events. No need to think about threads and shit. You no longer have to know what will actually happen on the metal. Let it go.
> A system that AOTs and JITs and recompiles based on how the specific user actually uses the app and what it actually does on that specific device.
Basically every Android device since version 7, and Windows Phone 8 execution model.
For example if an app tries to connect to the internet to download some news on every launch, but the user is often offline, the system magic would automatically inject a check for connectivity to avoid a lengthy timeout.
Most software doesnt fully map to a data flow architecture, and when it does you can run it extremely efficiently on today's hardware anyway.
[citation needed] There are many difficult parts to a super scalar speculative dynamically scheduled microprocessor, but retirement doesn't even make top 10. If I had to pick, it would hands-down be the load-store unit which is really hard to scale (and has a lot of gnarly corner cases).
> This all may seem inefficient and crazy and it is. Program representation and execution need a major re-think along the lines of the once-investigated dataflow architecture.
I actually agree with the impedance mismatch of our legacy ISAs, but "dataflow" is a bizarre pick as the original formulation was incredibly inefficient and all modern processors (A72 included) are already dataflow machines over a fixed windows of the (partially speculated) path through the program.
There have been a lot of interesting paradigms published, but it's extremely rare for industry to take a risk. VLIW is still a darling (in principle very efficient iff you hit in the caches), but there are a _lot_ of other ideas. Browse through the past few decades of ISCA and MICRO proceedings to see examples.
The cost of making new binaries is always the problem. At Transmeta we used binary translation as the answer for x86 and NVIDIA's Denver much improved upon the idea for Arm. Both use in-order execution which in hindsight didn't seem to have worked out. Alas, dynamic translation of binary code has huge overheads and issues with cold code. There's hope though; if the code you are translating is WASM then you are in a much better place, but still not quite as good as source as you are lacking all the alias knowledge.
[updated typos and grammar]
There have been many attempts at making data-flow applications compatible with general purpose computation workloads. They all failed to beat the performance of comparable conventional processors. [1] lists the following disadvantages of data-flow:
- Debugging difficult (no precise state)
- Interrupt/exception handling is difficult (what is precise state semantics?)
- Implementing dynamic data structures difficult in pure data flow models
- Too much parallelism? (Parallelism control needed)
- High bookkeeping overhead (tag matching, data storage)
- Instruction cycle is inefficient
[1] https://course.ece.cmu.edu/~ece740/f13/lib/exe/fetch.php?med...