We had to add a caching layer to token_info() from Token module in Drupal 7 as it's a relatively expensive hook and can be called quite often when generating a UI for tokens. We should move this caching layer into core's token_info() itself.
| Comment | File | Size | Author |
|---|---|---|---|
| #35 | drupal_1211864_35.patch | 7 KB | xano |
| #35 | interdiff.txt | 1.62 KB | xano |
Comments
Comment #1
fagoThe problem is token caching in contrib doesn't fly without a way to discover when the cache should be cleared. And if all modules implementing tokens would have to do it for token.module, token.module would become a requirement - thus a kind of extension of drupal core ;)
See #1211608: Caching requires modules to implement token.module API.
So let's better do it directly in core.
Comment #2
dave reidComment #3
dave reid#2: 1211864-token-info-cache.patch queued for re-testing.
Comment #4
xano#2: 1211864-token-info-cache.patch queued for re-testing.
Comment #6
xanoLet's get #1969540: Convert token.inc to a service in first, so we can inject the cache service into it.
Comment #7
dave reidSounds great! This will be a great way to integrate caching.
Comment #8
Taz commentedRe-rolling patch for current dev branch on 7.x
When a site is using the entity.module, with an above average number of content types or fields, entity_token_tokens() and various token alters are expensive. entity.module itself was sucking up 50ms of processing time, as per a sample of cachegrinds.
While i've submitted a patch to entity.module for one part of their code, the fact token_info() isn't cached still remains.
This is a highly important speed increase for any drupal site with the entity module, or modules exposing a stack of tokens, which in reality is a now a lot of D7 sites.
I'd like to see this in 7.x before it's final days, as it seems the 8.x token solution is vastly different and wouldn't ever be "backported" to core.
Comment #9
xanoAs per the guidelines, this will have to be fixed in the most recent major version first.
Comment #10
xanoI'm sprinting here at Drupalcon anyway. Will post a patch.
Comment #11
xanoComment #12
xano2: 1211864-token-info-cache.patch queued for re-testing.
Comment #14
xanoRe-roll with a PHPUnit test.
Comment #15
xano14: drupal_1211864_14.patch queued for re-testing.
Comment #16
berdirEvery unique cache tag adds performance overhead when loading caches.
In DefaultPluginManager, I have been able to optimize this by instead of using a tag, loop over the languages and do a deleteMultiple, see DefaultPluginManager::clearCachedDefinitions()
The cache should be got sounds a bit strange, maybe it's easier to write this in a more direct way, something like it will try to fetch from the cache?
Comment #18
xanoI rewrote some of the code comments, and added PHPUnit annotations. I also replaced the cache tags with a dedicated cache bin for tokens, so we can just flush the entire bin instead.
Comment #19
xano18: drupal_1211864_18.patch queued for re-testing.
Comment #21
xano18: drupal_1211864_18.patch queued for re-testing.
Comment #22
longwaveComment #23
xano18: drupal_1211864_18.patch queued for re-testing.
Comment #24
xano18: drupal_1211864_18.patch queued for re-testing.
Comment #26
xano18: drupal_1211864_18.patch queued for re-testing.
Comment #28
xanoComment #29
penyaskito#28 looks awesome. The only thing I'm missing is test coverage for checking any concrete token, but I guess this is already tested with WebTests and moving that to PHPUnit tests is a completely different thing. So RTBCing this.
Comment #30
xanoBerdir told me having a separate cache bin is a no-go these days, so here is a patch that makes token info share the cosy
cache.cachebin.Comment #31
berdirThe format for the cache tag should be array(tag_name => TRUE), or array(tag_name => array(1, 2, 3)) when you have ID's.
Comment #32
xano30: drupal_1211864_30.patch queued for re-testing.
Comment #34
berdirI guess we can use the new cache.discovery bin for this?
Comment #35
xanoComment #36
berdirThanks, now I'm happy :)
Comment #37
webchickThis feels like more of a task than a feature request.
Looks fine to me, but assigning to catch since it's performance-y.
Speaking of which: Benchmarks?
Comment #38
berdirNot sure if we can do useful benchmarking as this will only become a bigger problem in contrib, when tokens will grow a lot due to field tokens and so on.
Comment #39
webchickGotcha. Ok, thanks!
Comment #41
catchYeah this is a bit borderline since it only becomes a problem with contrib modules. However we have plenty of data that contrib implementations are expensive, so I think it's OK to add the cache here. Committed/pushed to 8.x, thanks!