Skip to content

Conversation

@KiKoS0
Copy link
Contributor

@KiKoS0 KiKoS0 commented Jan 16, 2026

Bunch of optimizations regarding memory allocation, reducing lock contention in pauses aggregator:

  • MatchResult was flattened from a nested map to a single map[matchKey]int, removed mutex from it so it's no longer thread safe but the synchronization overhead of multiple goroutines writing to it likely outweighed the parallelism gains.
  • Add a sync.Pool for MatchResult to reduce allocations per eval.
  • Removed goroutine pools from engine Match() methods, the spawning/scheduling/atomics overhead was likely beating the purpose of actually parallelizing these typically small iterations.
  • Remove() is now O(1): just stores the ID of the deleted evaluable in a sync.Map. A background gcWorker goroutine periodically drains the deleted set in batches so that we never block evaluations for long periods. Engine Remove() also takes a batch now, single lock acquisition per batch.
  • rand.Rand can also be pooled via sync.Pool in the parser.

@KiKoS0 KiKoS0 force-pushed the riadh/mem-optimization branch from b882245 to 3874414 Compare January 28, 2026 20:57
@KiKoS0 KiKoS0 force-pushed the riadh/mem-optimization branch from 3bba3e2 to a904502 Compare January 28, 2026 23:59
expr_test.go Outdated
// NOTE: With async GC, Remove() no longer returns an error for non-existent items
// It just marks the ID as deleted, and GC handles cleanup
// err = e.Remove(ctx, tex(`event.data.another == "i'm not here"`))
// require.Error(t, ErrEvaluableNotFound, err)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: probably can delete these lines now

@KiKoS0 KiKoS0 marked this pull request as ready for review January 30, 2026 11:13
@KiKoS0 KiKoS0 force-pushed the riadh/mem-optimization branch from 31eec77 to a25724b Compare January 30, 2026 11:19
@KiKoS0 KiKoS0 merged commit 06d5fe6 into main Jan 30, 2026
2 checks passed
@KiKoS0 KiKoS0 deleted the riadh/mem-optimization branch January 30, 2026 11:23
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.

2 participants