Skip to content

Tracking down the FastWeak "leak" and solving it for ghc 9.X #515

@maralorn

Description

@maralorn

reflex-plattform contains a patch for the garbage collector of ghcjs to fix a "leak" in the implementation of FastWeak/FastWeakBag. Before we can migrate production systems to ghc 9.X we need to either forward port that patch, ideally upstreaming it for all ghc backends, determine that it is unnecessary or find another workaround. @ryantrinkle has started on upstreaming this at https://gitlab.haskell.org/ghc/ghc/-/issues/25373, where the core problem is described:

  • Every value pointed to by a waiting finalizer is alive.
  • On GC all dangling Weak pointers will be GC’d, but their finalizer will only be run after the GC phase.
  • Thus, all Weak pointers retained by a finalizer can only be cleared in the next GC step.
  • This leads to problem with chains of Weak pointers:

    Specifically, in the case of a doubly-linked list which is weak in one direction, cleaning up a list of n items takes O(n) full GC+finalization cycles. Since certain workloads (particularly FRP) construct long chains like this frequently, in a steady state, this results in memory effectively leaking - even though it will eventually get cleaned up, garbage can be created much faster than it gets cleaned up.

My goal is to

  1. write a reproducer for the problem as it occurs in reflex.
  2. Figure out whether we can find a workaround or demonstrate that a patch like the above will be needed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions