Skip to content

Refactor parser to be lenient on values#58

Open
blakeembrey wants to merge 1 commit intobe/typescriptfrom
be/improved-parser
Open

Refactor parser to be lenient on values#58
blakeembrey wants to merge 1 commit intobe/typescriptfrom
be/improved-parser

Conversation

@blakeembrey
Copy link
Member

Building on #57 for benchmarking. Rewrites the parser to be incremental without regex validation, and more lenient for upstream dependents who need things like foo=bar=baz to be parsed correctly.

@blakeembrey
Copy link
Member Author

blakeembrey commented Feb 12, 2026

Perf tests before:

 ✓ src/index.bench.ts > parse 4917ms
     name                                      hz     min     max    mean     p75     p99    p995    p999     rme  samples
   · basic                          10,545,863.30  0.0000  2.0555  0.0001  0.0001  0.0001  0.0002  0.0007  ±0.91%  5272932
   · simple parameters               2,414,131.39  0.0003  0.3282  0.0004  0.0004  0.0005  0.0005  0.0010  ±0.37%  1207066
   · quoted and escaped parameters   1,700,063.21  0.0005  0.3490  0.0006  0.0006  0.0007  0.0008  0.0012  ±0.33%   850032
   · OWS-heavy parameters            2,370,873.91  0.0003  0.4244  0.0004  0.0004  0.0005  0.0006  0.0010  ±0.45%  1185437

 ✓ src/index.bench.ts > format 4824ms
     name                                      hz     min     max    mean     p75     p99    p995    p999     rme  samples
   · basic                          15,954,499.11  0.0000  0.0858  0.0001  0.0001  0.0001  0.0001  0.0002  ±0.07%  7977250
   · simple parameters               2,152,850.11  0.0004  0.3426  0.0005  0.0005  0.0006  0.0009  0.0011  ±0.44%  1076426
   · quoted and escaped parameters   1,545,029.32  0.0005  0.3580  0.0006  0.0007  0.0008  0.0010  0.0013  ±0.33%   772515

After:

 ✓ src/index.bench.ts > parse 5031ms
     name                                      hz     min     max    mean     p75     p99    p995    p999     rme  samples
   · basic                          10,488,660.07  0.0000  1.8354  0.0001  0.0001  0.0001  0.0002  0.0007  ±1.16%  5244331
   · simple parameters               2,896,440.78  0.0002  0.4201  0.0003  0.0003  0.0005  0.0005  0.0009  ±0.22%  1448221
   · quoted and escaped parameters   1,650,035.57  0.0005  0.3441  0.0006  0.0006  0.0007  0.0009  0.0021  ±0.33%   825018
   · OWS-heavy parameters            2,673,445.24  0.0003  0.3925  0.0004  0.0004  0.0004  0.0005  0.0008  ±0.22%  1336723

 ✓ src/index.bench.ts > format 4775ms
     name                                      hz     min     max    mean     p75     p99    p995    p999     rme  samples
   · basic                          16,172,897.54  0.0000  0.0415  0.0001  0.0001  0.0001  0.0001  0.0002  ±0.10%  8086450
   · simple parameters               2,102,840.62  0.0004  0.3839  0.0005  0.0005  0.0006  0.0010  0.0012  ±0.50%  1051421
   · quoted and escaped parameters   1,518,375.90  0.0005  0.3014  0.0007  0.0007  0.0008  0.0010  0.0013  ±0.33%   759188

Arguably not much performance change but the changes aren't easy to do in a regex only.

@blakeembrey
Copy link
Member Author

Realized there is an optimization available for getting rid of .trim(), new benchmark:

 ✓ src/index.bench.ts > parse 5026ms
     name                                      hz     min     max    mean     p75     p99    p995    p999     rme  samples
   · basic                          11,091,574.29  0.0000  3.7066  0.0001  0.0001  0.0001  0.0001  0.0005  ±1.51%  5545788
   · simple parameters               2,688,793.52  0.0003  0.3477  0.0004  0.0004  0.0005  0.0005  0.0008  ±0.20%  1344397
   · quoted and escaped parameters   1,758,222.89  0.0005  0.3292  0.0006  0.0006  0.0007  0.0007  0.0012  ±0.25%   879112
   · OWS-heavy parameters            2,349,556.00  0.0003  3.2109  0.0004  0.0004  0.0005  0.0005  0.0009  ±1.87%  1174778

 ✓ src/index.bench.ts > format 4797ms
     name                                      hz     min     max    mean     p75     p99    p995    p999     rme  samples
   · basic                          15,884,536.95  0.0000  0.0384  0.0001  0.0001  0.0001  0.0001  0.0002  ±0.08%  7942269
   · simple parameters               2,111,259.33  0.0004  0.3335  0.0005  0.0005  0.0006  0.0009  0.0011  ±0.43%  1055630
   · quoted and escaped parameters   1,517,261.44  0.0005  0.3292  0.0007  0.0007  0.0008  0.0010  0.0013  ±0.42%   758631

@bjohansebas
Copy link
Member

bjohansebas commented Feb 12, 2026

Just one question before I continue reviewing, will this be a new major version? I assume so, or not? Just asking so I can better align with what you’re planning to do.

@blakeembrey
Copy link
Member Author

Yes, sorry. I mentioned a major in the typescript PR so this plus follow ups beyond this to further optimize by removing old code paths will be a major. I tried to change minimal things in this PR on the API side to get a fair comparison on benchmarks.

@blakeembrey blakeembrey deleted the be/improved-parser branch February 12, 2026 23:09
@codecov
Copy link

codecov bot commented Feb 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (edaa362) to head (cc480a1).

Additional details and impacted files
@@               Coverage Diff               @@
##           be/typescript       #58   +/-   ##
===============================================
  Coverage         100.00%   100.00%           
===============================================
  Files                  1         1           
  Lines                 97       137   +40     
  Branches              40        55   +15     
===============================================
+ Hits                  97       137   +40     

☔ 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 blakeembrey restored the be/improved-parser branch February 12, 2026 23:09
@blakeembrey blakeembrey reopened this Feb 12, 2026
@blakeembrey
Copy link
Member Author

blakeembrey commented Feb 12, 2026

Accidentally deleted rebasing my 3rd branch from main due to the TypeScript PR changes. 😓

@blakeembrey blakeembrey requested a review from a team February 13, 2026 22:50
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