First Steps with Java's New Vector API and JITWatch
Вставка
- Опубліковано 10 вер 2024
- Java has a new Vector API and in this video I show the basics of how to use it.
To get everyone on the same page, I start by showing how to prepare the Eclipse IDE. This includes the installation process, installing a couple plugins (Launch Configuration View, and Jeeeyul's Eclipse Themes), and walking through several preferences that I wish someone had told me about earlier.
The new Vector API is still "incubating" so it's no surprise that performance is improving with each new release of the JDK. To highlight the differences, I show how to test your code with Java 16, 17, and 18. Java 18 is not out yet, but nightly builds are available on Shipilev's web site (and other places.)
I share an example of when you might use vectorized (SIMD) code: checksum validation. Telemetry Viewer has a "binary mode" with optional checksums, and this is one area of my code that could use some optimizing. I benchmark my original scalar code against four attempts at vectorizing it. As we'll see, sometimes performance gets better, but other times it gets worse -- sometimes much worse. We'll run across a bug in Java 16, and see how slowly some of the API's fallback implementations perform.
The code is tested in Windows, in a Linux VM, and even on a Raspberry Pi 4. Two versions of Raspberry Pi OS are tested: the default Arm32 (32-bit) version, and the beta AArch64 (64-bit) version. The new vector API does not support Arm32 right now, and we'll see some serious bugs that crashed the JVM when running on a Pi.
With 3 operating systems to test, and 3 versions of Java for each OS, that's a total of 9 different configurations. It would be a pain to manually test changes to the code, but we can use Eclipse's "Launch Group" feature to automate the whole process. It's like a crude CI/CD pipeline.
Finally, I show how to use JITWatch to look at how your source code transforms to Java bytecode and to actual assembly instructions. We can get the runtime to output a log with the disassembly and optimization details by using a handful of flags passed to the JRE. That log can then be parsed by JITWatch, allowing us to see what happened.
OpenJDK does not include the disassembler due to licensing conflicts, so I show to to manually compile the HSDIS DLL. This involves use Cygwin to setup a development environment, and downloading the source code for OpenJDK and Binutils. A Make target is invoked, and after a few minutes the DLL is ready to use.
A text summary of this video is available on my web site:
www.farrellf.co...
Well I am obviously behind the times as I had no idea what the vector business was about before the video. I found the IDE setup interesting, I had no idea Eclipse could ssh hosts and run code on them so easily. I mostly write C/C++ code and seldom deal with datasets where performance like you deal with is needed, just little things like light control and temperature monitoring around my house. This gave a nice background in to part of what it takes for you to write such a high performance tool like this (I have seen your videos where you really push things to the limit with very fast sensor readings and video streams.) Which reminds me someday I want to make a balancing robot like you did, but I never seem to make the time. Anyway thanks for the nice walk through, made for an interesting evening.
Thanks for the kind feedback. Glad you liked the video.
A bit late but still worth mentioning: Optimizations for the Vector API are done by C2. When doing benchmarks like that, make sure you are doing appropriate warmup (and other stuff which is way easier with JMH).
This is probably the reason for your performance issues (especially if it runs in interpreter mode which can typically be around 20 times slower).
Really enjoyed the video. I learned a lot about Eclipse and the new vector api.😊
hi can u reupload it with a better resolution 1080p or 4k?
Hi. It's a 4K video. UA-cam is probably still processing the higher resolution versions. Check back in a few hours.
@@upgrdman oh yea u r right now its 1080 p thx 👍🙂 is intellij not better then eclipse?
IntelliJ IDEA seems to be more popular, but I'm happy with Eclipse. Both are good options.