
_theme_process_registry() includes any include file (could be a template or foo.admin.inc) when building the registry. It looks like including the file isn't necessary.
I traced the include back to #168028: both theme functions and templates may need include files, when that patch went in hook_theme() and especially include file/template handling was very different, and as far as I can tell it's no longer needed. Originally the include had a comment 'just to be safe', this was lost in the past three years.
This saves at least 40ms off a registry rebuild, but more importantly 5mb of memory, with just core modules enabled. Sites with lots of modules, lots of includes and lots of templates are going to see considerably bigger savings.
As well as this, all those included files, many of which are never going to be used if they're templates, will pollute opcode caches - potentially causing evictions etc. - so this should help on cold starts a fair bit.
Theme tests pass but didn't run the whole suite.
If I run drush cc all then hit the front page without apc enabled, that requires 45mb of memory with all the caches being rebuilt.
I confirmed that the total memory usage with this patch dropped to 41mb. So if these includes really aren't needed, that may end up helping with issues like #1008362: 32M is sometimes not enough memory to install Drupal 7, module page submit - anywhere else where a single request can end up building all global caches.
If this doesn't break things horribly, it may win the award for most kilobytes of memory saved per line of patch ;)
Comment | File | Size | Author |
---|---|---|---|
#30 | 1177762-30.patch | 1.99 KB | longwave |
#25 | 1177762-25-includes.patch | 1.29 KB | longwave |
#24 | 1177762-24-includes.patch | 1.35 KB | longwave |
#22 | 1177762-file.patch | 826 bytes | catch |
#22 | 1177762-includes.patch | 875 bytes | catch |
Issue fork drupal-1177762
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 #1
catchThis may not be possible due to process functions - at least not if we're relying on function_exists() to see whether they exist or not in include files, see what the bot says though.
Comment #3
catchShame.
Comment #4
catchThis patch won't work, but we could find out if the functions exist another way, such as using the registry regexp.
Comment #5
joelpittetComment #6
joelpittet@catch this may still valid in 8.1.x but not 8.0.x. Maybe you have another way of dealing but I'm reposting the patch for our current 8.0.x
Comment #7
joelpittetBumping
Comment #20
catchThis code still exists, but 'includes' isn't documented in hook_theme() at all: https://api.drupal.org/api/drupal/core%21lib%21Drupal%21Core%21Render%21...
And I'm not convinced we need to support 'file' any more now that actual theme implementations are in templates.
Soo.. maybe we can deprecate both keys for removal in 10.x? Or at least 'includes' if file is still used somehow.
Comment #21
catchSee if any of this is dead code first..
Comment #22
catchComment #23
andypost3k failed tests looks promising!
Comment #24
longwaveI don't think we can get rid of 'file' easily as there are plenty of usages in core modules but there only seems to be one use of 'includes' that we can refactor away.
Comment #25
longwaveComment #26
longwaveTurns out Views uses it as well, but we might be able to remove that too.
Comment #27
catchOK to do 'files' we'll probably need #1804614: [meta] Consolidate similar twig templates and properly use theme suggestions in core and various related issues done first, but good spot on the one remaining usage of 'includes', looks like we just need to move the preprocess out of that file, and possibly a follow-up to refactor the remaining function in it.
Comment #28
catchComment #29
longwave1291 failures, I think this is all because of
Comment #30
longwaveNope, there is a bigger issue: 'file' sets up 'includes' for later cached calls:
We can still deprecate 'includes' from being declared in the first place though.
Comment #36
berdir#3495943: Handle module preprocess functions as OOP hooks should make this pretty straight-forward. Once we converted the remaining preprocess functions in .inc files in core like system and views, we should be able to trigger deprecations if this is set.
Comment #37
nicxvan CreditAttribution: nicxvan commentedThemeCommonElements uses it too, but that should be able to be cleaned up too.
Comment #39
berdirStill postponed, but wanted to have a try, all we have to do now is trigger a deprecation if one of the two keys is set, started a MR based on #3504381: [meta] Convert Template Preprocess hooks to OOP equivalent which removes those in system module and a quickfix for authorize report that I might move to #3518822: Convert template preprocess hooks in core/includes/theme.inc, there shouldn't be too much left after that.
Comment #40
larowlanBlocker has been committed
Comment #41
berdirStill postponed on at 50% of #3504381: [meta] Convert Template Preprocess hooks to OOP equivalent, template_preprocess is actually the main thing here, module preprocess aren't really in those files. I'm aggregating the relevant ones from the meta to check what's left, but keeping at postponed.
Comment #42
andypostComment #43
berdirThis is still postponed and contains 4 or so other issues and a bunch of manual fixes, but with all that, it is now green. We might need to add a BC test though for this. could be combined with a BC test for template_preprocess.