Skip to content

Parse messages in linear time and bound the receive buffer - #3

Merged
2rdzy merged 2 commits into
masterfrom
fix/message-parser
Oct 6, 2026
Merged

2rdzy merged 2 commits into
masterfrom
fix/message-parser

Conversation

@2rdzy

@2rdzy 2rdzy commented Oct 5, 2026

Copy link
Copy Markdown
Owner

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.

  • Cut each message out with indexOf; skip empty lines.
  • Refuse more than maxBuffer bytes (default 64 MiB, option maxBuffer) 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.

2rdzy added 2 commits October 5, 2026 22:14
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.
@2rdzy
2rdzy merged commit 64c264a into master Oct 6, 2026
5 of 6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant