Repository navigation
Parse messages in linear time and bound the receive buffer - #3
Merged
Merged
Conversation
Add node:test tests against a small in-process Electrum server over TCP and TLS (with a committed, test-only certificate), covering requests, errors, concurrency, batches, notifications and close. Run them in CI on Node 18, 20 and 22. Point the repository, bugs and homepage fields at this fork, require Node 18 or later, and publish only index.js and lib.
The parser split the whole buffer on every message, so a reply holding many messages (a long address history) took quadratic time: 20,000 messages of about 200 bytes took 21 seconds, and now take 15 milliseconds. It also kept growing the buffer for a server that never sends a newline. Cut each message out with indexOf, skip empty lines, and refuse more than maxBuffer bytes (default 64 MiB, option maxBuffer) without a delimiter by reporting an error and dropping the connection. createRecuesiveParser, an internal helper used only by the parser, is removed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Builds on the test harness in #1 (merge that first).
The parser split the whole buffer on every message, so a reply holding many messages (a long address history) took quadratic time: 20,000 messages of about 200 bytes took 21 seconds; now they take 15 milliseconds. It also kept growing its buffer for a server that never sends a newline.
indexOf; skip empty lines.maxBufferbytes (default 64 MiB, optionmaxBuffer) without a delimiter: report an error and drop the connection.createRecuesiveParser, an internal helper used only by the parser, is removed.Unit tests for the parser (including a speed check and the 20-message limit the old one had) and a client test for the buffer limit.