From 22250d2d59d1f993a0da01969f8ad1830f5651dc Mon Sep 17 00:00:00 2001 From: Matt Larraz Date: Fri, 20 Feb 2026 16:17:38 -0500 Subject: [PATCH] Optimize simplecov-html for large coverage reports MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ## Problem A real-world coverage report with 1705 source files produces a **41MB HTML file** (~1.9M lines) that causes significant browser slowdown: - 96% of the file is the source files section (~41.3MB) - 51% of that section is whitespace from ERB template formatting (~21MB) - 142,254 `
  • ` elements rendered into the DOM at page load (hidden) - 142K event handlers individually bound to line number elements - An unnecessary `
    ` wrapper around each `
  • ` adds 142K extra DOM nodes ## Changes ### Phase 1: Template Optimizations **ERB whitespace trimming** (`lib/simplecov-html.rb`, all `.erb` views) - Add `trim_mode: '-'` to the ERB constructor - Add `<%-` / `-%>` trim markers to control flow tags in all templates - Eliminates ~21MB of blank lines produced by ERB conditionals/loops **Remove `
    ` wrapper around `
  • `** (`views/source_file.erb`) - These were semantically invalid inside `
      ` and unnecessary - Saves ~2.8MB and 142K DOM nodes **Conditional `data-hits` attribute** (`views/source_file.erb`) - Only emit `data-hits="N"` when `line.coverage` is truthy - Previously emitted `data-hits=""` for ~83K "never" lines with no JS/CSS referencing the empty attribute **Compact `covered_percent.erb`** - Single-line template avoids multi-line whitespace across ~3,400 calls ### Phase 2: Browser Performance **`