Performance is poor when lines are much longer than stream chunks
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 296
- Forks
- 25
- PR merge metrics
- No merged PRs in 30d
Description
Suppose we have lines that are very long (sometimes tens of megabytes each of JSON in my case), and stream chunks of more normal length, say 16kB. That means there can be over 1000 chunks per line. This comes up when trying to fetch the changes stream from NPM's couchdb replication endpoint for example.
Each time a new chunk comes in, it gets appended to this[kLast] and then string.split() get called on the resulting string. This means that string.split() is getting called over 1000 times to find a single newline, so splitting in effect becomes O(n^2) in the length of the line.
The fast way to do this is to search for \n before appending to this[kLast]. Unfortunately that doesn't work properly if you have a delimiter like the default /\r?\n/ that can cross chunk boundaries.
So I don't know if this is something you can easily fix while keeping the same interface. A fast-path option that only works for a single character delimiter, or maybe a fixed delimiter string but not functions or regexes, would be handy.
Do you have any better ideas? Or is this use case out of scope for this package? Or am I doing something else dumb?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing how incoming chunks update this[kLast] and how string.split() handles delimiters crossing chunk boundaries. Done means improving long-line performance without changing the existing interface or delimiter behavior; the issue does not name a file or test to run.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- performance, stream-processing
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100