← Back to context

Comment by marcosdumay

6 hours ago

> That's when you measure and optimize.

How do you "optimize" the GC away after you wrote your entire database server in a language that uses it?

Object pooling and bump allocators using persistent scratch buffers, mostly. The latter what you'd use for read buffers in I/O intensive applications like databases and the like.

Starting by using a GC language that is strongly typed, compiles to native code, supports value types, memory pools/arenas if required, which provides best of both worlds.

Where GC means any kind of GC algorithm from CS point of view.

GC languages typically have features of the language and/or standard library that make GC the default, not the only option.

  • What doesn't save you from having to rewrite the entire system.

    (Even though, no, that's not typical. That's a tiny minority of them.)

    • Not sure I understand the question, but it generally works like this:

      Once you measure, you'll find a small fraction of the code is taking a large fraction of the time. When you zoom in on trouble-spots you may find, e.g. that the GC is taking the time (or you may find something else entirely is taking the time). If it's the GC, you might look and see, e.g., that it's spending its time tracing the objects in the 100K node graph you're creating several times a second, and realize you could, e.g., create it once and simply keep reusing it. Perhaps it might be as simple as using removeAll(keepingCapacity: true) instead of removeAll() (a Swift example).

      The superficial details differ, but you generally just want to understand what the GC is working so hard on and lighten its load. If you haven't been measuring and optimizing throughout, there are almost certainly easy-to-pluck, low-hanging fruits, ripe for the taking.