Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Problem/Motivation
When you have lots of jsonapi routes the \Drupal\views\Plugin\views\display\PathPluginBase::alterRoutes() method does lots and lots of unnecessary work.
Steps to reproduce
Install JsonAPI and views and rebuild the routes.
Using the standard profile this change results in 2220 less calls to \Drupal\views\Plugin\views\display\PathPluginBase::overrideAppliesPathAndMethod(). On a client site which makes heavy use of JsonAPI and has a *lot* of custom entity types and bundles of said entity types this results in 290556 less calls!
Blackfire runs:
- Standard + JSON API: https://blackfire.io/profiles/compare/ecc94800-5825-489b-ab6d-fce95a2c6c...
- My client site: https://blackfire.io/profiles/compare/2e0bd21a-5fae-430f-b072-03321d2592...
Proposed resolution
Change the order of the if condition.
Remaining tasks
User interface changes
None
API changes
None
Data model changes
None
Release notes snippet
N/a
Comment | File | Size | Author |
---|---|---|---|
#2 | 3248649-2.patch | 917 bytes | alexpott |
Comments
Comment #2
alexpottComment #3
vijaycs85Wow, that's a massive gain (esp. on the client site) for a change of order of conditions checked.
Comment #4
vijaycs85Comment #5
bbralaAgree, was also reviewing lol. Rtbc agreed.
Comment #7
larowlanCommitted 1e05f80 and pushed to 9.4.x. Thanks!
Holding off backport until I ascertain whether we're in beta freeze.
Comment #9
larowlanFreeze hasn't started yet
Backported to 9.3.x
Comment #11
donquixote CreditAttribution: donquixote as a volunteer commentedWith this optimization we still have O(n*m) cost.
n = number of routes
m = number of views displays with path plugins, or other route subscribers that need to scan all routes.
So there is still a problem on some sites.
Follow-up: #3372094: Optimize route subscribers using indexed route collection