Problem/Motivation
Originally, this issue was about deprecating file and include keys in hook_theme. That turned out to be hard. But for a long time, the last thing they were used for were putting template preprocess functions in conditionally loaded include files.
Since template_preprocess files are now fully converted and deprecated, we can formally deprecate them and file/include keys together.
Steps to reproduce
Proposed resolution
This includes:
* 3 deprecations for those 3 things: file, includes and automatic discovery of template_preprocess functions
* A special case to not trigger the deprecation for fully converted theme hook definitions, so that we do not need to convert those two
* That doesn't apply to the file deprecation, so they are moved into an always loaded file
* A deprecation test, I picked a test module that already exists, but turns out it's quite a mess because the defined functions are bogus (invalid arguments, return values, function names, ..) so I ended up adding new ones anyway.
* Convert missed leftovers.
Remaining tasks
Confirm decision to not deprecate these keys when the function is already deprecated
User interface changes
N/A
Introduced terminology
N/A
API changes
N/A
Data model changes
N/A
Release notes snippet
Original issue summary
_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 |
|---|
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:
- 1177762-remove-includes-support
changes, plain diff MR !11808

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 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.
Comment #44
berdirThis postponed on one last issue: #3346394: Replace BlockContentController::add with EntityController::addPage via the AdminHtmlRouteProvider route provider.
The deprecation for template_preprocess is in place and is correctly picking up some bits we missed. There's one in field_ui that looks converted because it's already a one-liner calling the service, but it's a redirection to another preprocess, this can now actually directly use that.
And one in views was missed too, that seems completely untested as the old function had been deprecated.
Comment #45
berdirThis months theme is finishing 2011 issues.
This can finally be reviewed.
Updated the issue summary
Comment #46
berdirComment #47
berdirComment #48
berdirComment #49
nicxvan commentedI think this is almost ready, just one question on testing the last deprecation path.
Comment #50
berdirI can add includes, would require another hook definition and include file. The only argument to not do it is the fact that we didn't have any actual test coverage in core for it. It wasn't used at all, tests or otherwise. Directly at least, having a file key is just a shorthand for having an include.
Comment #51
nicxvan commentedFair enough, I'll review again without it.
Comment #52
nicxvan commentedI think this is almost ready then, one last question.
I see you are only deprecating if it's not already deprecated. At first I thought this was a nice little optimization, but can we end up in a bit of a bind.
E.g. we are removing this support in 12 someone could deprecate their template preprocess and try adding support for 12 and this would not notify them.
Without that check it's a double deprecation, but that might be preferable unless I'm missing something.
Other than that.
Took another look, all deprecations line up.
We usually don't test deprecation pathways but this is unique enough it is warranted.
Everything else is just a couple that were still in the include file or were using the deprecated fallback.
50 convinced me we don't need a test for the third pathway.
Comment #53
nicxvan commentedWhoops, didn't mean too rtbc before that question was addressed.
Comment #54
berdirThe intention of the deprecated check isn't to avoid double deprecation, I don't really care about that and they have a different target audience (one is for the code defining the theme hook and one is for those using it).
The reason is just to avoid having to convert those already deprecated template preprocess functions into OOP, so we end up having a deprecated functional BC function calling into an also deprecated OOP method.
It's IMHO unlikely to effect anything else or cause problems with different versions, even if we deprecate more template preprocess functions, they're already converted now in core.
> The only argument to not do it is the fact that we didn't have any actual test coverage in core for it. It wasn't used at all, tests or otherwise
This is wrong, it was used in the maintenance page template, I'm not sure if we have deprecation test coverage for that though. I'm open to adding a deprecation test example for that
> We usually don't test deprecation pathways but this is unique enough it is warranted.
I would actually invert it. We test deprecated pathways *unless* they are trivial. It just so happens that many of them are in fact trivial.
The test coverage is primarily about making sure that the code, while deprecated, still works, because it's still heavily used in contrib (template_preprocess functions). A kernel test can only partially guarantee that because the includes are not only for discovery but also rendering the templates, which we could only test with a functional test and doing that on a different request.
Either way, if you or a committer thinks it would be valuable to extend the coverage then I'm happy to do so.
Comment #55
nicxvan commentedHad a brief chat in slack:
We're going to add test coverage for include, but leave the deprecation exclusion for already deprecated functions.
Comment #56
berdirDone.
Comment #57
nicxvan commentedI took a pass at updating the CR and IS
Comment #58
nicxvan commentedCr could use another review but I think this is ready now.
Comment #60
catchThis looks great. Agreed with the double deprecation check it will save a lot of churn in things that are going to be removed anyway.
Committed/pushed to 11.x, thanks!