Template talk:Code
(Redirected from Template talk:Code/sandbox)
Latest comment: 3 months ago by Od1n in topic Edit request 6 April 2025 - Performance improvement
This is the talk page for discussing improvements to the Code template. |
|
Archives: 1Auto-archiving period: 6 months ![]() |
![]() | Template:Code is permanently protected from editing because it is a heavily used or highly visible template. Substantial changes should first be proposed and discussed here on this page. If the proposal is uncontroversial or has been discussed and is supported by consensus, editors may use {{edit template-protected}} to notify an administrator or template editor to make the requested edit. Usually, any contributor may edit the template's documentation to add usage notes or categories.
Any contributor may edit the template's sandbox. Functionality of the template can be checked using test cases. |
![]() | Text and/or other creative content from this version of Template:Code was copied or moved into incubator:Template:Wp/nod/code with this edit. The former page's history now serves to provide attribution for that content in the latter page, and it must not be deleted as long as the latter page exists. |
|
This page has archives. Sections older than 180 days may be auto-archived by Lowercase sigmabot III. |
Edit request 6 April 2025 - Performance improvement
editThis edit request has been answered. Set the |answered= parameter to no to reactivate your request. |
Hello, you may be interested by the code used by this template on frwiki: [1].
When the template is used without "lang" parameter, I figured out a way to use "code + nowiki" instead of "syntaxhighlight". The result is visually identical, but we avoid the expensive syntaxhighlight call.
(Refs a previous, failed attempt: Template talk:Code/Archive 1#Template-protected edit request on 4 March 2024.)
Od1n (talk) 18:03, 6 April 2025 (UTC)
- I have pushed (pushed back, actually) the suggested change to the sandbox. Note that, as it happens, there is a difference in behavior with HTML entities. See third table in the previous discussion. Od1n (talk) 01:19, 7 April 2025 (UTC)
- I note that this edit removes the
|id=
parameter on the grounds that it's unused. That may be the case; but it was added on the grounds of harmonisation. I think that it should not be removed. --Redrose64 🌹 (talk) 16:56, 7 April 2025 (UTC)- Some relevant examples from the previous discussion have been copied to the testcases page. I see differences in rendering between the live template and the sandbox in the second "Markup behaviour" table. Are those differences intended? – Jonesey95 (talk) 18:37, 8 April 2025 (UTC)
- No opinion regarding the removal of the
|id=
parameter. I just synchronized with the production template, where it has been removed. I lean toward keeping it removed, but that’s a secondary consideration. - I noticed the discrepancy with HTML entities only after posting the suggested change. On one hand, the change would make the template significantly faster (eliminating the expensive
<syntaxhighlight>
call on all simple uses), but on the other hand, it introduces that discrepancy with HTML entities. Thoughts?
- No opinion regarding the removal of the
- Od1n (talk) 20:58, 10 April 2025 (UTC)
- Some relevant examples from the previous discussion have been copied to the testcases page. I see differences in rendering between the live template and the sandbox in the second "Markup behaviour" table. Are those differences intended? – Jonesey95 (talk) 18:37, 8 April 2025 (UTC)
- I note that this edit removes the
- What's the use case for this? Are there actually a significant number of pages running into the expensive parser function limit because of calls to this template with lang=text? Otherwise WP:PERF applies and it's not worth the extra complexity. * Pppery * it has begun... 20:17, 22 April 2025 (UTC)
- Are there any pages that have
lang=text
? I for one have never seen any in the wild. 𝕁𝕄𝔽 (talk) 20:40, 22 April 2025 (UTC)- "Text" is the default, so any pages that don't specify a language would trigger this, which is probably fairly common. But even given that there are only 6 pages using this template with too many expensive parser function calls so I still don't think it's worth it. * Pppery * it has begun... 23:26, 24 April 2025 (UTC)
- Are there any pages that have
- Not done for now: please establish a consensus for this alteration before using the
{{Edit template-protected}}
template. jlwoodwa (talk) 01:35, 27 April 2025 (UTC)- A great solution for this issue would be upstream, in the extension code: when no syntax highlighting is applied, there is no reason for the tag to be expensive.
- When using
lang="text"
, we should ensure that the tag execution is fast, and does not increment the expensive function count. For instance, I thought of an early return in SyntaxHighlight.php://if ( $lexer === null ) { if ( $lexer === null || $lexer === 'text' ) { // When syntax highlighting is disabled.. $status->value = self::plainCodeWrap( $code, $isInline ); return $status; }
- Od1n (talk) 20:36, 19 May 2025 (UTC)
- One caveat with the above change: it would break the "line numbers" feature on plain text, i.e.
<syntaxhighlight lang="text" line>
. So my proposed change requires further refinement. - By the way, I noticed a related bug that would impact this change too: when using
<syntaxhighlight line>
(erroneously omitting thelang
attribute), the lines placeholder appears but does not contain line numbers. - Od1n (talk) 20:52, 19 May 2025 (UTC)
- One caveat with the above change: it would break the "line numbers" feature on plain text, i.e.