Skip to content

perf(dicer): avoid regex when parsing headers#211

Open
mcollina wants to merge 3 commits into
mainfrom
perf/header-parser-fast-path
Open

perf(dicer): avoid regex when parsing headers#211
mcollina wants to merge 3 commits into
mainfrom
perf/header-parser-fast-path

Conversation

@mcollina
Copy link
Copy Markdown
Member

Summary

  • avoid regex-based header field parsing in Dicer's HeaderParser
  • scan CRLF-delimited header lines directly instead of using buffer.split(/\r\n/g)
  • preserve folded-header handling and existing malformed-header behavior

Performance

Local HeaderParser microbenchmark on a 3-header block:

  • before: ~1.78M ops/sec
  • after: ~2.66M ops/sec

A local @platformatic/flame run also confirmed HeaderParser._parseHeader remains a primary hotspot, but its self-time dropped in the targeted multipart workload.

Validation

  • npm test
  • npm run lint

Copy link
Copy Markdown
Member

@ivan-tymoshenko ivan-tymoshenko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@marcopiraccini
Copy link
Copy Markdown

lgtm

@mcollina
Copy link
Copy Markdown
Member Author

Added a follow-up optimization in 6d81635: HeaderParser now scans for the header terminator directly instead of routing header parsing through StreamSearch. I also added coverage for CRLFCRLF split across chunks, including after maxHeaderSize is reached.\n\nValidation:\n- npm test\n- npm run lint\n- npm run bench:dicer\n- remote CI checks are passing.

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.

4 participants