Skip to content

Performance improvements part2#45

Merged
elcritch merged 7 commits into
mainfrom
performance-improvements-part2
Jun 4, 2026
Merged

Performance improvements part2#45
elcritch merged 7 commits into
mainfrom
performance-improvements-part2

Conversation

@elcritch

@elcritch elcritch commented Jun 3, 2026

Copy link
Copy Markdown
Owner

Summary

This PR improves subscription lookup performance for agents with larger subscription lists while preserving the fast path for small lists.

  • Keeps subcriptions sorted by signal name on insert.
  • Adds binary-search range lookup for larger subscription lists.
  • Uses a linear-scan fast path below sigilsSubscriptionBinarySearchThreshold to avoid regressing the common single-signal case.
  • Applies sorted insertion to AgentActor subscriptions as well.
  • Adds a regression test for sorted signal ranges plus AnySigilName wildcard lookup.
  • Adds tests/tbenchmarks3.nim, a multi-signal fanout benchmark with 6 signals x 6 slots.

Performance Notes

The small-list threshold keeps tests/tbenchmarks.nim close to the previous single-subscription behavior:

emit->slot procRatio ~= 18-19x
methodRatio ~= 13x

The new multi-signal benchmark stresses 36 subscriptions and exercises the binary-search path:

signals=6, slotsPerSignal=6, subscriptions=36
emits=600000, slotCalls=3600000

Local samples showed the multi-signal emit loop dropping from the earlier linear-scan sample around 283 ms to roughly 58-73 ms.

Testing

Ran:

nim c -r tests/tslots.nim
nim c -r tests/tclosures.nim
nim c -r tests/tweakrefs.nim
nim c -r tests/tregistryCloneSignals.nim
nim c -r tests/tthreadPool.nim
nim c -r -d:release tests/tbenchmarks.nim
nim c -r -d:release tests/tbenchmarks2.nim
nim c -r -d:release tests/tbenchmarks3.nim
git diff --check

@elcritch elcritch merged commit fa33f37 into main Jun 4, 2026
1 check passed
@elcritch elcritch deleted the performance-improvements-part2 branch June 4, 2026 03:46
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.

1 participant