Every Byte Matters
The article discusses the importance of understanding hardware performance when programming, particularly in Java. It highlights how cache sizes and data structures can significantly affect performance, especially when iterating over large arrays. By optimizing data layout, such as using a 'Struct of Arrays' instead of an 'Array of Structs', programmers can achieve substantial performance improvements.
- ▪The performance of algorithms can vary dramatically based on the underlying hardware and data structure layout.
- ▪Cache line sizes and the way data is organized in memory can greatly influence the efficiency of data access.
- ▪Using a 'Struct of Arrays' layout can lead to performance improvements of up to 30 times compared to an 'Array of Structs'.
Opening excerpt (first ~120 words) tap to expand
I have spent a large portion of my career working in Java. In that time, you get used to huge classes. New functionality? Just add a new method and field to the class. The cost of each new field is rarely considered. Performance is often considered from a classic computer science perspective by considering asymptotic analysis of the algorithms and data structures in-use. Turns out that even within a growth scale for your algorithm, such as a simple for-loop O(N), time can vary dramatically if we have a little deeper understanding of the underlying hardware. First, let’s understand our current machine. Let’s take a peek at our cache line and page sizes.
…
Excerpt limited to ~120 words for fair-use compliance. The full article is at Farid Zakaria’s Blog.