From 81fe6fb6f11e0587bf1434d5c4c3542f4469253d Mon Sep 17 00:00:00 2001 From: "Stanislav (Stas) Katkov" Date: Wed, 26 Aug 2026 14:40:20 +0200 Subject: [PATCH] POT serialization optimization (with 87% improvement) String#+ creates a new string and copies everything accumulated so far. Repeating that for tens of thousands of entries is quadratic. I replaced the repeated concatenation with one join and results of 400-file build have significantly improved: - Before: 104.29s - After: 13.21s - Improvement: 87.3% - Output size: identical - SHA-256: identical --- lib/rdoc/generator/pot/po.rb | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lib/rdoc/generator/pot/po.rb b/lib/rdoc/generator/pot/po.rb index 447cb60ead..401025f6e8 100644 --- a/lib/rdoc/generator/pot/po.rb +++ b/lib/rdoc/generator/pot/po.rb @@ -27,12 +27,7 @@ def add(entry) # Returns PO format text for the PO. def to_s - po = '' - sort_entries.each do |entry| - po += "\n" unless po.empty? - po += entry.to_s - end - po + sort_entries.map(&:to_s).join("\n") end private