Every Byte Matters

(fzakaria.com)

38 points | by ingve 54 minutes ago

6 comments

  • pron 2 minutes ago
    > The cost of each new field is rarely considered

    Most developers, in Java and in most other languages, do not consider the cost of every field, but I can tell you that people who need micro-optimisations certainly do care, and in Java's standard library, a layout is very much a concern (except, as always, you want to optimise what really matters; there's no point in optimising something that is unlikely to be a hot spot in a real program). Sometimes, though, you want to intentionally spread out the layout to avoid cache line sharing when concurrency is involved. You will find such examples in the standard library, too.

  • yas_hmaheshwari 3 minutes ago
    Out of course: I had thought about reading an article about Iran war or some geo political news when I read fzakaria :-)
  • noelwelsh 12 minutes ago
    The JVM is currently pretty bad for memory allocation. Every object (i.e. not a primitive) has a header that IIRC is 12 bytes. But there is good news in JVM land: this will be reduced to 8 bytes in the next JVM release, and Project Valhalla will give the tools to do away with headers entirely in some cases. Project Valhalla also has tools to manage off-heap memory, which is important in many cases.

    The JVM is an odd place where it requires too much heap to compete with the AOT compiled languages, but its startup time is too slow compared to interpreted languages. I think these enhancements are essential to keep the platform relevant.

  • forinti 25 minutes ago
    So if you need speed, you just have to swallow your OO programmer's pride and put your data in arrays.
    • theandrewbailey 18 minutes ago
      Maybe someone can write an OO language where arrays of structs are automatically stored as structs of arrays.

      mild /s

      • Mizza 8 minutes ago
        Are you talking about Zig's MultiArrayList?
  • ssiddharth 10 minutes ago
    Slight tangent, but every ms, μs, and ns counts too. We've gotten awfully carefree with response times and wasted compute cycles.
  • coldcity_again 29 minutes ago
    I love to see stuff like this. And an active Vectrex gamedev and PC/Amiga sizecoder I strongly agree with the sentiment!