Skip to content

SYSTEM Cited by 1 source

GHC (Glasgow Haskell Compiler)

What it is

GHC — the Glasgow Haskell Compiler — is the dominant Haskell compiler and runtime system. Project home: haskell.org/ghc. It is both the reference implementation of the language and a sophisticated optimising compiler with a managed runtime (garbage collection, green threads, FFI, runtime linker, etc.).

On the sysdesign-wiki, GHC's canonical appearance is as the runtime underneath Meta's Sigma anti-abuse rule engine, where Meta contributed several load-bearing features upstream.

Meta-contributed features (as of the 2015 Sigma-rewrite post)

Feature What it does
Applicative do-notation Compiler rearrangement of imperative-looking do-blocks to exploit independence between statements. Enables Haxl's implicit-concurrent data fetching without explicit concurrency constructs.
Heap-management changes Reduce the frequency of garbage collections on multicore machines. Meta runs ≥ 64 MB allocation area per core (up from GHC's default "frugal" settings).
Allocation limits Bound the amount of memory a single thread can allocate before runtime terminates it via an asynchronous exception. Safely releases resources; other threads unaffected. See concepts/allocation-limit.
GC detection of unreferenced old code GHC's reachability-based GC detects when hot-swapped compiled code is no longer used by any in-flight request, enabling safe unloading. See concepts/hot-code-swapping.
GC crash fix A GC bug that had caused Meta's Sigma processes to crash every few hours — and gone undetected in GHC "for several years" — was found + fixed under Meta's hyperscale workload. Canonical instance of long-latency compiler bugs flushed out only by production scale.
Finalizer-lifecycle fix Addressed crashes during process shutdown.

Post-contribution: "we haven't seen any crashes in either the Haskell runtime or the Haskell code itself across our whole fleet" (Source: sources/2015-06-26-meta-fighting-spam-with-haskell).

Runtime features Sigma uses

  • Runtime linker — Sigma loads/unloads freshly-compiled policy object code via GHC's built-in runtime linker; the post notes the system dynamic linker could also be used.
  • GHCi — GHC's interactive environment, customised by Meta for in-session testing against real production data sources (build system linked C++ dependencies into a shared library GHCi could load; front-end commands added for Meta workflows).
  • Asynchronous exceptions — the safe-termination mechanism underneath concepts/allocation-limit.

Seen in

Last updated · 319 distilled / 1,201 read