50x Faster Code and Fewer Bugs? Ditch the Classes | HackerNoon
Briefly

Using classes can significantly decrease performance and increase complexity in software development. Every new instance of a class can result in cache misses, degrading speed. A complex structure with multiple methods and fields increases the likelihood of state corruption, making it challenging to track possible object states. Refactoring a typical customer-class structure with arrays can result in a substantial performance improvement, demonstrating the drawbacks of traditional object-oriented approaches regarding memory access patterns and code complexity.
Every class is a petri dish for state corruption. You have ten methods touching five fields. Quick: tell me all the possible states your object can be in. You can't. Nobody can.
Write a Customer class with a List<Order> where each Order had a List<LineItem>. Following one customer's data meant chasing pointers all over the heap.
Replace it with three arrays - customers, orders, line items - and suddenly the same algorithm runs 50x faster. Not 50%. Fifty times.
Every new MyClass() is another cache miss waiting to happen. Your CPU has these beautiful cache lines, 64 bytes of data it can grab at once.
Read at Hackernoon
[
|
]