Skip to content

feat: experimental compiler (3x faster matcher!) #155

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 18 commits into from
Jun 15, 2025
Merged

feat: experimental compiler (3x faster matcher!) #155

merged 18 commits into from
Jun 15, 2025

Conversation

aquapi
Copy link
Contributor

@aquapi aquapi commented Jun 13, 2025

Resolves #154
I got the compiler working for static paths and required parameters.
Currently I'm not sure how to handle regexp name and optional parameters.

@aquapi aquapi requested a review from pi0 June 13, 2025 17:21
Copy link

codecov bot commented Jun 13, 2025

Codecov Report

Attention: Patch coverage is 95.04950% with 5 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/compiler.ts 95.04% 5 Missing ⚠️

📢 Thoughts on this report? Let us know!

@aquapi
Copy link
Contributor Author

aquapi commented Jun 13, 2025

I need to setup tests too will do that later

@pi0 pi0 changed the title Rou3 experimental pattern matching compiler feat: experimental compiler Jun 14, 2025
@aquapi aquapi marked this pull request as ready for review June 15, 2025 06:43
Copy link
Member

@pi0 pi0 left a comment

Choose a reason for hiding this comment

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

Beautiful work 🚀

@pi0 pi0 merged commit 22f8be1 into h3js:main Jun 15, 2025
2 of 3 checks passed
@pi0
Copy link
Member

pi0 commented Jun 15, 2025

Current benchmarks: (i think should be safe to say it gets ~3x faster!)

Bun:

clk: ~4.25 GHz
cpu: Apple M4 Pro
runtime: bun 1.2.15 (arm64-darwin)

benchmark                   avg (min … max) p75 / p99    (min … top 1%)
------------------------------------------- -------------------------------
• dynamic routes
------------------------------------------- -------------------------------
findRoute                    218.99 ns/iter 222.30 ns 273.49 ns ▁▁▁▄█▆▁▁▁▁▁
compileRouter                 58.68 ns/iter  59.83 ns  91.79 ns ▆█▄▁▁▁▁▁▁▁▁

summary
  compileRouter
   3.73x faster than findRoute

• all routes
------------------------------------------- -------------------------------
findRoute                    188.87 ns/iter 190.21 ns 240.15 ns ▃▆█▃▁▁▁▁▁▁▁
compileRouter                 74.67 ns/iter  75.96 ns 107.79 ns ▃█▆▂▁▁▁▁▁▁▁

summary
  compileRouter
   2.53x faster than findRoute

Deno:

runtime: deno 2.3.5 (aarch64-apple-darwin)

benchmark                   avg (min … max) p75 / p99    (min … top 1%)
------------------------------------------- -------------------------------
• dynamic routes
------------------------------------------- -------------------------------
findRoute                    324.24 ns/iter 328.48 ns 345.46 ns ▁▁▁▂▂▃▇█▃▁▁
compileRouter                 97.39 ns/iter  97.75 ns 114.74 ns ▁▁▁█▄▂▂▁▁▁▁

summary
  compileRouter
   3.33x faster than findRoute

• all routes
------------------------------------------- -------------------------------
findRoute                    343.79 ns/iter 347.12 ns 424.69 ns ▁▂█▇▂▁▁▁▁▁▁
compileRouter                117.19 ns/iter 117.16 ns 137.99 ns ▁▁▁█▃▂▁▁▁▁▁

summary
  compileRouter
   2.93x faster than findRoute

Node:

runtime: node 22.13.0 (arm64-darwin)

benchmark                   avg (min … max) p75 / p99    (min … top 1%)
------------------------------------------- -------------------------------
• dynamic routes
------------------------------------------- -------------------------------
findRoute                    328.07 ns/iter 334.27 ns 351.88 ns ▁▂█▄▂▄▃▂▁▁▁
compileRouter                 95.61 ns/iter  95.22 ns 112.38 ns ▁▁▁█▄▁▁▁▂▁▁

summary
  compileRouter
   3.43x faster than findRoute

• all routes
------------------------------------------- -------------------------------
findRoute                    354.31 ns/iter 360.59 ns 377.75 ns ▁▁▁▁▇█▂▄▂▁▁
compileRouter                115.01 ns/iter 113.81 ns 132.56 ns ▁▁▁█▇▁▁▁▂▁▁

summary
  compileRouter
   3.08x faster than findRoute

@pi0 pi0 changed the title feat: experimental compiler feat: experimental compiler (3x faster matcher!) Jun 15, 2025
@pi0 pi0 mentioned this pull request Jun 15, 2025
11 tasks
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.

Rou3 pattern compiler
2 participants