Template talk:Event date
Performance improvement over Template:Dm
Switching {{Calendar/event}} from {{Dm}} to {{Event date}} resulted in a 20% improvement in page load time on Main Page:
− | NewPP limit report
Cached time: | + | NewPP limit report
Cached time: 20190613194003 Cache expiry: 3600 Dynamic content: true CPU time usage: 2.964 seconds Real time usage: 4.133 seconds Preprocessor visited node count: 26937/1000000 Preprocessor generated node count: 48244/1000000 Post‐expand include size: 350150/2097152 bytes Template argument size: 27384/2097152 bytes Highest expansion depth: 18/40 Expensive parser function count: 180/500 Unstrip recursion depth: 0/20 Unstrip post‐expand size: 0/5000000 bytes Lua time usage: 1.000/15.000 seconds Lua virtual size: 17.39 MB/50 MB Lua estimated memory usage: 0 bytes Transclusion expansion time report (%,ms,calls,template) 100.00% 3830.371 1 -total 62.36% 2388.618 1 Template:Languages 62.21% 2382.904 1 Template:Languages/div 59.56% 2281.280 115 Template:LanguageLink 47.56% 1821.851 115 Template:Languagename 27.71% 1061.238 1 Template:Calendar3 27.39% 1049.181 1 Template:Calendar 26.94% 1032.086 69 Template:Calendar/event 22.66% 868.093 626 Template:Langcode 11.90% 455.736 69 Template:Event_date |
– Minh Nguyễn 💬 19:43, 13 June 2019 (UTC)
- Very likely and very plausible. Dm was rewritten to use {{LangSwitch}}, which calls {{Langcode}} with arguments: a massive pessimisation as it gets evaluated every time instead of once per page. We could try the Wikidata version of LangSwitch but that needs language tags for pages to be set up, we can also remove languages not used on this wiki from the language bar. --Andrew (talk) 20:28, 13 June 2019 (UTC)
- This template still has the
{{langcode|{{{lang|}}}}}
pessimisation; as of this morning the page content language has been set for every main page except Gcf:Main Page so you could try{{PAGELANGUAGE}}
instead. --Andrew (talk) 07:06, 14 June 2019 (UTC)
Thanks Andrew, I didn't know about Special:PageLanguage. Here's a comparison on Main Page between the {{Langcode}}-based implementation and inlining Module:Langcode into Main Page:
− | NewPP limit report
Cached time: | + | NewPP limit report
Cached time: 20190614193712 Cache expiry: 3600 Dynamic content: true CPU time usage: 2.843 seconds Real time usage: 3.915 seconds Preprocessor visited node count: 22965/1000000 Preprocessor generated node count: 31004/1000000 Post‐expand include size: 351132/2097152 bytes Template argument size: 27790/2097152 bytes Highest expansion depth: 18/40 Expensive parser function count: 180/500 Unstrip recursion depth: 0/20 Unstrip post‐expand size: 0/5000000 bytes Lua time usage: 0.890/15.000 seconds Lua virtual size: 17.51 MB/50 MB Lua estimated memory usage: 0 bytes Transclusion expansion time report (%,ms,calls,template) 100.00% 3616.172 1 -total 67.74% 2449.619 1 Template:Languages 67.53% 2442.001 1 Template:Languages/div 64.55% 2334.133 115 Template:LanguageLink 51.59% 1865.760 115 Template:Languagename 26.25% 949.331 1 Template:Calendar3 25.98% 939.400 1 Template:Calendar 25.54% 923.565 69 Template:Calendar/event 17.07% 617.293 512 Template:Langcode 10.41% 376.595 77 Template:Event_date |
Here's a comparison between inlining Module:Langcode into Main Page and relying exclusively on {{PAGELANGUAGE}}
:
− | NewPP limit report
Cached time: | + | NewPP limit report
Cached time: 20190614194007 Cache expiry: 3600 Dynamic content: true CPU time usage: 2.834 seconds Real time usage: 3.772 seconds Preprocessor visited node count: 22888/1000000 Preprocessor generated node count: 30546/1000000 Post‐expand include size: 351132/2097152 bytes Template argument size: 27790/2097152 bytes Highest expansion depth: 18/40 Expensive parser function count: 180/500 Unstrip recursion depth: 0/20 Unstrip post‐expand size: 0/5000000 bytes Lua time usage: 0.890/15.000 seconds Lua virtual size: 17.46 MB/50 MB Lua estimated memory usage: 0 bytes Transclusion expansion time report (%,ms,calls,template) 100.00% 3466.156 1 -total 65.88% 2283.455 1 Template:Languages 65.69% 2276.875 1 Template:Languages/div 62.34% 2160.817 115 Template:LanguageLink 49.13% 1702.782 115 Template:Languagename 28.28% 980.228 1 Template:Calendar3 27.89% 966.578 1 Template:Calendar 27.34% 947.709 69 Template:Calendar/event 17.55% 608.297 512 Template:Langcode 11.11% 385.159 77 Template:Event_date |
As you can see, Module:Langcode itself isn't much of a pessimization on its own. The real optimization between {{Dm}} and this template is that this template determines the page language only once per inclusion, compared to about five times per inclusion of {{Dm}}. It would be just as optimal to factor {{Dm}} into a {{Dm/core}} that accepts the evaluated result of {{Langcode}} as a parameter. But this template and the accompanying module are much more readable than {{Dm}}, so the performance improvement is just a nice side benefit.
A 0.4% performance improvement probably isn't worth the trouble of manually setting the page language of every page that includes this template, so I've reverted to the version that inlines Module:Langcode into Module:Dates and uses {{PAGELANGUAGE}}
as a fallback. But {{PAGELANGUAGE}}
is an idea worth revisiting if we set up a bot to automatically set page languages, or if we switch to language subpages, as I proposed towards the bottom of this discussion.
– Minh Nguyễn 💬 19:55, 14 June 2019 (UTC)