Skip to content

perf(core): reuse Sets in notification loop instead of allocating per flush#108

Merged
nerdalytics merged 1 commit into
trunkfrom
perf/64-reuse-sets-in-notification-loop
Apr 6, 2026
Merged

perf(core): reuse Sets in notification loop instead of allocating per flush#108
nerdalytics merged 1 commit into
trunkfrom
perf/64-reuse-sets-in-notification-loop

Conversation

@nerdalytics
Copy link
Copy Markdown
Owner

Closes #64

Summary

  • Replace new Set() allocation on every flush iteration with a double-buffer pattern using two pre-allocated Sets (flushing/queued)
  • After iterating a buffer, .clear() it so it's ready for reuse on the next iteration
  • Eliminates GC pressure from short-lived Set allocations under cascading-update workloads

Benchmark

Derive chain depth=10, 100k iterations per batch:

Avg Min
Before (new Set per flush) 3.405ms 2.389ms
After (double-buffer) 2.191ms 1.467ms

~38% improvement.

Test plan

  • Biome lint passes
  • TypeScript compiles with no errors
  • All 117 tests pass
  • Benchmarked before/after

… flush (#64)

Replace new Set() allocation on every flush iteration with a
double-buffer pattern using two pre-allocated Sets (flushing/queued).
Eliminates GC pressure from short-lived Set allocations under
cascading-update workloads.

Benchmarked: ~38% improvement on derive chain (depth 10, 100k iterations).
@nerdalytics nerdalytics merged commit 4d545e5 into trunk Apr 6, 2026
12 checks passed
@nerdalytics nerdalytics deleted the perf/64-reuse-sets-in-notification-loop branch April 6, 2026 18:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

core: reuse Sets in notification loop instead of allocating per flush

1 participant