perf: reduce TDD page latency with draw batching and DOM optimizations#9067
Draft
perf: reduce TDD page latency with draw batching and DOM optimizations#9067
Conversation
Key changes: - Batch multiple draw() calls using requestAnimationFrame (scheduleDraw) to coalesce redundant redraws into a single frame - Remove per-cell onmouseover/onfocus handlers from RegularTable cells, use event delegation via a single table-level mouseover listener instead - Optimize styleListener to reduce DOM queries (single querySelector per section instead of multiple querySelectorAll + Array.from) - Pre-allocate class removal arrays as constants instead of creating new arrays on every renderCell call - Fix hover condition bug (AND -> OR) so highlight updates when either row or column changes, not only when both change simultaneously - Make the setTimeout initial draw hack one-shot instead of firing on every pivot reference change - Hoist bgColors lookup table in getClassForCell to module scope to avoid object allocation per cell Co-authored-by: ericokuma <ericokuma@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Addresses the TDD page latency issue (APP-789) where scrolling and hovering on the Time Dimension Detail table causes significant lag. The root causes were: multiple redundant
draw()calls per animation frame, per-cell DOM event handler allocation on every draw cycle, and unnecessary object/array allocations in hot render paths.Changes
1. Batch draw calls with
requestAnimationFrame(TDDTable.svelte)scheduleDraw()which coalesces multipledraw()requests into a single frame viarequestAnimationFramepivot?.draw()calls (from reactive blocks, hover handlers, mouseleave) withscheduleDraw()handleMouseHoverand another from the reactive block trackinghighlightedColStart/highlightedColEnd2. Remove per-cell event handlers (
RegularTable.svelte)td.onmouseoverandth.onmouseover/th.onfocusassignments fromstyle_tdandstyle_row_thcellInspectorStore.updateValueon every mouse movementinspectCellValue()3. Optimize
styleListenerDOM queries (RegularTable.svelte)querySelectorAll+Array.fromcalls with targetedquerySelector("tbody")/querySelector("thead")lookupsforloops overNodeListinstead of creating intermediate arrays4. Reduce per-cell allocations (
TDDTable.svelte)classesToRemovearrays to module-level constants (CELL_BG_CLASSES_TO_REMOVE,ROW_HEADER_BG_CLASSES_TO_REMOVE) instead of allocating on everyrenderCellcallclassList.toggle()instead of conditional push + batch add5. Fix hover condition bug (
TDDTable.svelte)&&to||inhandleMouseHoverso highlight updates when either row OR column changes, not only when both change simultaneously6. Make setTimeout hack one-shot (
TDDTable.svelte)setTimeout(pivot.draw, 0)workaround was re-triggering on everypivotreference change; now gated withinitialExtraDrawDoneflag7. Optimize
getClassForCell(util.ts)Impact
These changes primarily reduce the number of full table redraws during interaction (hover, scroll) and reduce the per-cell work during each draw cycle. For a typical TDD view with YTD daily data (~365 columns, 12 rows), this eliminates hundreds of redundant closure allocations and multiple redundant draw passes per frame.
Checklist:
Linear Issue: APP-789