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

[WIP] Performance Improvement : Set name of system routes #9048

Closed
wants to merge 3 commits into from

Conversation

hissy
Copy link
Contributor

@hissy hissy commented Sep 21, 2020

Currently, 2.4% of execution time, 2.5% of CPU usage is wasted to generate route names, but nobody can see that name.
How about to set route names by default?
Package developers still can add custom routes without its name.

This PR is in progress. If the core team looks it's fine, I'll add the remaining route names.

Screen Shot 2020-09-22 at 2 19 12

@hissy
Copy link
Contributor Author

hissy commented Sep 22, 2020

422 routes exist but Router::addRoute called 845 times. It's also weird and maybe wasting resources

@mlocati
Copy link
Contributor

mlocati commented Sep 23, 2020

@hissy: could you try to add this line:

$route->setCustomName($name);

right before this line:

https://github.com/concrete5/concrete5/blob/f22f8a6b78ee357dd07cf7d4963e6d0185e5e312/concrete/src/Routing/RouteGroupBuilder.php#L190

It seems to me that the route names are calculated twice: with this change it should be done only once.

Could you try to see if this makes some difference (that is, execution time, less useless calls)?

@hissy
Copy link
Contributor Author

hissy commented Sep 23, 2020

@mlocati I'll try it later, but we're generating names nobody can see more than 400 times at every request, even if that change works as expected.

@hissy
Copy link
Contributor Author

hissy commented Sep 23, 2020

@mlocati Number of calls dramatically reduced by adding $route->setCustomName($name);

Screen Shot 2020-09-24 at 2 04 13

@aembler
Copy link
Member

aembler commented Oct 19, 2020

I don't disagree that it'd be nice to improve performance... but this makes the routing in the core look a lot uglier by default.

Would it be better if we could simply cache these routes in some way, and leave the original registering of routes alone?

I think this deserves more discussion.

@mlocati
Copy link
Contributor

mlocati commented Oct 19, 2020

With simply #9048 (comment) we can already reduce the time wasted for calculating route names twice.

@hissy
Copy link
Contributor Author

hissy commented Oct 19, 2020

Reducing 2.4% of execution time should be a big performance improvement, but yeah, this is not the only way to do that.
The current routing system also accessing File Locator many times, so the caching approach is better than this pull request.

@hissy
Copy link
Contributor Author

hissy commented Oct 20, 2020

We might be able to follow what the Symfony's Router class does. It caches UrlMatcher class.

https://github.com/symfony/routing/blob/3.4/Router.php#L265-L310

@aembler
Copy link
Member

aembler commented Oct 23, 2020

Yeah, that sounds like a good way forward.

@stale
Copy link

stale bot commented May 9, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions!

@stale stale bot added the Stale Issues that have been inactive for more than 180 days and will soon be closed label May 9, 2021
@hissy
Copy link
Contributor Author

hissy commented May 9, 2021

I'm working on it

@stale stale bot removed the Stale Issues that have been inactive for more than 180 days and will soon be closed label May 9, 2021
@stale
Copy link

stale bot commented Nov 9, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions!

@stale stale bot added the Stale Issues that have been inactive for more than 180 days and will soon be closed label Nov 9, 2021
@hissy
Copy link
Contributor Author

hissy commented Nov 10, 2021

Sorry, it's in my list

@stale stale bot removed the Stale Issues that have been inactive for more than 180 days and will soon be closed label Nov 10, 2021
@aembler
Copy link
Member

aembler commented Mar 14, 2022

An interesting idea, but let's think about caching the router in some other ways.

@aembler aembler closed this Mar 14, 2022
@hissy
Copy link
Contributor Author

hissy commented Mar 16, 2022

Yeah, I'll try to cache UrlMatcher class like Symfony. Please close this PR

@mlocati
Copy link
Contributor

mlocati commented Mar 16, 2022

I don't think it's worth caching it: please remark that we pre-filter the routes (see #7026 ), so that we actually need to compile just a tiny subset of them (is this done by Symfony too?)

The problem with caching is that routes may be added on the fly (for an example see https://github.com/concrete5/addon_community_translation/blob/1.0.1/controller.php#L277), and correctly handle this case may be a nightmare

@hissy
Copy link
Contributor Author

hissy commented Mar 16, 2022

I have to test it again with the recent develop branch, but it was horrible 2 years ago. We're generating route names nobody can see more than 400 times at every request

@hissy
Copy link
Contributor Author

hissy commented Apr 17, 2022

Tested with recent develop branch. Concrete still generating route names more than 1000 times even though nobody can see it. However, I can't find any good solution to improve this. Give up.

Screen Shot 2022-04-17 at 17 00 17

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants