Create router once
See original GitHub issueHi! Continuing #73 discussion.
Now for each http request on server side we have to create router instance with routes tree and options, attach plugins and middleware. And then run route.start
.
We do it for creating different context for each request. But why should we apply the same routes tree, options and plugins again and again, parsing all that stuff just for creating context?
I think it doesn’t make any sense.
Router should be created once with routes tree and options, plugins and middlewares, whilst route.start
should spawn new context on each request on server side and once on client side (I still don’t see any real cases of router.stop
). Plugins and middlewares should depend on this context. For now I don’t see benefits from https://github.com/router5/router5/issues/73#issuecomment-244713011, anyway I can create middleware on each router creation and bind it in closure by myself.
I mean, mechanism that we have in 4.0 is expensive on server side and not really useful. It can be improved!
Issue Analytics
- State:
- Created 7 years ago
- Comments:13 (7 by maintainers)
Hi everybody and @troch, I just wanna share some data related to this topic and was wondering if cloning is the best current available solution? Registering about 220 routes dynamically on each express route call will take around ~300ms which is a big pain and slows down the app massively! By registering the routes on bootstrap and only cloning the routes on each express route call will reduce the overhead to around ~10ms. Thanks for your feedback!
Hey @davidecantoni, thanks for sharing. That’s great to hear!