Closed basham closed 1 year ago
For reference, I'm noticing eraseExpiredDocs()
takes about 1.5ms per call. After about 3ms, it is being called again. This repeats forever.
Oh yeah. That's... me just forgetting to pass an argument. Thanks for catching this.
I'm profiling my browser app with the latest Earthstar 9.3.2. The replica's
eraseExpiredDocs()
method is being called continuously. This happens because there's asetInterval()
with no delay argument. This means it is called at every tick. This seems like lots of unnecessary work and CPU time. I don't know what is a more reasonable default delay. Maybe once a minute? You could consider adding an option to the Replica constructor to allow this delay to be configured by the user.Alternatively, on load, the Replica could query to find the timestamps of all the expiring docs. Then set up
setTimeout()
to calleraseExpiredDocs()
at the designated time. Once that completes, initiate anothersetTimeout()
. This is better than setting up timers for every expired docs, as it will scale better. When a new doc is added to the Replica that has an expiration, add that timestamp to the list. If it is sooner than the active timer, then stop the timer and set up a new one for that newest timestamp.Even though its slightly more work, I'd advocate for the second option (or something like it). I don't currently plan to have any expiring docs, so I'd like something that has as minimal CPU/memory impact as possible.