-
Notifications
You must be signed in to change notification settings - Fork 23
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 routing is O(m * n) #144
Comments
It's even I know that routing strategy, it's based on a Trie-like data structure. The complexity is inherent from using callbacks to match requests. It might be a good thing to make a compromise though. I'm am refactoring the Also, for relatively small application, the time spent on matching the On the other hand, it's possible to reduce the complexity by building a tree of var users = new Router ();
users.get ("users/me", (req, res) => {});
app.all ("users/<any:path>", users.handle); The first thing I did was to untie the code so that it can support various backend. EDIT: Just saying, thanks for the feedback! |
I have a glib-based Trie if you need that as well. https://github.com/chergert/gnome-builder/blob/master/contrib/search/trie.h Cacheline optimized too. |
Improve the complexity as of #144. Traverse the linked list nodes and use the current node directly (rather than traversing it again) to describe how the routing should continue when 'next' is called.
I doubt I can simply include GPL code, the project is distributed under the LGPL. Otherwise, it can surely be useful to build a prefix index for static piece of rule and regex. I think I could come up with a strategy that would select potentially « matching » Just need to finish things first in #133 and I'll start working on this. |
Feel free to use it under LGPL-2+ |
Improve the complexity as of #144. Traverse the linked list nodes and use the current node directly (rather than traversing it again) to describe how the routing should continue when 'next' is called.
I performed two related improvements:
The idea is that we can eventually use exclusive criteria (like accepted HTTP method) to sort the sequence and find the candidates in logarithmic time. Using flags for HTTP methods remove the need for app.rule (Method.ALL, "", (req, res) => {
// any standard HTTP method
});
app.rule (Method.GET | Method.POST, "", (req, res) => {
// on GET or POST
});
app.rule (Method.ANY, "", (req, res) => {
// any HTTP method (including custom)
}); All the The trie would be specific to |
Also, |
Not really a bug, just wanted to drop a note of some alternate dispatching possibilities. It's usually the first code I look at when perusing frameworks.
You might look at https://github.com/chergert/postal/blob/master/src/cut-n-paste/url-router.c for an example of alternate, faster url dispatching. And some usage examples: https://github.com/chergert/postal/blob/master/src/postal/postal-http.c#L1125
It is, however, tied to libsoup.
Cheers
The text was updated successfully, but these errors were encountered: