Project

General

Profile

Actions

Defect #43446

open

CommonMark rendering became significantly slower after #42737

Added by Katsuya HIDAKA 1 day ago. Updated about 16 hours ago.

Status:
New
Priority:
Normal
Category:
Performance
Target version:
-
Start date:
Due date:
% Done:

0%

Estimated time:
Resolution:
Affected version:

Description

After applying the changes from #42737, CommonMark rendering (issue descriptions, comments, wiki, etc.) has become much slower. Measuring before and after that change shows a slowdown of about 6x.

Since CommonMark rendering is used frequently across Redmine, this regression affects the overall responsiveness of the application.

Benchmark results

Revision Avg per render
r24093 (before #42737) 23.90 ms
r24097 (after #42737) 148.99 ms

Benchmark script

bin/rails r commonmark_bench.rb

commonmark_bench.rb


Files

0001-Fix-performance-issue.patch (4.31 KB) 0001-Fix-performance-issue.patch Takashi Kato, 2025-11-07 16:36
Actions #1

Updated by Marius BĂLTEANU about 24 hours ago

  • Assignee set to Marius BĂLTEANU
Actions #2

Updated by Katsuya HIDAKA about 23 hours ago

It turns out that the rendering becomes even slower when the CommonMark content is larger.

The following results are from running the same benchmark script used for the issue description, but with the CommonMark content tripled in size.

Revision Avg per render (10 times)
r24093 (before #42737) 35.57 ms
r24094 (after #42737) 1043.98 ms

That's about 29.4x slower. From this result, the rendering performance appears to scale worse with larger content than it did before.

Benchmark script (with a slightly modified average calculation):

commonmark_bench_3x_content.rb

Actions #3

Updated by Takashi Kato about 16 hours ago

The performance issue was caused by SyntaxHighlightScrubber checking all nodes using a CSS selector and the `matches?` method.
The benchmark results after applying the patch in my environment are as follows:

r24093: Average: 34.94s ms
r24132: Average: 1492.66s ms
patched: Average: 48.18s ms

While the performance is not completely back to its original speed, a significant performance degradation has been avoided.

Actions

Also available in: Atom PDF