Skip to content

Remove API overhead and checks#59

Merged
blakeembrey merged 4 commits intomasterfrom
be/delete-overhead
Apr 3, 2026
Merged

Remove API overhead and checks#59
blakeembrey merged 4 commits intomasterfrom
be/delete-overhead

Conversation

@blakeembrey
Copy link
Copy Markdown
Member

Based on the improved parser PR, this one takes things further with major breaking changes to the API. It's intended to provide basic performance boosts and ignore things that are likely already occurring upstream or downstream of the package.

Example:

  • Accept string input only. Currently it accepts req/res objects but throws when the header field is missing. This would require upstream to grab it and validate behavior already, negating the need for these shortcuts.
  • Made parameters optional for a ~10% perf boost when no parameters present.
  • Stopped validating type on the parser (should done downstream anyway, no need to check the format is ideal here) for ~10% improvement across all benchmarks.
  • Stopped sorting parameter names, use object ordering provided in format (>10% boost when parameters are present)

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (4d2e19d) to head (f7a656e).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff            @@
##            master       #59   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files            1         1           
  Lines           97       107   +10     
  Branches        40        40           
=========================================
+ Hits            97       107   +10     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@blakeembrey
Copy link
Copy Markdown
Member Author

Benchmarking results as I refactoring, with some level of noise:

Begin:

 ✓ src/index.bench.ts > parse 5168ms
     name                                      hz     min     max    mean     p75     p99    p995    p999     rme  samples
   · basic                          11,095,872.87  0.0000  0.2537  0.0001  0.0001  0.0001  0.0002  0.0006  ±0.36%  5547937
   · simple parameters               2,790,153.54  0.0003  0.4071  0.0004  0.0004  0.0005  0.0005  0.0009  ±0.28%  1395077
   · quoted and escaped parameters   1,702,015.97  0.0005  5.0965  0.0006  0.0006  0.0007  0.0010  0.0023  ±2.04%   851008
   · OWS-heavy parameters            2,452,847.58  0.0003  0.4173  0.0004  0.0004  0.0005  0.0005  0.0011  ±0.30%  1226424

 ✓ src/index.bench.ts > format 4749ms
     name                                      hz     min     max    mean     p75     p99    p995    p999     rme  samples
   · basic                          16,051,491.72  0.0000  0.0642  0.0001  0.0001  0.0001  0.0001  0.0002  ±0.11%  8025747
   · simple parameters               2,126,189.29  0.0003  0.3365  0.0005  0.0005  0.0006  0.0010  0.0012  ±0.51%  1063095
   · quoted and escaped parameters   1,541,025.19  0.0005  0.4090  0.0006  0.0007  0.0008  0.0010  0.0013  ±0.35%   770513

Accept only 1 type:

 ✓ src/index.bench.ts > parse 5034ms
     name                                      hz     min     max    mean     p75     p99    p995    p999     rme  samples
   · basic                          11,089,125.38  0.0000  0.3371  0.0001  0.0001  0.0001  0.0001  0.0005  ±0.31%  5544563
   · simple parameters               2,727,523.95  0.0003  0.3662  0.0004  0.0004  0.0005  0.0005  0.0008  ±0.15%  1363763
   · quoted and escaped parameters   1,694,832.46  0.0005  0.3011  0.0006  0.0006  0.0007  0.0008  0.0012  ±0.23%   847417
   · OWS-heavy parameters            2,473,229.58  0.0003  0.0378  0.0004  0.0004  0.0005  0.0005  0.0008  ±0.04%  1236615

 ✓ src/index.bench.ts > format 4657ms
     name                                      hz     min     max    mean     p75     p99    p995    p999     rme  samples
   · basic                          15,526,014.57  0.0000  0.0418  0.0001  0.0001  0.0001  0.0001  0.0002  ±0.07%  7763008
   · simple parameters               2,094,746.67  0.0004  0.3286  0.0005  0.0005  0.0006  0.0010  0.0012  ±0.45%  1047374
   · quoted and escaped parameters   1,508,273.20  0.0005  0.3430  0.0007  0.0007  0.0008  0.0010  0.0013  ±0.44%   754137

