There is 1 update.
 
 
XWiki Platform / cid:jira-generated-image-avatar-1bb7b14b-e175-480c-8087-62401b95a325 XWIKI-25413 Open

The code macro syntax highlighting is slow and scales badly when several pages are rendered in parallel

 
View issue   ยท   Add comment
 

1 update

 
cid:jira-generated-image-avatar-41537f23-89cc-4e2e-a955-f6d1835960b2 Changes by Michael Hamann on 19/Oct/26 17:36
 
Description: Pages with many code macros are slow to render, and they get much slower when many of them are rendered at the same time (for example while crawlers visit a wiki): each code macro is highlighted on the server by Pygments running in Jython, and the highlighting has costs that don't depend on the code being highlighted and that limit how well it runs on several threads.

h2. Causes

* {{PygmentsParser}} passes the Python script that drives Pygments as a string to the script engine for each highlight, so Jython parses and compiles it again every time and loads a new Java class for each highlight.
* Pygments lexers keep their token rules in Python lists shared by all threads, and Jython synchronizes each step of the iteration over a list. The lexer iterates over these rules at each position of the code, so the threads highlighting code at the same time block each other.
* The text of each token is parsed with the plain text parser, which allocates a 16 KB read buffer for each call. This one is fixed in the plain text parser, see the linked XRENDERING issue.

h2. Measurements

Highlighting Highlights per second of a 25-line Java snippet on an 8-core laptop, measured with prototypes of {{PygmentsParserScalingTest}}. The control is a pure-Java regular expression tokenizer without shared state, which shows how far the changes: machine itself scales.
* Currently: 240 highlights per second on
||Code macro||Plain text parser||
1 thread , 630 per second ||8 threads||Speedup on 8 threads ||
|master|master|238|734|3
. 09|
* Compiling |with this issue's changes|master|413|981|2.38|
|with this issue's changes|with XRENDERING-822|521|1510|2.90|
|master|with XRENDERING-822|275|865|3.14|
|control| |680 - 834|2070 - 2340|2.7 - 3.0|

With both changes,
the script once: 450 highlights per second highlighting is 2.2 times faster on 1 thread , 960 per second and 2.1 times faster on 8 threads , and it scales like the control .
* Also avoiding
With only the shared lists and changes of this issue, the allocations of the plain text parser buffer: 470 highlights per second become the limit on 1 thread, 1570 per second on 8 several threads.