Replies: 1 comment
-
It happens that this is a very interesting discussion, it dates back to the origins of Nikita Popov's FastRoute. Inspired on FastRoute, Symphony brought changes to its router: Posts by Nikolas Grekas: Making Symfony’s Router 77.7x faster - 1/2 and by Frank de Jonge: New in Symfony 3.3: Faster routing. Basically both solutions advocate to take advantage of the static part of the routes first: make a first sift on static routes and then jump into regex to find the matching route. When working with
I implemented the second solution on a project with 16 microcollections and the performance gain was quite noticiable (some cases up to 500%, i.e. with a MicroCollection with only two routes) On a side note, Popov is quite critical about Phalcon. But even in the cases where he is right, no solution can match having the algorithm implemented in the extension and quickly called with an |
Beta Was this translation helpful? Give feedback.
-
According to the documentation on MicroCollections, to increase performance
we can use lazy loading, so that the controller will be loaded only if the relevant route is matched
.By accident I just defined a MicroCollection for controller A without endpoints, ie:
Then I made a request to controller B (a simple ping request), properly defined, but I received the following error:
To fix it, I added a route to MicroCollection A:
And it works. But is this the expected behaviour when using lazy loading? It seems that Phalcon is loading all the endpoints in order to process the request, while according to the documentation it could stop at the prefix definition (load the controller only if the prefix route is matched, not all the end points). Is lazy loading working as expected?
This gives me the idea to create a first router like:
Or more generic:
This woul;d be a kind of nano applications (or micro modules), only loading the handlers/classes/services that it needs. Could this be a workaround to have lighter endpoints?
Beta Was this translation helpful? Give feedback.
All reactions