Problem/Motivation
Spotted this when profiling a cold cache request on a site with token and metatag module installed.
For date formats and field tokens, token checks TokenModuleProvider::getTokenModule before defining a token (probably to avoid overwriting tokens from core?). On this site at least, that call triggers discovery and takes about 800ms.
If we remove the check from those two places, it doesn't get called at all.
I didn't yet look into the full history of why this check exists in the first place, but if it's safe to remove it would presumably defer that discovery until the token browser is viewed rather than blocking all HTML requests after a cache clear.
Steps to reproduce
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | 3621357 after.png | 679.35 KB | csakiistvan |
| #8 | 3621357 before.png | 406.46 KB | csakiistvan |
Issue fork token-3621357
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
catchComment #3
catchComment #5
berdirYes, token alters in a lot of tokens, to figure out if tokens are defined by itself and not others, it checks that. Otherwise it might also try to act on core tokens such as node:title.
It's already optimized to use a cache collector, this only happens on the first request, afterwards it read from a minimal cache the in the bootstrap bin since the most recent release or so.
Comment #6
csakiistvanComment #7
csakiistvan❌ Does not fix the issue — applied MR !137, ran
ddev drush crand loaded /node/4 as anonymous with metatag enabled: the call still arrives fromTokenTokensHooks.php:651, soTokenModuleProvider::getTokenModule()keeps token info discovery on the critical path of every HTML request after a cache clear.Notes
getTokenInfo()altogether.isNew()andhasLinkTemplate()guards; reordering helps when the entity has no canonical link, but not on a node page where [node:url] is requested.Comment #8
csakiistvanUpload network usage with always cold cache