Hacker News new | ask | show | jobs
by astrange 1644 days ago
There's more than just the stack/heap - in a compiled language your constant data is file backed and doesn't need to contribute to memory footprint at all. Java doesn't have that because jar files are missing it (being zipped, syntax that looks like it creates them emit heap allocation bytecode, etc.) and it doesn't have multidimensional arrays or things that might help you use it even if you wrote it in C.

There's some other tricks like tagged pointers, purgeable data it doesn't reliably have either.

2 comments

Java NIO can mmap a file of bytes or ints or whatever without using the heap’s private pages, and there are some JVMs that persist and reuse jitted machine code.

I’ve read that games and simulators schedule realtime asset loading pretty carefully; what other problems are solved using large constant data?

ZIP does support uncompressed data, so this could easily be added in a backward-compatible way if deemed worthwhile.
Eh you can still have compression, what’s important is the OS pager knows how to read the page from disk as opposed to eagerly loading and swapping it.