~/talk

Blazing Fast Merge with Loser Trees

Talkat GopherCon 2023 · 2023-09-26..09-29· [go]
slides:none on file

Implements a k‑way merge using a Loser Tree in Go, using generics to eliminate indirect calls and storing leaf values to avoid repeated sequence lookups. Benchmarks show 5–12× faster microbenchmark versus container/heap, memory rises (about 6 MB extra for 100k series), and a generic fallback using a comparison function is generics vs function‑pointer ~2× slower because the call doesn’t inline. Applied in production systems (Prometheus PR 12878, Grafana Loki PR 8351) with real workloads yielding ~30% faster Loki queries, so the structure is practical and effective.

AI-written summary · about

  1. 0:00Introduction
  2. 1:10Optimizing algorithms like a game
  3. 2:36Heap bottleneck in Prometheus
  4. 5:04K-way merge problem
  5. 6:30Loser tree introduction
  6. 8:24How loser trees work
  7. 12:44Complexity of loser trees
  8. 14:51Go generics implementation
  9. 18:30Node storage and inner loop
  10. 20:21Benchmarking loser trees
  11. 23:16Adapting loser trees for Loki
  12. 25:28Go generics limitations
  13. 27:14Function pointers with loser trees
  14. 28:19Performance trade-offs
  15. 29:44Loser trees in production
  16. 31:29Visualizing loser trees
  17. 32:15Why loser trees beat heaps
  18. 33:21Lessons from Go generics
  19. 33:44Loser tree code
~/search
type to search 6,249 conferences, 138,987 speakers and 185,172 talks
~/help
cmdctrl k
search every conference, speaker and series
/
focus the filter search
h
home
c
conferences
s
speakers
e
series
t
light / dark — the status bar button does the same
?
this help
esc
close this, then clear every filter — or just the search, while you are typing in it

Ignored while you are typing. Pages without a filter rail have no search to focus.