5 ms·
The problem with native code is platform disparity. It's absurd that so many binary variants are required when shipping code to e.g. Android or iPhone. This ca
by zamalek 11y ago
The problem with native code is platform disparity. It's absurd that so many binary variants are required when shipping code to e.g. Android or iPhone.
This can apply to x86, too. Not sure if all your users have TSX-capable CPUs? You're now shipping two binaries. Not sure if your users have AVX? Now you have at least three binaries.
This is the biggest advantage of intermediate languages - your code can at the very least execute everywhere with a single image, and in some cases automatically take advantage of platform features such as AVX.
I think ART takes the correct approach: ship IL and AOT it on the device. Hopefully some day we can get the same type of system for LLVM IR.
- Kristine1975 11y ago>This can apply to x86, too. The Intel C/C++ compiler creates different code paths depending on the CPU's capabilities. So at least there's no duplication of non-cpu-specific code. It also does or at least used to check for the CPU's capabilities by using the CPU's vendor ID string, resulting in AMD CPUs executing the slowest code path: http://agner.org/optimize/blog/read.php?i=49#49 http://agner.org/optimize/blog/read.php?i=49#49 (Intel got sued for this by AMD: https://en.wikipedia.org/wiki/Intel_C%2B%2B_Compiler#Criticism https://en.wikipedia.org/wiki/Intel_C%2B%2B_Compiler#Critici...) *Edit: >Hopefully some day we can get the same type of system for LLVM IR. Right now the LLVM IR isn't platform-agnostic, e.g. when it comes to calling conventions. Also when Apple transitioned from 68000 to PPC in the 90ies, then from PPC to x86 and recently from 32 bit to 64 bit, they used "fat binaries" where a single executable file contained code for several platforms. That way one and the same application could run on old Macs with PPC, newer ones with 32 bit x86 CPUs and really new ones with 64 bit capable x86 CPUs.
- zamalek 11y ago> The Intel C/C++ compiler creates different code paths depending on the CPU's capabilities. Wow. That's a really slick way to solve the problem. Edit: > Right now the LLVM IR isn't platform-agnostic, e.g. when it comes to calling conventions. That's unfortunate. Either way I'd love to see some form of native IL that can be shipped instead of binaries.
- Kristine1975 11y ago>Either way I'd love to see some form of native IL that can be shipped instead of binaries WebAssembly could fit the bill, although it's still in early development.
- rwallace 11y ago> Right now the LLVM IR isn't platform-agnostic, e.g. when it comes to calling conventions. But it does give you the same benefits in terms of CPU capabilities. You can't ship intermediate code that's agnostic about e.g. x86 vs x64 (C and C++ just aren't amenable to that, no matter what your intermediate representation looks like), but you can ship intermediate code that expects some form of x64 but postpones instruction selection until the program is installed, so you can take advantage of new instructions just when they are available. As I understand it, Apple is going to use it for that purpose.
- pjmlp 11y agoThe idea of using a portable bytecode and AOT it on installation time goes back to the mainframes. OS/400, now IBM i, is probably the last living mainframe doing it.
- zamalek 11y agoIn software development we routinely ignore historical good ideas - we keep re-discovering the same things over and over again. I'd say that even if we eclipse JIT in the coming years, in the distant future someone is going to repeat our same mistakes.
- pjmlp 11y agoI guess it is because many do not care to learn. Using USA CS speak, I guess I majored in systems programming with a minor in computer graphics, and my university had a very nice library. So I got to do lots of programming language and OS research at that library. When I got into the university, we still had Gopher. :)
- k__ 11y agoAlso, we ship JIT compilers with the software right now, so why don't just ship AOT compilers instead?
- pjmlp 11y agoWell, at least in Windows it was always the case with .NET. NGEN is there since day one, but they always kept it quite simple in optimizations and only allowed for dynamic linking (no static binaries). Also it required signed binaries, which many people did not bothered with. Windows Phone 8 adopted the Singularity toolchain with AOT compilation in the store, with a dynamic linker on the phone. .NET Native just moves the WP8 linker out of the device and produces static binaries instead.
- ajuc 11y agoGentoo linux distribution works that way. It has automatic package management system (Portage) similar to apt-get or rpm (and even more similar to ports in *BSD). The source meta-packages (specyfying the compiler flags, patches etc) are maintained by the community. You configure a system-wide flags specifying your cpu, optimization level, the features you want to enable and disable (many libraries and apps have flags to compile support for some features or not), etc. There were also app-specific flags IIRC. When you install a package it downloads sources and the meta-package from portage, then it is compiled on your machine with your flags added for your specific processor with only the features you enabled. It was supposed to be much faster than "bloated ubuntu", but I suspect now it was mostly placebo :) On the other hand installing Open Office on my Celeron 2000 laptop with 256 MB RAM took 10 hours, and if I wanted to enable some feature that turned out to be useful after all - I would need to wait another 10 hours. I used it for 2 years when I was on university but then it was too much to wait for hours when I needed sth.
- cperciva 11y agoThis can apply to x86, too. Not sure if all your users have TSX-capable CPUs? You're now shipping two binaries. Not sure if your users have AVX? Now you have at least three binaries. Three code paths, not necessarily three binaries. It's easy enough to compile different variants of performance-critical routines and then select between them at run-time. I think ART takes the correct approach: ship IL and AOT it on the device. Hopefully some day we can get the same type of system for LLVM IR. This isn't necessarily optimal though. Having certain CPU features may make algorithmic changes useful -- e.g., switching between lookup tables and direct computation depending on whether you have the CPU features which make the direct computation fast. There's no way an AOT will be able to handle that for you.
- tormeh 11y agoNo, but neither will compilation on a dev machine. You'll have to insert a manual switch witch depends on compilation target anyway. Phoronix did a test where compiling with march=native sped up programs a substantial amount. 20% for one application. It astounds me that we throw away that sort of gains.