| minthreadsleft = 5
}}
== Portals with many images ==
{{ping|Evad37|Northamerica1000}} Portal generation can be slow and sometimes breaches the 10-second limit. [[Portal:Pakistan]] was showing "The time allocated for running scripts has expired."; I purged it at a quiet time but it's still over 9 seconds and may flip back randomly. 66% of that is one call to {{tl|Transclude files as random slideshow}} which generates 145 images. What should we do?
One option is to have the module apply a maximum image count. It might be better to tune individual portals, reducing the list of articles from which images are extracted. At least that way we have some say in which ones are removed. Another idea is to limit the number of images per article (currently hard-coded as 100 in the module, which in practice means "all"). However, doing so naively would drop the later images which might be the best ones. Ideally, the module would select the "best" pictures, but that probably involves doing all the current work (and more) before discarding the mediocre, which improves the portal but doesn't solve the timing problem.
I think that choosing 50 at random is as simple as adding the <code>, 1, 50</code> in <code>local galleryContent = table.concat(sortedLines, '\n', 1, 50)</code>, though pruning the selection earlier might be more efficient and we may want to accept a parameter to override the value of 50 that I plucked from thin air. Any thoughts? [[User:Certes|Certes]] ([[User talk:Certes|talk]]) 12:47, 30 September 2020 (UTC)
*I noticed that {{u|Pakieditor}} significantly expanded the General images section on 20 September 2020 ([https://en.wikipedia.org/w/index.php?title=Portal:Pakistan&diff=979444187&oldid=972187558 diff]), which is very likely contributing to the Lua timeout errors. An immediate fix would be to prune some of the entries from the General images section. From past experience, this tends to stop the timeouts. <span class="smallcaps" style="font-variant:small-caps;">[[User:Northamerica1000|North America]]<sup>[[User talk:Northamerica1000|<span style="font-size: x-small;">1000</span>]]</sup></span> 13:20, 30 September 2020 (UTC)
:{{re|Certes}} That's rather late in the piece to be limiting the number of images. The expensive (time-consuming) work is likely to be in the {{tt|extractRegularFiles}} function, which does a bunch of string manipluation and (potentially) preprocessing of templates in a loop. - <u>'''[[User:Evad37|Evad]]''37'''''</u> <span style="font-size:95%;">[[[d:w:User talk:Evad37|talk]]]</span> 13:29, 30 September 2020 (UTC)
::You're right; it's too late. extractRegularFiles is efficient: gsub takes 0.32 seconds, some of which lies elsewhere. I suspect the time goes even earlier, in the parse function of Module:Excerpt/portals (which is mainly my fault, though the attribution has become separated). The killer there is retrieving up to 100 file description pages to check for non-free licences. We should probably set files=1-50 rather than 100 in this module but also remove some articles from the list in Portal:Pakistan and similar cases. [[User:Certes|Certes]] ([[User talk:Certes|talk]]) 13:59, 30 September 2020 (UTC)
:I've removed subnational articles such as [[Quetta]] from [[Portal:Pakistan]]. It now renders in 6 seconds, of which only 2 s is the slideshow. As an experiment, I've introduced some variety via a region of the day: one final article of {{tlx|Random item|Islamabad|Lahore|Karachi|Quetta|Peshawar|Northern Pakistan}} rotates the evicted images. [[User:Certes|Certes]] ([[User talk:Certes|talk]]) 14:41, 30 September 2020 (UTC)
:{{ping|GKFX}} I see the maximum number of images is down to 4. This seems rather low compared to the 50/100 discussed above. Is a new problem occurring with higher numbers? [[User:Certes|Certes]] ([[User talk:Certes|talk]]) 00:15, 9 May 2021 (UTC)
::{{ping|Certes}} [[Portal:Arithmetic]] passes article names not filenames and was struggling at 5 articles. I will revert and make changes to the portal instead. [[User:GKFX]]<sup>[[User talk:GKFX|talk]]</sup> 08:39, 9 May 2021 (UTC)
:::{{ping|GKFX}} That portal is taking 9.7 seconds (close to the maximum of 10). 37% is in {{tl|Transclude files as random slideshow}}. Although there are only five arguments, each of them has several files (images). However, there are only 14 altogether and I can't see why this is slow. Maybe {{u|Evad37}} can advise us. Another 29% is in {{tl|Transclude list item excerpts as random slideshow}}. That runs on [[Portal:Arithmetic/Selected article]], which lists about 60 articles. I tried adding {{para|limit|30}} to that call, but it didn't seem to help. It runs again on [[Portal:Arithmetic/Biographies]] but that list is short. [[User:Certes|Certes]] ([[User talk:Certes|talk]]) 11:05, 9 May 2021 (UTC)
== Mobile view improvement ==
|