Hacker News new | ask | show | jobs
by brighteyes 2374 days ago
You're right, yes - a 1ms pause has a cost, even in a 16ms budget.

I interpreted the author's point as "GC is now potentially viable for games", in the sense that older GCs might have pause times larger than 16ms, making them obviously inappropriate, whereas today 1ms pauses is something that can be budgeted for at least in some cases.

As you said, malloc/free also have costs, and also GC has other benefits, like bump allocation, moving things to compact memory and improve cache locality, etc. 1ms pauses means GC is worth considering even for a game, in other words.

2 comments

> As you said, malloc/free also have costs, and also GC has other benefits, like bump allocation, moving things to compact memory and improve cache locality, etc. 1ms pauses means GC is worth considering even for a game, in other words.

The general approach used by games is probably superior, which are arenas or zones.

One approach games use is to allocate everything that's necessary for a given frame in a single large block, carve it off over time as needed, then drop the entire arena. All allocations then have memory locality, no fragmentation, basically zero cost to allocate (increment a pointer) and zero cost to deallocate.

This kind of thing actually plays really nicely with Rust's lifetimes since you can couple frame lifetime with objects in that frame and get static validation. Arenas are already available in nightly [1].

[1] https://doc.rust-lang.org/nightly/nightly-rustc/arena/index....

Arenas exist in stable too, this is just the arena the compiler uses internally. See packages like https://crates.io/crates/generational-arena or https://crates.io/crates/typed-arena
Ah of course, my bad, I must not have noticed. For some reason I read the "internal" flag as "nightly" :P
It's all good!
"Games" is a term for are a large collection of very different types of software, do we mean AAA FPS games? Then I would probably not use a GC, if we mean most other games? Then it's just fine. Many GC events are way shorter than 1ms also...
Turn-based or pausable-real time 4X games where you spend most of your time paused and also get hit by a regular (~1000 ms) autosave freeze spring to mind.
If you look around configuration REDEngine configuration files in PC version of Witcher 3, there is file with what for me looks like tuning parameters of Boehm-like conservative tracing GC, it is probably the only file in there that even includes comments about what the parameters mean and partially how they were determined. My overall impression from the various configuration files is that the whole world streaming/demand-paging mechanism is somehow interwoven with or even partially driven by the GC (so the GC is not meant for some small-ish scripting heap)