Description
Specification
Currently, the tracer is pull-based. The events are generated and added to a global queue, which a generator can consume. This is bad, as if no consumers are present, then the events can start building up indefinitely.
To fix this, we need to adopt a push-based dataflow, where there is a source of events which are all consumed in real-time by subscribers via callbacks. This approach draws inspiration from how rxjs
handles this.
For this implementation, however, rxjs
is unnecessary complexity and we can make do with only WebStreams
or EventEmitters
internally. I'm leaning towards using streams, as streams handle backpressure for us if the consuming callbacks are slower than incoming data. However, that might mean an observable slowdown of the program if the backpressure buffer is full. To avoid this, we may need to create an unbound buffer, but that would again result in the same issue where the buffer can grow indefinitely. It would be a bit more manageable here, as events can be ignored if no consumers have been registered. This would need some discussion.
Additional context
Tasks
- Switch from pull-based to push-based design
- Incorporate rxjs or streams to manage resources
- Should support multiple consumers or subscribers
- Add benchmarks for different approaches like observables and webstreams