Make parameters optional:

 ✓ src/index.bench.ts > parse 5372ms
     name                                      hz     min      max    mean     p75     p99    p995    p999     rme  samples
   · basic                          12,385,240.86  0.0000   1.4538  0.0001  0.0001  0.0001  0.0001  0.0002  ±0.58%  6192621
   · simple parameters               2,701,204.56  0.0002   0.3405  0.0004  0.0004  0.0005  0.0005  0.0008  ±0.19%  1350603
   · quoted and escaped parameters   1,652,974.56  0.0004  14.1370  0.0006  0.0006  0.0007  0.0010  0.0031  ±5.68%   826488
   · OWS-heavy parameters            2,480,004.50  0.0003   0.4736  0.0004  0.0004  0.0005  0.0005  0.0009  ±0.25%  1240003

 ✓ src/index.bench.ts > format 4804ms
     name                                      hz     min     max    mean     p75     p99    p995    p999     rme  samples
   · basic                          16,254,679.38  0.0000  0.0742  0.0001  0.0001  0.0001  0.0001  0.0002  ±0.10%  8127340
   · simple parameters               2,124,130.70  0.0003  0.3569  0.0005  0.0005  0.0006  0.0010  0.0012  ±0.49%  1062066
   · quoted and escaped parameters   1,518,046.69  0.0005  0.4213  0.0007  0.0007  0.0008  0.0010  0.0013  ±0.44%   759024

Stop validating type:

 ✓ src/index.bench.ts > parse 6342ms
     name                                      hz     min     max    mean     p75     p99    p995    p999     rme  samples
   · basic                          19,182,395.23  0.0000  0.5084  0.0001  0.0000  0.0001  0.0001  0.0002  ±0.25%  9591198
   · simple parameters               2,987,966.15  0.0002  0.2443  0.0003  0.0003  0.0004  0.0005  0.0008  ±0.11%  1493984
   · quoted and escaped parameters   1,819,740.33  0.0004  0.4465  0.0005  0.0005  0.0007  0.0009  0.0020  ±0.55%   909871
   · OWS-heavy parameters            2,678,027.18  0.0003  0.3218  0.0004  0.0004  0.0005  0.0005  0.0008  ±0.19%  1339014

 ✓ src/index.bench.ts > format 4755ms
     name                                      hz     min      max    mean     p75     p99    p995    p999     rme  samples
   · basic                          15,981,519.35  0.0000   0.0498  0.0001  0.0001  0.0001  0.0001  0.0002  ±0.07%  7990761
   · simple parameters               2,017,000.31  0.0003  23.7573  0.0005  0.0005  0.0006  0.0010  0.0014  ±9.32%  1008501
   · quoted and escaped parameters   1,478,169.23  0.0005   4.0170  0.0007  0.0007  0.0009  0.0012  0.0029  ±1.61%   739114

Stop sorting params in format:

 ✓ src/index.bench.ts > parse 6449ms
     name                                      hz     min     max    mean     p75     p99    p995    p999     rme  samples
   · basic                          18,759,838.39  0.0000  1.5379  0.0001  0.0000  0.0001  0.0001  0.0002  ±1.06%  9379920
   · simple parameters               2,994,849.78  0.0002  0.3295  0.0003  0.0003  0.0004  0.0005  0.0009  ±0.19%  1497425
   · quoted and escaped parameters   1,842,136.72  0.0004  2.3385  0.0005  0.0005  0.0007  0.0009  0.0020  ±1.10%   921069
   · OWS-heavy parameters            2,663,291.93  0.0002  0.4533  0.0004  0.0004  0.0005  0.0005  0.0008  ±0.25%  1331646

 ✓ src/index.bench.ts > format 4930ms
     name                                      hz     min      max    mean     p75     p99    p995    p999     rme  samples
   · basic                          16,062,205.72  0.0000   0.0403  0.0001  0.0001  0.0001  0.0001  0.0002  ±0.08%  8031104
   · simple parameters               2,811,505.03  0.0002  14.9218  0.0004  0.0003  0.0004  0.0005  0.0009  ±5.88%  1405753
   · quoted and escaped parameters   1,862,616.45  0.0004   0.2688  0.0005  0.0005  0.0006  0.0007  0.0011  ±0.22%   931309

Notably the type validation during parsing and parameter sorting were the bigger wins. Arguably maybe we should validate, but I do prefer the safe no-throw path of a parser and the strict validation of the formatter. This mirrors other packages like cookie.

@blakeembrey blakeembrey requested a review from a team February 13, 2026 22:51
Copy link
Copy Markdown
Member

@bjohansebas bjohansebas left a comment

Choose a reason for hiding this comment

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

LGMT!

Base automatically changed from be/improved-parser to be/typescript March 31, 2026 22:51
@blakeembrey blakeembrey changed the base branch from be/typescript to master March 31, 2026 22:51
@blakeembrey blakeembrey force-pushed the be/delete-overhead branch 7 times, most recently from a387ffa to cd3428a Compare March 31, 2026 23:54
@blakeembrey blakeembrey merged commit a23924a into master Apr 3, 2026
8 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.

2 participants