Skip to content
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

URL Parsing Performance #1115

Closed
dajinchu opened this issue Sep 10, 2023 · 2 comments
Closed

URL Parsing Performance #1115

dajinchu opened this issue Sep 10, 2023 · 2 comments
Labels
enhancement 🚀 New feature or request

Comments

@dajinchu
Copy link
Contributor

dajinchu commented Sep 10, 2023

Description

Ran a benchmark using the npm create vite-plugin-ssr starter repo on the index page. Used bombardier and node --inspect to generate flamegraph.

Looks like URL parsing is taking up a disproportionate amount of time (~50%) and might be good low hanging fruit for a perf boost.
image

Noticed parseWithNewUrl is:

  1. called ~40 times per request
  2. Spending a lot of time in node error handling (see flamegraph)

As a proof of concept I commented out the try section and just let the catch run 100% of the time, and assume there is no origin to return - I'm sure a real solution has more nuance, but this gave ~80% increased req/s and shaves ~40ms off avg latency:

before
Statistics        Avg      Stdev        Max
  Reqs/sec      1484.61     124.81    1829.91
  Latency       83.93ms     7.69ms   183.48ms

after
Statistics        Avg      Stdev        Max
  Reqs/sec      2591.98     309.50    3136.87
  Latency       48.13ms     5.61ms   126.46ms

flamegraph after:
image

Not sure what the intent is behind the origin handling, so not sure what the real fix is, but curious what can be done.

Thanks!

@dajinchu dajinchu added the enhancement 🚀 New feature or request label Sep 10, 2023
@brillout
Copy link
Member

It's quite suprising that new URL() is that slow. I'm thinking Deno and Bun may have a much faster implementation.

The new URL() usage is only about extracting the origin from the URL (needed for many use cases).

I think getting rid of new URL() and using a custom origin extraction would be not only faster but also more compact (less KBs sent to the browser).

(The couple of days ETA still holds for cumulative: the progress on it has been delayed by a couple of urgent tickets.)

@brillout
Copy link
Member

Actually, new URL() is also needed for resolving the pathname which isn't trivial (there are quite a lot of edge cases around escaping for example).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 🚀 New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants