Skip to content

perf: streamline cell content generation - #4724

Open
lukecotter wants to merge 1 commit into
tabulator-tables:masterfrom
lukecotter:perf-cell-render
Open

perf: streamline cell content generation#4724
lukecotter wants to merge 1 commit into
tabulator-tables:masterfrom
lukecotter:perf-cell-render

Conversation

@lukecotter

@lukecotter lukecotter commented Mar 25, 2025

Copy link
Copy Markdown
Contributor

What

Two changes to Cell._generateContents:

  • Write innerHTML once instead of twice — the fallback set innerHTML = value and returned it, then the switch default wrote it again.
  • Clear cell content with a removeChild loop (_clearCellContent()) instead of innerHTML = "".

Behaviour

Unchanged — Format tests pass. The common formatted-string path (default: innerHTML = val) is untouched. No new browser requirements.

Performance (isolated, 250k renders; jsdom, directional)

  • render, no formatter (2× → 1× innerHTML) 2971 → 1492 ms (~2.0×); clear cell (innerHTML=""removeChild) 1257 → 489 ms (~2.6×).

Grid impact

Negligible — with the Format module present the common path is unchanged, so full-grid render is unaffected (headless Chromium, virtual renderer). The win applies to no-Format builds and cell-clear paths. Baseline upstream/master @ 9539446.

@lukecotter lukecotter changed the title perf: improve cell rendering perf: speed up cell rendering Mar 25, 2025
@rathboma

Copy link
Copy Markdown
Collaborator

Hey! Was the previous implementation causing some issues for you?

@lukecotter

lukecotter commented Apr 17, 2025

Copy link
Copy Markdown
Contributor Author

@rathboma
Not a huge issue but when profiling I noticed quite a bit of time spent in parseHtml.

This speeds up rendering quite a bit for me especially when the virtual renderer is not being used.

If you want I can provide some timings.

@lukecotter lukecotter changed the title perf: speed up cell rendering perf: avoid redundant innerHTML write in cell content generation Jul 2, 2026
@lukecotter lukecotter changed the title perf: avoid redundant innerHTML write in cell content generation perf: streamline cell content generation Jul 3, 2026
Two changes to Cell._generateContents:
- The cell-format fallback set element.innerHTML = value AND returned it, then the switch default wrote innerHTML again (double write on the no-Format-module path). Return the value so innerHTML is written once (~2x on that path).
- Clear content via a removeChild loop (_clearCellContent) instead of innerHTML="" (~2.6x; no HTML-parser teardown).

The common path (formatted string -> default: innerHTML = val) is unchanged. Uses only long-standing DOM APIs.
@lukecotter

Copy link
Copy Markdown
Contributor Author

Part of #4917 (overview + combined numbers).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants