chouzar / chip

Registry library for gleam
12 stars 2 forks source link

As subjects are registered, the selector keeps growing. #2

Closed chouzar closed 1 month ago

chouzar commented 4 months ago
  1. Test how number of subjects affect performance (memory consumption, slowdown).
  2. Divise an approach to clean loose selectors.
chouzar commented 4 months ago

A previous attempt at solving this was to do a cleanup after a condition met. Needed to keep track of the actor itself self and a copy of the actor's selector or monitors in state:

type State(msg, tag, group) {
  State(
    self: Registry(msg, tag, group),
    selector: process.Selector(Message(msg, tag, group)),
    monitors: set.Set(process.ProcessMonitor)
  )

Then when a threshold is reached, send a Cleanup message to self so that we can rebuild the selector with the current stored monitors.

chouzar commented 4 months ago

We may use this type to re-build a selector:

type State(msg, tag, group) {
  State(
    // This keeps track of registered subjects and where to look for them on de-registration.
    registration: Dict(process.Pid, set.Set(Registrant(msg, tag, group)))
  )
}
chouzar commented 1 month ago

This was solved in 4dccee8c4b858f03da41c142a3ae881f82cd43fa

The selector growing didn't turn out to be a big issue:

https://github.com/chouzar/chip/blob/1cbf02bfec648c6d21e83dec3b755124f58834d8/Benchmarks.md?plain=1#L27-L45