delvedor / find-my-way

A crazy fast HTTP router

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Static routes optimization

ivan-tymoshenko opened this issue · comments

@mcollina Hi, I have an idea for optimizing static paths. But I'm not sure it is worth it. Can you tell me from your experience, or maybe you got some statistics for Fastify:

  1. What part of all routes do static routes take?
  2. What part of all routes do static routes without querystring params take?

It's not an easy question, but maybe you got something. I have only my developer experience, and it can be not representative.

What do you mean by part?

If you want to do bring this to the next level of perf we might want to generate a full function and get rid of the trie.

By part, I mean usage percentage. What percentage of static routes have in relation to all routes? Maybe static paths are a rare case and most people use parametric routes, so some overhead to optimize static paths is inappropriate.

I'm afraid it will not help. We are stuck looping through a path. Comparing char by char is really slow in comparison with comparing the hole string. It would help if we had the fast native String.startsWith method, but we haven't.

By part, I mean usage percentage. What percentage of static routes have in relation to all routes? Maybe static paths are a rare case and most people use parametric routes, so some overhead to optimize static paths is inappropriate.

I would not overfocus on static routes, they are very common when using fastify-static or similar, but serving static files with Node.js is a bad idea.

The static files case is clear. I'm more interested in the general request case. As I understand the most popular path template is something like /entities/:id/property. But maybe I'm wrong and there are a lot of projects that have a lot of static routes.

I agree with you with the exception of first level paths, /, /news, /about, /shop, etc.