jenkins-bot has submitted this change and it was merged.

Change subject: Disable some highlighting for MOUSs
......................................................................


Disable some highlighting for MOUSs

(...modules of unusual size.)

Enabling full syntax highlighting for very long Lua modules can produce DOMs
that have hundreds of thousands of elements and cause browsers to lock up.

I took a count of spans by class (which amounts to a count of tokens by type)
of https://en.wiktionary.org/wiki/Module:languages and came up with:

       sy0:      62545 (symbols)
       br0:      61952 (brackets)
       st0:      39291 (strings)
       kw3:       7746 (keywords)
       kw1:          3
       kw2:          2
       co2:          2
       co1:          2
       nu0:          1
     ------     ------
     Total:     171544

GeSHi allows you to disable highlighting for a particular token type (see
<http://qbnz.com/highlighter/geshi-doc.html#disabling-lexics>) which like a
good way of handling this issue.

Disabling symbols (set_symbols_highlighting(false)) removes both sy0 and br0
elements from the DOM (about 124k elements in the case of Module:languages),
with about 47k elements remaining on the page. This is enough to make Chromium
responsive on my laptop (2.3ghz i5, 8 GB RAM), but it's still noticeably
sluggish. Adding 'set_string_highlighting(false);' removes another 40k elements
from the rendered output, and the resulting DOM is quite zippy at 8k elements.

Proposed solution: disable symbols highlighting when >100 kB; disable strings
highlighting too when >200 kB.

Change-Id: I90c645f9d03bbdc135058a3717a463dec40aa77d
---
M README
M SyntaxHighlight_GeSHi.class.php
2 files changed, 18 insertions(+), 0 deletions(-)

Approvals:
  Ori.livneh: Looks good to me, approved
  Mattflaschen: Looks good to me, but someone else must approve
  Helder.wiki: Looks good to me, but someone else must approve
  jenkins-bot: Verified



diff --git a/README b/README
index fa20c0a..c000431 100644
--- a/README
+++ b/README
@@ -64,3 +64,10 @@
 * line;                Corresponds to enable_line_numbers method on GeSHi
 * start;       Corresponds to start_line_numbers_at method on GeSHi
 * strict;      Corresponds to enable_strict_mode method on GeSHi
+
+== Note ==
+
+GeSHi is generous about creating HTML elements: highlighting large blocks of
+code can easily generate enough of them to crash a browser. As a guard, symbol
+highlighting is turned off for code fragments larger than 100 kB. For fragments
+larger than 200 kB, string highlighting is turned off as well.
diff --git a/SyntaxHighlight_GeSHi.class.php b/SyntaxHighlight_GeSHi.class.php
index 632c85d..3eec854 100644
--- a/SyntaxHighlight_GeSHi.class.php
+++ b/SyntaxHighlight_GeSHi.class.php
@@ -276,6 +276,17 @@
                $geshi->enable_classes();
                $geshi->set_overall_class( "source-$lang" );
                $geshi->enable_keyword_links( false );
+
+               // If the source code is over 100 kB, disable higlighting of 
symbols.
+               // If over 200 kB, disable highlighting of strings too.
+               $bytes = strlen( $text );
+               if ( $bytes > 102400 ) {
+                       $geshi->set_symbols_highlighting( false );
+                       if ( $bytes > 204800 ) {
+                               $geshi->set_strings_highlighting( false );
+                       }
+               }
+
                return $geshi;
        }
 

-- 
To view, visit https://gerrit.wikimedia.org/r/49985
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I90c645f9d03bbdc135058a3717a463dec40aa77d
Gerrit-PatchSet: 4
Gerrit-Project: mediawiki/extensions/SyntaxHighlight_GeSHi
Gerrit-Branch: master
Gerrit-Owner: Ori.livneh <[email protected]>
Gerrit-Reviewer: Helder.wiki <[email protected]>
Gerrit-Reviewer: MZMcBride <[email protected]>
Gerrit-Reviewer: Mattflaschen <[email protected]>
Gerrit-Reviewer: Ori.livneh <[email protected]>
Gerrit-Reviewer: Tim Starling <[email protected]>
Gerrit-Reviewer: jenkins-bot

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to