I've been trying to track down some performance problems on our site and discovered that the combination of the "me" module and tokens is playing a significant part. It seems the "me" module likes to pass paths through token_replace() to replace any global tokens, which causes all global tokens to be fetched on every page. Because we have some modules that produce somewhat expensive global tokens (like Ubercart), this was significantly increasing query count and load time.
Since we don't have any tokens in paths anyway, it seems wasteful for token_replace() to load up all this data if it's not going to use it, so I've crafted a small patch that will skip all that hard work if the string doesn't contain any tokens anyway. I can't see this being detrimental in any way?
Another optimisation that would be nice would be to token_scan() the string before substitution (like D7 does), and only call out to those modules that supply the tokens that are in the string, rather than fetching all the tokens of that type. Some token_values() calls are quite expensive, and often superfluous.
Patch attached for review.
|PASSED: [[SimpleTest]]: [MySQL] 196 pass(es).|
|#8||1307890-skip-if-no-tokens-in-string.patch||3.6 KB||Dave Reid|
|FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch 1307890-skip-if-no-tokens-in-string_1.patch. This may be a -p0 (old style) patch, which is no longer supported by the testbots.|
|#6||1307890-skip-if-no-tokens-in-string.patch||3.6 KB||Dave Reid|
|FAILED: [[SimpleTest]]: [MySQL] 183 pass(es), 1 fail(s), and 0 exception(es).|
|#5||1307890-skip-if-no-tokens-in-string.patch||3.6 KB||Dave Reid|
|PASSED: [[SimpleTest]]: [MySQL] 184 pass(es).|
|FAILED: [[SimpleTest]]: [MySQL] Unable to apply patch token.module-skipload.patch. See the log in the details link for more information.|