Re: What is "cheaper"?
Jesper Louis Andersen <[email protected]>
| Newsgroups | gmane.comp.lang.erlang.general |
|---|---|
| Message-ID | <CAGrdgiWaGs-FXyP2m856A2WFZsBk6yHPUiUEad+-DU2_VqRXjA@mail.gmail.com> |
On Thu, Mar 25, 2021 at 1:14 PM Valentin Micic <[email protected]> wrote: > Usually, when I use erlang:send_after/3, but no longer need the “ordered" > event, I issue a corresponding erlang:cancel_timer/1 to stop this event > from being raised. > > Correctness is also a player in this. For some protocols, you absolutely want the cancellation to be there in order to avoid a stale message, though they tend to be hard to completely avoid (because the timer expiration and message send happens before the cancel is executed. The window is small, but present). Another important point is the amount of timers you have running, and how quickly you start new timers. If your timer is for an hour, and you generate 100 timers a second, it runs up, quickly. It might be reasonably efficient to fire those timers into the void, but they also take up space while they are just sitting there.