Java is Very Fast, If You Don’t Create Many Objects

Seriously Java being an Object Oriented Language, literally

> if you want to have write fast java code, you have to code as if you were using C

~a certain minecraft mod developer

@wolf480pl @the100rabh to be fair performance critical code in any language tries not to go near malloc. it's just made so damn easy to do it by accident in stuff like java where you can't touch a string without the GC getting nosy.
@wolf480pl @the100rabh i remember reading about Abuse using their own flavor of common lisp for scripting and when it came to memory management their answer was "don't." they just arena allocated the heap, had an allocator that incremented a pointer and at the end of each frame reset the pointer back to start. :comfyeyes:

@the100rabh Not to apologize for Java, but this article just confirms what's been known in the embedded programming space since basically forever: if you can, avoid dynamic allocations at all costs, and use pools of objects/records of you can't. This isn't just an OO or Java issue, it also affects C/C++, Rust, Modula-2, etc.

@vertigo @the100rabh Also as someone who's made games in Java, you can still be OOP all the way down, just pre-allocate things and return them to a dead object pool when you're done.

@vertigo @the100rabh i think the most interesting thing the article highlights is that the cost isn't going in GC (which is negligible); it's the actual allocation where the time is being spent. which is fascinating, given that the whole raison d'etre of the Azul memory manager is to always do allocation by just incrementing a pointer...

i can only assume that the knock-on effects of continually cycling through new objects are screwing up the cacheing - a new object is necessarily not likely to be in the cache already, and something will have to be evicted to make room for it; whereas if you're reusing an object it's more or less guaranteed to already have booked its space in the cache

Sign in to participate in the conversation
Mastodon for Tech Folks

This Mastodon instance is for people interested in technology. Discussions aren't limited to technology, because tech folks shouldn't be limited to technology either!