HEQL default query catalog
Generated from commit e8a491d6e1e2.
The default HEQL catalog: the collections the inspector ships, each
a small library of detectors over the live heap. This is exactly the
catalog the HEQL tab and hins heql load by default — every query
below typechecks against the heap schema.
#Leak suspects
The front page: dominator accumulation points holding a meaningful share of the live heap, as scored cards — start here, then drill.
#leak-suspects — Leak suspects
Grade Cn {dominators, ipe} reads {Frame.label, Frame.pos, Frame.type, Node.label, Node.pos, Node.retained, Node.type}
Type Seq Finding
view leak-suspects "Leak suspects" (minShare = 0.05) section "Leak suspects" =
[ card (rep g)
{ title = "{count g} x {k.label} hold a large share of the heap"
, bytes = domRetained g
, chips = [ chip "heap share" (percent (domRetained g / totalHeapBytes))
(tiers [ domRetained g / totalHeapBytes >= 0.25 ~> bad
, domRetained g / totalHeapBytes >= 0.1
~> warn ])
, chip "thunks" (percent (frac thunkBroad g))
(tiers [ frac thunkBroad g >= 0.5 ~> warn ]) ]
, evidence = top 3 .retained g
, ..drills (rep g) }
| c <- heap, group by domKey c into (k, g)
, domRetained g / totalHeapBytes >= minShare
, order by domRetained g desc, limit 25 ]
#Diagnostics
Lint-style leak detectors: each view flags one suspicious heap shape and reports the worst offenders as finding cards.
#selector-leak — Selector leaks
Grade Cn reads {Frame.type, Node.retained, Node.self, Node.type}
Type Bag Finding
view selector-leak "Selector leaks" section "Diagnostics" =
amplifier (.type == SELECTOR) (minBytes = 4KiB) (minRatio = 8)
#deep-stack — Deep thread stacks
Grade Cn {threads} reads {Node.type, TSO.stackBytes}
Type Seq Finding
view deep-stack "Deep thread stacks" section "Diagnostics" =
[ card c { chips = [ chip "stack" (bytes c.stackBytes)
(tiers [ c.stackBytes >= 1MiB ~> bad
, c.stackBytes >= 128KiB ~> warn ]) ]
, frames = expand stack-frames { tso = c }
, ..drills c }
| c <- heap as TSO, c.stackBytes >= 64KiB
, order by c.stackBytes desc ]
#ap-stack-heavy — Suspended computations
Grade Cn reads {Frame.type, Node.retained, Node.self, Node.type}
Type Bag Finding
view ap-stack-heavy "Suspended computations" section "Diagnostics" =
amplifier (\c -> c.type in {AP, AP_STACK}) (minBytes = 16KiB) (minRatio = 8)
#retained-thunk — Large deferred computations
Grade Cn reads {Node.retained, Node.self, Node.type}
Type Bag Finding
view retained-thunk "Large deferred computations" section "Diagnostics" =
amplifier thunkBroad (minBytes = 64KiB) (minRatio = 16)
#lazy-container — Lazy containers
Grade Cn {dominators} reads {Frame.label, Frame.type, Node.label, Node.retained, Node.type}
Type Bag Finding
view lazy-container "Lazy containers" section "Diagnostics" =
lazyKids container (minKids = 3) (minFrac = 0.25) (hi = 0.33) (mid = 0.25)
#mut-arr-thunks — Lazy array elements
Grade Cn {dominators} reads {Frame.type, Node.retained, Node.type}
Type Bag Finding
view mut-arr-thunks "Lazy array elements" section "Diagnostics" =
lazyKids (\c -> c.type in {MUT_ARR_PTRS, SMALL_MUT_ARR_PTRS})
(minKids = 8) (minFrac = 0.5)
#mut-var-thunk — Thunks behind mutable cells
Grade Cn {dominators} reads {Frame.type, Node.retained, Node.type}
Type Bag Finding
view mut-var-thunk "Thunks behind mutable cells" section "Diagnostics" =
[ card c { bytes = m, ..drills c }
| c <- heap, c.type == MUT_VAR
, count (children c) == 1, all thunkLike (children c)
, m <- max (children c).retained, m >= 1KiB ]
#thunk-chain — Long thunk chains
Grade Cp {dominators, paths} reads {Frame.type, Node.retained, Node.type}
Type Bag Finding
view thunk-chain "Long thunk chains" section "Diagnostics" =
chainRun (what = "Long THUNK") (cell = thunkLike)
(minLen = 4) (minBytes = 4KiB)
#ind-pileup — Indirection build-up
Grade Cn reads {Frame.type, Node.self, Node.type}
Type Bag Finding
view ind-pileup "Indirection build-up" section "Diagnostics" =
[ card (rep g)
{ title = "{count g} pending {k} indirections"
, count = count g
, bytes = sum g.self
, evidence = top 3 .self g
, chips = [chip "count" (number (count g))
(tiers [count g >= 100k ~> bad,
count g >= 25k ~> warn])]
, ..drills (rep g) }
| c <- heap, indirection c
, group by c.type into (k, g)
, count g >= 5000, sum g.self >= 64KiB ]
#cons-list-thunks — Lazy spine lists
Grade Cp {dominators, paths} reads {Frame.label, Frame.type, Node.label, Node.retained, Node.type}
Type Bag Finding
view cons-list-thunks "Lazy spine lists" section "Diagnostics" =
[ card (first p) { title = "Lazy spine list ({count (nodes p)} cells)"
, count = count (nodes p)
, evidence = take 3 (nodes p)
, ..drills (first p) }
| p <- chains /dom[consish]/ consish
, count (nodes p) >= 20, (first p).retained >= 8KiB
, frac (\c -> any thunkLike (children c)) (nodes p) >= 0.5 ]
#pap-cluster — PAP clusters
Grade Cn {dominators, ipe} reads {Frame.label, Frame.pos, Frame.type, Node.label, Node.pos, Node.retained, Node.type}
Type Bag Finding
view pap-cluster "PAP clusters" section "Diagnostics" =
[ card (rep g)
{ title = "{count g} PAPs"
, count = count g
, bytes = domRetained g
, evidence = top 3 .retained g
, ..drills (rep g) }
| c <- heap, c.type == PAP
, group by (c.pos, c.label) into (_, g)
, count g >= 5, domRetained g >= 16KiB ]
#constructor-bloat — Constructor bloat
Grade Cn {dominators} reads {Frame.label, Frame.type, Node.label, Node.retained, Node.type}
Type Bag Finding
view constructor-bloat "Constructor bloat" section "Diagnostics" =
[ card (rep g)
{ title = "{count g} instances of {g.label}"
, count = count g
, bytes = domRetained g
, evidence = top 3 .retained g
, chips = [chip "instances" (number (count g))
(tiers [count g >= 100k ~> bad,
count g >= 25k ~> warn])]
, ..drills (rep g) }
| g <- heap
, g.type in CONSTR*, g.label contains ".", not (container g)
, group by (g.label, g.type)
, count g >= 5000, domRetained g >= 1MiB ]
#bco-retention — Bytecode retention
Grade Cn {dominators} reads {Frame.type, Node.type}
Type Bag Finding
view bco-retention "Bytecode retention" section "Diagnostics" =
[ card (rep g) { title = "{count g} bytecode objects"
, count = count g
, bytes = domRetained g
, ..drills (rep g) }
| g <- heap, g.type == BCO, group by g.type
, count g >= 200, domRetained g >= 1MiB ]
#Type profile
A census of live closures grouped by type, largest self-footprint first.
#type-profile — Closures by type
Grade Cn reads {Frame.label, Node.label, Node.self}
Type Seq { label : Text, count : Q 1, self : Q B, instances : Query type-instances, ifDead : Query freed-by, keptAlive : Query kept-alive-via }
view type-profile "Closures by type" section "Type profile" =
[ { c.label, count c, sum c.self
, instances = expand type-instances { label = c.label }
, ifDead = expand freed-by { via = c.label }
, keptAlive = expand kept-alive-via { residence = c.label } }
| c <- heap, group by c.label, order by sum c.self desc ]
#large-object-share — Large-object share by type
Grade Cn reads {Frame.label, Node.label, Node.self}
Type Seq { label : Text, count : Q 1, large_bytes : Q B, share : Q 1 }
view large-object-share "Large-object share by type"
(minSelf = 64B) section "Type profile" =
[ { c.label, count c, sum c.self as "Large bytes"
, sum c.self / (sum [ x.self | x <- heap, x.self >= minSelf ])
as "Share" }
| c <- heap, c.self >= minSelf, group by c.label
, order by sum c.self desc, limit 30 ]
#Dominators
The heap's biggest retainers: live closures grouped by what they are and where they were allocated, ranked by retained size — the bytes freed if the whole group died.
#dominators — Heap dominators
Grade Cn {dominators, ipe} reads {Frame.label, Frame.pos, Frame.type, Node.label, Node.pos, Node.retained, Node.self, Node.type}
Type Seq { label : Text, type : CType, site : SrcPos, count : Q 1, self : Q B, retained : Q B, max_retained : Q B, members : Seq Node, children : Query dom-under }
view dominators "Heap dominators" section "Dominators" show 100 =
[ { k.label, k.type, k.pos as "Site"
, count g, sum g.self
, domRetained g as "Retained"
, maxOr 0B g.retained as "Max retained"
, members = top 1000 .retained g
, children = expand dom-under { parent = rep g } }
| c <- heap, group by domKey c into (k, g)
, domRetained g >= 1KiB
, order by domRetained g desc, limit 1000 ]
#thread-retention — Per-thread retention
Grade Cn {dominators} reads {Frame.label, Frame.type, Node.label, Node.retained, Node.type}
Type Seq { label : Text, type : CType, retained : Q B, topChildren : Seq { label : Text, type : CType, retained : Q B }, retainedBy : Query retained-by, retainerPaths : Query retainer-paths, references : Query node-refs, dominates : Query dom-under }
view thread-retention "Per-thread retention" section "Dominators" show 100 =
[ { t.label, t.type, t.retained as "Retained"
, topChildren = [ { c.label, c.type, c.retained }
| c <- children t, order by c.retained desc, limit 20 ]
, ..drills t }
| t <- heap, t.type == TSO, order by t.retained desc, limit 200 ]
#By IPE
Allocations grouped by their source position (needs info-table provenance).
#alloc-sites — Allocations by source site
Grade Cn {dominators, ipe} reads {Frame.pos, Frame.type, Node.module, Node.name, Node.pos, Node.self, Node.type}
Type Seq { module : Text, name : Text, pos : SrcPos, count : Q 1, self : Q B, retained : Q B, byType : Seq { type : CType, n : Q 1 }, contents : Query site-contents }
view alloc-sites "Allocations by source site" section "By IPE" =
[ { ..k, count g, sum g.self, domRetained g as "Retained"
, byType = [ { c.type, n = count c }
| c <- g, group by c.type, order by count c desc ]
, contents = expand site-contents { module = k.module, pos = k.pos } }
| c <- heap, group by site c into (k, g)
, order by domRetained g desc ]
#module-sites — Modules, sites nested
Grade Cn {ipe} reads {Frame.label, Frame.pos, Node.label, Node.module, Node.pos, Node.self}
Type Seq { module : Text, objects : Q 1, self : Q B, sites : Seq { site : SrcPos, objects : Q 1, self : Q B, largest : Seq { label : Text, self : Q B } } }
view module-sites "Modules, sites nested" section "By IPE" =
[ { module = m, objects = count g, sum g.self
, sites = [ { site = k, objects = count s, sum s.self
, largest = [ { c.label, c.self }
| c <- s, order by c.self desc, limit 5 ] }
| c <- g, group by c.pos into (k, s)
, order by sum s.self desc ] }
| c <- heap, c.module /= "", group by c.module into (m, g)
, order by sum g.self desc, limit 100 ]
#Search
Find large lazy values, flat and grouped by how they are retained.
#find — Find: lazy values over 8.00 KiB
Grade Cn {ipe} reads {Frame.label, Frame.pos, Frame.type, Node.label, Node.pos, Node.retained, Node.type}
Type Seq { label : Text, type : CType, retained : Q B, site : SrcPos, retainedBy : Query retained-by, retainerPaths : Query retainer-paths, references : Query node-refs, dominates : Query dom-under }
view find "Find: lazy values over {minBytes}"
(minBytes = 8KiB) section "Search" =
[ { c.label, c.type, c.retained, c.pos as "Site", ..drills c }
| c <- heap, thunkBroad c, c.retained >= minBytes
, order by c.retained desc, limit 200 ]
#find-collapsed — Matches grouped by retention
Grade Cp {dominators, paths, reverse-graph} reads {Frame.label, Node.label, Node.retained, Node.type}
Type Seq { label : Text, count : Q 1, retained : Q B, members : Bag (Thunk \| Ap) \| BlackHole }
view find-collapsed "Matches grouped by retention" section "Search" =
[ { (rep c).label, count c, domRetained c as "Retained"
, members = collect c }
| c <- heap, thunkBroad c, c.retained >= 8KiB
, group by retainerSig c, order by count c desc, limit 200 ]
#Thunk-retained
Data alive only through unevaluated thunks — what forcing could free — and its attribution to first-level thunks.
#thunk-retained — Only retained through thunks
Grade Cp {paths, reverse-graph, roots} reads {Frame.label, Node.label, Node.self, Node.type}
Type Seq { label : Text, count : Q 1, self : Q B }
view thunk-retained "Only retained through thunks"
section "Thunk-retained" show 100 =
[ { c.label, count c, sum c.self }
| c <- heap, not (c in plainAlive)
, group by c.label, order by sum c.self desc, limit 200 ]
#thunk-frontier — Data of first-level thunks
Grade Cp {paths, reverse-graph, roots} reads {Frame.label, Node.label, Node.self, Node.type}
Type Seq { label : Text, count : Q 1, self : Q B }
view thunk-frontier "Data of first-level thunks"
section "Thunk-retained" show 100 =
[ { d.label, count d, sum d.self }
| d <- heap, not (d in plainAlive), d in underFrontier
, group by d.label, order by sum d.self desc, limit 200 ]
#thunk-strict — Only retained by first-level thunks
Grade C? {paths, reverse-graph, roots} reads {Edge.src, Edge.tgt, Frame.label, Node.label, Node.rooted, Node.self, Node.type}
Type Seq { label : Text, self : Q B, parents : Q 1 }
view thunk-strict "Only retained by first-level thunks"
section "Thunk-retained" show 100 =
[ { e.tgt.label, self = e.tgt.self, parents = count e }
| e <- edges, not (e.tgt in plainAlive), e.tgt.rooted
, group by (e.tgt, e.tgt.label, e.tgt.self)
, all frontierRetainer e.src
, order by self desc, limit 200 ]
#Selectors
Every selector thunk, biggest retainers first.
#selectors — All selectors
Grade Cn {ipe} reads {Frame.label, Frame.pos, Frame.type, Node.label, Node.pos, Node.retained, Node.type}
Type Seq { label : Text, retained : Q B, site : SrcPos, retainedBy : Query retained-by, retainerPaths : Query retainer-paths, references : Query node-refs, dominates : Query dom-under }
view selectors "All selectors" section "Selectors" show 50 =
[ { c.label, c.retained, c.pos as "Site", ..drills c }
| c <- heap, c.type == SELECTOR, order by c.retained desc ]
#Cycles
Closures on strong reference cycles: mutually-retaining groups (TVar/MVar rings, knot-tied structures), found by the SCC kernel.
#reference-cycles — Reference cycles
Grade Cp {paths, reverse-graph} reads {Frame.label, Frame.type, Node.label, Node.self, Node.type}
Type Seq { label : Text, type : CType, count : Q 1, self : Q B }
view reference-cycles "Reference cycles" section "Cycles" show 50 =
[ { c.label, c.type, count c, sum c.self }
| c <- heap, c -[strong+]-> c
, group by (c.label, c.type), order by sum c.self desc ]
#stm-cycles — STM retainer loops
Grade Cp {paths, reverse-graph} reads {Node.self, Node.type}
Type Seq Finding
view stm-cycles "STM retainer loops" section "Cycles" =
[ card (rep s) { title = "Cycle of {count s} nodes, {sum s.self}"
, bytes = sum s.self
, evidence = top 5 .self s
, ..drills (rep s) }
| s <- scc strong
, any (is TVar) s, any (is TSO) s
, order by sum s.self desc ]
#Type points-from
Which types reference which: a census over pointer edges.
#points-from — Type -> type references
Grade Ce {reverse-graph} reads {Edge.src, Edge.tgt, Frame.label, Node.label, Node.self}
Type Seq { from : Text, to : Text, refs : Q 1, bytes : Q B, examples : Query edge-examples }
view points-from "Type -> type references"
section "Type points-from" grade Ce =
[ { e.src.label as "From", e.tgt.label as "To"
, count e as "Refs", sum (distinct e.tgt).self as "Bytes"
, examples = expand edge-examples
{ from = e.src.label, to = e.tgt.label } }
| e <- edges, group by (e.src.label, e.tgt.label)
, order by count e desc ]
#Duplicates
Structurally identical objects that could be shared, by copy count and bytes.
#duplicate-objects — Duplicate objects
Grade Cn {ipe, object-hash} reads {Block.addr, Frame.label, Frame.pos, Frame.type, Node.addr, Node.label, Node.pos, Node.retained, Node.self, Node.type}
Type Seq { label : Text, type : CType, n : Q 1, self : Q B, copies : Seq { addr : Addr, self : Q B, retained : Q B, site : SrcPos } }
view duplicate-objects "Duplicate objects" section "Duplicates" =
[ { k.label, k.type, n = count g as "Copies", sum g.self
, copies = [ { c.addr, c.self, c.retained, c.pos as "Site" }
| c <- g, order by c.retained desc, limit 200 ] }
| c <- heap, group by objectKey c into (k, g)
, count g >= 2, sum g.self >= 1KiB
, order by sum g.self desc, limit 200 ]
#Eras
Allocation-era cohorts (needs era profiling): live objects by when they were allocated — old cohorts that keep growing are the classic leak signal.
#era-profile — Live bytes by era
Grade Cn {eras} reads {Node.era, Node.self}
Type Seq { era : Era, count : Q 1, self : Q B }
view era-profile "Live bytes by era" section "Eras" =
[ { c.era, count c, sum c.self }
| c <- heap, group by c.era, order by c.era ]
#era-survivors — Old-cohort survivors
Grade Cn {eras, ipe} reads {Frame.label, Frame.pos, Node.era, Node.label, Node.pos, Node.self}
Type Seq { era : Era, label : Text, site : SrcPos, count : Q 1, self : Q B, instances : Query type-instances }
view era-survivors "Old-cohort survivors" (back = 2) section "Eras" show 100 =
[ { c.era, c.label, c.pos as "Site", count c, sum c.self
, instances = expand type-instances { label = c.label } }
| c <- heap, c.era <= eraBack back
, group by (c.era, c.label, c.pos), order by sum c.self desc ]
#Retainers
Exact retention counterfactuals (the multi-world kernel): what the GC would free if every value of a candidate type died, and what each root class keeps alive — all candidates in one pass.
#kept-alive — Heap residence — kept alive via
Grade Cn reads {Frame.label, Node.label, Node.self}
Type Seq { type : Text, count : Q 1, residence : Q B, keptAliveVia : Query kept-alive-via }
view kept-alive "Heap residence — kept alive via"
section "Retainers" show 100 =
[ { c.label as "Type", count c, sum c.self as "Residence"
, keptAliveVia = expand kept-alive-via { residence = c.label } }
| c <- heap, group by c.label
, order by sum c.self desc, limit 200 ]
#retainer-types — Freed if each type died
Grade Cp {paths, reverse-graph, roots} reads {Frame.label, Node.label, Node.retained, Node.self}
Type Seq { if_every_value_of_this_type_died : Text, n : Q 1, bytes : Q B, freed : Query freed-by }
view retainer-types "Freed if each type died"
(minRetained = 256KiB) section "Retainers" =
[ { k as "If every value of this type died"
, n = count b, bytes = sum b.self
, freed = expand freed-by { via = k } }
| (k, freed) <- deletionWorlds (\n -> n.label)
(distinctValues
[ c.label | c <- heap, c.retained >= minRetained ])
, b <- toBag freed
, group by k, order by bytes desc ]
#root-attribution — Retained by each root class
Grade Cp {paths, reverse-graph, roots} reads {Frame.label, Node.label, Node.self, Root.node}
Type Seq { root_class : Text, n : Q 1, bytes : Q B }
view root-attribution "Retained by each root class" section "Retainers" =
[ { k as "Root class", n = count b, bytes = sum b.self }
| (k, kept) <- retainedByEach (\r -> r.label)
(distinctValues [ r.node.label | r <- roots ])
, b <- toBag kept
, group by k, order by bytes desc ]
#Weak & stable
Weak pointers, finalizers and stable roots: memory held by the reference machinery itself — the Haskell analogue of the detached-DOM checklist.
#weak-pointers — Weak pointers
Grade Cn reads {Block.addr, Node.addr, Node.retained, Node.self, Node.type}
Type Seq { addr : Addr, self : Q B, retained : Q B, contents : Query cell-contents, retainedBy : Query retained-by, retainerPaths : Query retainer-paths, references : Query node-refs, dominates : Query dom-under }
view weak-pointers "Weak pointers" section "Weak & stable" =
[ { w.addr, w.self, w.retained
, contents = expand cell-contents { node = w }, ..drills w }
| w <- heap as Weak, order by w.retained desc, limit 500 ]
#weakly-retained — Alive only via weak references
Grade Cp {paths, reverse-graph, roots} reads {Frame.label, Frame.type, Node.label, Node.retained, Node.self, Node.type}
Type Seq { label : Text, type : CType, self : Q B, retained : Q B, retainedBy : Query retained-by, retainerPaths : Query retainer-paths, references : Query node-refs, dominates : Query dom-under }
view weakly-retained "Alive only via weak references"
section "Weak & stable" =
[ { c.label, c.type, c.self, c.retained, ..drills c }
| c <- heap, not (c in aliveVia /strong*/)
, order by c.retained desc, limit 200 ]
#finalizer-retention — Finalizer retention
Grade Cn {weak} reads {Block.addr, Frame.label, Frame.type, Node.addr, Node.label, Node.retained, Node.type, Weak.finalizer} — needs weak, not supported by this backend
Type Seq { weak : Addr, label : Text, type : CType, retained : Q B, retainedBy : Query retained-by, retainerPaths : Query retainer-paths, references : Query node-refs, dominates : Query dom-under }
view finalizer-retention "Finalizer retention" section "Weak & stable" =
[ { w.addr as "Weak", f.label, f.type, f.retained, ..drills f }
| w <- heap as Weak, f <- w.finalizer
, order by f.retained desc, limit 200 ]
#ephemeron-cycles — Weak value retains its key
Grade C? {closure-fields, paths, reverse-graph, weak} reads {Block.addr, Frame.label, MVar.value, Node.addr, Node.label, Node.retained, Node.type, TVar.value, Weak.key, Weak.value} — needs closure-fields, weak, not supported by this backend
Type Bag { weak : Addr, key : Text, value : Text, retained : Q B, retainedBy : Query retained-by, retainerPaths : Query retainer-paths, references : Query node-refs, dominates : Query dom-under }
view ephemeron-cycles "Weak value retains its key" section "Weak & stable" =
[ { w.addr as "Weak", k.label as "Key", v.label as "Value"
, k.retained, ..drills w }
| w <- heap as Weak, k <- w.key, v <- w.value
, k in reachable /ptr*/ (toSet [v]) ]
#stable-roots — Stable-pointer roots
Grade Cr {roots} reads {Frame.label, Frame.type, Node.label, Node.retained, Node.self, Node.type, Root.kind, Root.node}
Type Seq { label : Text, type : CType, self : Q B, retained : Q B, keeps : Query dom-under, retainedBy : Query retained-by, retainerPaths : Query retainer-paths }
view stable-roots "Stable-pointer roots" section "Weak & stable" show 100 =
[ { n.label, n.type, n.self, n.retained
, keeps = expand dom-under { parent = n }, ..ascents n }
| r <- roots, r.kind in {STABLE_PTR, STABLE_NAME}, let n = r.node
, order by n.retained desc, limit 200 ]
#Fragmentation
Heap-block utilisation: blocks holding far less live data than their size — memory the profiler counts but the OS cannot reclaim.
#low-occupancy-blocks — Low-occupancy blocks
Grade Cn {blocks} reads {Block.addr, Block.live, Block.objects, Block.occupancy, Block.pinned, Node.addr}
Type Seq { addr : Addr, pinned : Bool, objects : Q 1, live : Q B, occupancy : Q 1, holds : Query block-closures }
view low-occupancy-blocks "Low-occupancy blocks"
section "Fragmentation" grade Cn show 100 =
[ { b.addr, b.pinned, b.objects, b.live, b.occupancy
, holds = expand block-closures { block = b.addr } }
| b <- blocks, b.occupancy <= 0.5
, order by b.occupancy asc, limit 1000 ]
#pinned-blocks — Pinned blocks
Grade Cn {blocks} reads {Block.addr, Block.live, Block.objects, Block.occupancy, Block.pinned, Node.addr}
Type Seq { addr : Addr, objects : Q 1, live : Q B, occupancy : Q 1, holds : Query block-closures }
view pinned-blocks "Pinned blocks" section "Fragmentation" show 100 =
[ { b.addr, b.objects, b.live, b.occupancy
, holds = expand block-closures { block = b.addr } }
| b <- blocks, b.pinned
, order by b.occupancy asc, limit 1000 ]
#block-contents — Closures by block
Grade Cn {blocks} reads {Block.addr, Block.occupancy, Block.pinned, Frame.label, Frame.type, Node.addr, Node.block, Node.label, Node.self, Node.type}
Type Seq { addr : Addr, pinned : Bool, occupancy : Q 1, label : Text, type : CType, self : Q B, retainedBy : Query retained-by, retainerPaths : Query retainer-paths, references : Query node-refs, dominates : Query dom-under }
view block-contents "Closures by block" section "Fragmentation" show 100 =
[ { b.addr, b.pinned, b.occupancy, c.label, c.type, c.self, ..drills c }
| b <- blocks, c <- heap, c.block == b.addr
, order by c.self desc, limit 1000 ]
#Garbage
Floating garbage: closures the GC will reclaim but has not yet, recovered by scanning blocks and subtracting the reachable set — what the program is churning. Needs a connector that ships block frontiers.
#garbage-census — Garbage by constructor
Grade Ce {blocks} reads {Frame.label, Node.label, Node.rooted, Node.self}
Type Seq { label : Text, count : Q 1, self : Q B }
view garbage-census "Garbage by constructor" section "Garbage" show 100 =
[ { c.label, count c, sum c.self }
| c <- allocated, not c.rooted
, group by c.label, order by sum c.self desc ]
#garbage-sites — Garbage by source site
Grade Ce {blocks, ipe} reads {Frame.pos, Node.module, Node.name, Node.pos, Node.rooted, Node.self}
Type Seq { module : Text, site : SrcPos, count : Q 1, self : Q B, contents : Query garbage-site-contents }
view garbage-sites "Garbage by source site" section "Garbage" show 100 =
[ { c.module, c.pos as "Site", count c, sum c.self
, contents = expand garbage-site-contents
{ module = c.module, pos = c.pos } }
| c <- allocated, not c.rooted, c.module /= ""
, group by (c.module, c.name, c.pos), order by sum c.self desc ]
#garbage-churn — Live vs dead by type
Grade Ce {blocks} reads {Frame.label, Node.label, Node.rooted, Node.self}
Type Seq { label : Text, total : Q 1, dead : Q 1, deadBytes : Q B, deadFrac : Q 1 }
view garbage-churn "Live vs dead by type" section "Garbage" show 100 =
[ { c.label, total = count c, dead = nDead c, deadBytes = bDead c
, deadFrac = 1 - frac (.rooted) c }
| c <- allocated, group by c.label, order by bDead c desc ]
#garbage-largest — Largest dead objects
Grade Ce {blocks, ipe} reads {Frame.label, Frame.pos, Node.label, Node.pos, Node.rooted, Node.self}
Type Seq { label : Text, self : Q B, site : SrcPos, retainedBy : Query retained-by, retainerPaths : Query retainer-paths, references : Query node-refs, dominates : Query dom-under }
view garbage-largest "Largest dead objects" section "Garbage" show 50 =
[ { c.label, c.self, c.pos as "Site", ..drills c }
| c <- allocated, not c.rooted, order by c.self desc, limit 200 ]
#dead-thunks — Dead thunks and blackholes
Grade Ce {blocks, ipe} reads {Frame.label, Frame.pos, Frame.type, Node.label, Node.pos, Node.rooted, Node.self, Node.type}
Type Seq { label : Text, site : SrcPos, count : Q 1, self : Q B }
view dead-thunks "Dead thunks and blackholes" section "Garbage" show 100 =
[ { c.label, c.pos as "Site", count c, sum c.self }
| c <- allocated, not c.rooted
, c.type in {THUNK, SELECTOR, AP, AP_STACK, BLACKHOLE}
, group by (c.label, c.pos), order by sum c.self desc ]
#garbage-duplicates — Duplicate dead objects
Grade Ce {blocks, ipe, object-hash} reads {Block.addr, Frame.label, Frame.pos, Frame.type, Node.addr, Node.label, Node.pos, Node.rooted, Node.self, Node.type}
Type Seq { label : Text, type : CType, n : Q 1, self : Q B, copies : Seq { addr : Addr, self : Q B, site : SrcPos } }
view garbage-duplicates "Duplicate dead objects" section "Garbage" show 100 =
[ { k.label, k.type, n = count g as "Copies", sum g.self
, copies = [ { c.addr, c.self, c.pos as "Site" }
| c <- g, order by c.self desc, limit 200 ] }
| c <- allocated, not c.rooted, group by objectKey c into (k, g)
, count g >= 2, order by sum g.self desc ]
#dead-buffers — Duplicate dead byte arrays
Grade Ce {blocks} reads {Frame.type, Node.rooted, Node.self, Node.type}
Type Seq { copies : Q 1, wasted : Q B }
view dead-buffers "Duplicate dead byte arrays" section "Garbage" show 100 =
[ { copies = count c, wasted = sum c.self }
| c <- allocated, not c.rooted, c.type == ARR_WORDS
, group by contentHash c, count c >= 2, order by sum c.self desc ]
#garbage-by-era — Garbage by era
Grade Ce {blocks, eras} reads {Node.era, Node.rooted, Node.self}
Type Seq { era : Era, count : Q 1, self : Q B }
view garbage-by-era "Garbage by era" section "Garbage" =
[ { c.era, count c, sum c.self }
| c <- allocated, not c.rooted, group by c.era, order by c.era ]
#garbage-shape — Dead closure -> pointee type
Grade Ce {blocks, reverse-graph} reads {Edge.tgt, Frame.label, Frame.type, Node.label, Node.rooted, Node.type}
Type Seq { label : Text, points_to : CType, count : Q 1 }
view garbage-shape "Dead closure -> pointee type" section "Garbage" show 100 =
[ { c.label, points_to = (e.tgt).type, count e }
| c <- allocated, not c.rooted, e <- outEdges c
, group by (c.label, (e.tgt).type), order by count e desc ]
#garbage-blocks — Blocks holding garbage
Grade Cn {blocks} reads {Block.addr, Block.dead, Block.deadBytes, Block.garbageFrac, Block.live, Block.pinned, Node.addr}
Type Seq { addr : Addr, pinned : Bool, live : Q B, deadBytes : Q B, garbageFrac : Q 1, holds : Query block-closures }
view garbage-blocks "Blocks holding garbage" section "Garbage" show 100 =
[ { b.addr, b.pinned, b.live, b.deadBytes, b.garbageFrac
, holds = expand block-closures { block = b.addr } }
| b <- blocks, b.dead > 0, order by b.deadBytes desc ]
#Helpers
Reusable detector combinators the views above share. The knob-record helpers list every parameter they accept.
#notThunk
Type Node -> Bool
let notThunk c = not (thunkBroad c)
#plainAlive
Type Set Node
let plainAlive = aliveVia /(ptr[notThunk])* ptr{0,1}/
#underFrontier
Type Set Node
let underFrontier =
aliveVia /(ptr[notThunk])* ptr[thunkBroad] (ptr[notThunk])* ptr{0,1}/
#frontierRetainer
Type Node -> Bool
let frontierRetainer p = thunkBroad p && p in plainAlive