Login
You're viewing the techdon.dev public feed.
  • Sep 18, 2026, 1:08 PM

    why do i say we're onto a loss of memory efficiency by using a gc? because a 1.3x working set heap is probably quite tight and that's already wasting 30%, even assuming everything else is perfect. more realistic would be 1.5-2x for most apps i think.

    of course we don't usually think about the bookkeeping overheads of malloc when we work with non-gc'd memory. they're not free. even assuming our malloc refuses allocations larger than 4gb (not entirely unreasonable tbqh), that's still a 32 bit size to store for it, even pretending we won't have other overheads (lol).

    most modern allocators use size classes. we're disincentivised to use size classes for a gc because it means we're not filling blocks as often and we can't relocate different sizes into the same block to save space.

    anyway i suspect that the memory overheads of allocators are not in practice wildly different from the memory overheads of GCs, albeit arranged somewhat differently.

    💬 1🔄 0⭐ 4

Replies

  • 💬 1🔄 0⭐ 2
  • Sep 18, 2026, 2:34 PM

    one thing i'm thinking is that 8 byte heap allocations make little sense. i plan for value types and unboxed integers, so there will be much less of a need to have tiny heap objects.

    💬 1🔄 0⭐ 1
  • Sep 18, 2026, 2:48 PM

    i don't think there's much call for having data more than cacheline-aligned unless it's very aligned indeed (i.e. pages). so we can consider regions for multiples of 16, 32 and 64 bytes and get natural alignment on them. this seems like comparable waste to an allocator.

    then we can use a very old trick indeed and compress two of these into one region by allocating from both ends until they meet in the middle. in the old days it used to be the stack and the heap meeting in the middle, of course.

    💬 1🔄 0⭐ 2
  • 💬 1🔄 0⭐ 0
  • Sep 18, 2026, 3:48 PM

    i guess we get to choose between synchronising allocation of pinned data or wasting memory. i expect pinned data is generally going to be fairly long-lived (buffers and such). you only need to pin data so long as C stuff can get at it, which is usually only for the duration of an ffi call, but async i/o apis of course break this assumption.

    💬 1🔄 0⭐ 0
  • Sep 18, 2026, 6:20 PM

    okay, so moving GCs are free of fragmentation, right? allegedly, anyway. but what is fragmentation? i think it only covers leaving holes that aren't quickly reused.

    anyway fragmentation seems lesser than the other thing moving collectors give you - relocating data to be contiguous in memory. i wonder how much that's good for.

    💬 1🔄 0⭐ 0
  • Sep 18, 2026, 6:32 PM

    so earlier, when i was musing about size classes, i overlooked something important: there is no fragmentation with size classes beyond padding things to the next size up if they are smaller. well there needn't be if you're already tracing, anyway.

    this also means the only reason to evacuate would be to merge partially filled blocks of the same size class.

    the downside is that each thread needs at least one block of each size class that it's allocating into. but again, this is comparable to ordinary allocators. so one partially filled block of one of each size class that's been encountered. that's kind of an annoying constant overhead.

    now why haven't i heard of anyone doing this before?

    💬 0🔄 0⭐ 0
  • Sep 18, 2026, 4:17 PM

    @dysfun

    One related beef I have with languages that use GC is that they usually don't let you store anything other than primitive types on the stack.

    In Rust, storing something on the heap is considered costly, and you only do it when you actually need to. In JavaScript, absolutely everything is stored on the heap.

    💬 0🔄 0⭐ 0
  • Sep 18, 2026, 4:18 PM

    @argv_minus_one part of this is due to considering heap allocation cheap (it's more or less free until collection!). storing stuff on the stack is not difficult. letting you take references to stuff on the stack safely is extremely difficult

    💬 0🔄 0⭐ 1
  • Sep 18, 2026, 7:11 PM

    @dysfun

    Heap allocation with a GC isn't cheap; its cost is just deferred, like buying something on a loan instead of paying up front.

    It's pretty much a natural law that heap allocation is expensive. You can defer the cost, and you can use various elaborate strategies to reduce the cost a little, but it's still expensive.

    And yeah, taking references to stack memory safely is difficult. That's why Rust is such a big deal: it has a solution for that thorny problem.

    💬 0🔄 0⭐ 0
  • Sep 18, 2026, 8:26 PM

    @argv_minus_one @dysfun some kinds of gc the `n` in the complexity is for the live set rather than the total allocations, which is, in practice for some workloads (lots and lots of small allocations that are thrown away quickly), a really substantial reduction in the cost of allocation, not just moving it around.

    💬 0🔄 0⭐ 0