How to write fast Java code – thinking about memory
summary
A simple JMH matrix‑multiply benchmark runs six loop orders on 1000×1000 double matrices and shows loop order alone causes 24× difference in speed; hand‑refactoring for cache‑friendly access raises that to about 40× faster on a workstation. Splitting work across cores gives roughly ~10× speedup for eight cores (hyperthreading helps less), and combined tuning plus multithreading hits around 400× faster versus a naive order. Advice: use primitive arrays, avoid boxing/extra allocations, prefer cache‑local inner loops; compare to native BLAS (Intel MKL, Apple vecLib/Accelerate) for very large ops.
AI-written summary · about
chapters (4)
related talks
51mJava at Speed: Getting the Most Out of Modern Hardware
46mJava vs CPU
53mFrom functional programming to assembly - the cost of abstractions....
45mHow difficult can it be to write efficient code?
41mJava 24, Faster Than Ever
49mMassive Parallelism with GPUs in Java
51mJava vs CPU — round 2
41mUp and Away: JDK Optimizations
