Skip to content

Reduce Buffer operations in EventSource #2630

Open
@Uzlopak

Description

@Uzlopak

In the EventSourceStream code of the initial EventSource implementation, alot of Buffer Operations are used to process the incoming Stream. The Buffer operations are concentrated in the _transform and parseLine method of the EventSourceStream.

I am sure, we can reduce the overhead of the buffer operations by using some simple integer variables, marking start and end of the Buffer we want to extract the subarray and then pass it accordingly parseLine method.

Maybe the Buffer.concat operation to buffer the incoming chunks can be avoided. But be careful, as the incoming stream is containing utf8 code. So you have to concat the buffers at one point to avoid utf8 issues.

In the parseLine method the field and value are also processed via .subarray. Maybe first calling toString('utf8') and then processing it makes more sense? Anyhow, some benchmarking would be useful to make a informed decision.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesteventsourcePull requests or issues related to EventSource and its standard

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions