logoalt Hacker News

Every Byte Matters

68 pointsby ingvetoday at 11:04 AM19 commentsview on HN

Comments

noelwelshtoday at 11:46 AM

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.

show 2 replies
forintitoday at 11:33 AM

So if you need speed, you just have to swallow your OO programmer's pride and put your data in arrays.

show 1 reply
prontoday at 11:55 AM

> 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.

ssiddharthtoday at 11:47 AM

Slight tangent, but every ms, μs, and ns counts too. We've gotten awfully carefree with response times and wasted compute cycles.

coldcity_againtoday at 11:29 AM

I love to see stuff like this. And an active Vectrex gamedev and PC/Amiga sizecoder I strongly agree with the sentiment!

RickJWagnertoday at 12:20 PM

That’s a great read. I wish more people wrote like that.

show 1 reply
yas_hmaheshwaritoday at 11:55 AM

Out of course: I had thought about reading an article about Iran war or some geo political news when I read fzakaria :-)

coolThingsFirsttoday at 12:19 PM

Why doesn’t the machine fill up the other cache lines as well why is 64 bytes only and then a miss?

show 2 replies