3 ms·
He did this in Java? In one case, running on an emulator? That's removed too far from the hardware for this kind of benchmarking. Try in a hard-compiled languag
by Animats 7y ago
He did this in Java? In one case, running on an emulator? That's removed too far from the hardware for this kind of benchmarking. Try in a hard-compiled language.
Using shifts for constant divide has been a compiler code generator optimization for decades. This is not something programmers have needed to worry about in source code for a long time, unless targeting some small microcontroller that lacks fast divide hardware.
- pjmlp 7y agoJava is a hard-compiled language on Android since version 5.0. ART, which replaced Dalvik on 5.0 (available as experimental on 4.4), was AOT only up to version 7.0. As it was proven that Android users lack the patience of a C++ developer when updating their apps, Google adopted another approach with version 7.0. A multi-tier compiler infrastructure, composed by a very fast interpreter hand written in Assembly for fast startup, a JIT compiler for the first optimization level, with gathering of PGO data, then the AOT compiler runs in the background and when the device is idle gets that PGO data and just like a C++ compiler with PGO data, outputs a clean AOT compiled binary for the usual user workflow. In case of an update or changes in the workflow that trigger the execution of code that wasn't AOT compiled, the process restarts. As means to reduce this kind of de-optimizations, since Android 10 those PGO files are uploaded into the Play Store and when a user installs an application that already has PGO data available, it is downloaded alongside the APK and the AOT compiler can do its job right from the start. In any case, he used dex2aot which is the AOT compiler daemon on Android. Microsoft has gone through similar process with .NET for UWP, with the main difference that the AOT compiler lives on the Microsoft store and what gets downloaded is already straight binary code. Apparently mixing language capabilities with toolchains keeps being an issue.