Skip to content

feat(toolbar): add interactive TTFB and LCP waterfall chart to profiler - #316

Merged
dermatz merged 3 commits into
mainfrom
feature/profiler-waterfall-chart
Dec 1, 2026
Merged

dermatz merged 3 commits into
mainfrom
feature/profiler-waterfall-chart

Conversation

@dermatz

@dermatz dermatz commented Dec 1, 2026

Copy link
Copy Markdown
Member

Summary

Replaces the flat stacked bars in the Toolbar Profiler's TTFB Waterfall & LCP 4-Phase Breakdown section with an interactive, staggered multi-row timeline waterfall chart and phase drill-down inspector.

What Changed

  • Extended W3C Navigation & Resource Telemetry (src/view/frontend/web/js/toolbar/profiler-collector.js)
    • Captures exact phase start/end timestamps (redirectStartMs, dnsStartMs, connectStartMs, requestStartMs, responseStartMs, responseEndMs), splits TCP handshake from TLS negotiation (secureConnectionStart), enriches render-blocking resource entries with DOM location/attributes (<head>/<body>, media, missing defer/async), and adds LCP resource transfer/decoded metadata.
    • Hardens isMageForgeNode() class matching so clicks inside detached/re-rendered toolbar subviews never leak into storefront INP metrics.
  • Staggered Multi-Row Timeline Waterfall (src/view/frontend/web/js/toolbar/ui/profiler-waterfall.js, profiler-sections.js)
    • Plots Redirect, DNS + TLS, Backend / FPC Wait, HTML Download, Render-Blocking Assets, and LCP Render on a shared millisecond ruler with vertical gridlines, dashed TTFB / FCP / LCP milestone markers, and TTFB / LCP dimension brackets.
    • Adds ‹ | 1× | › horizontal zoom (1×, 2×, 4× with sticky phase labels) and All | TTFB | LCP scope switching (including Server-Timing sub-rows in TTFB mode and individual 4-phase rows in LCP mode).
  • Click-to-Inspect Phase Detail Drawer (src/view/frontend/web/js/toolbar/ui/profiler-waterfall-details.js)
    • Clicking any waterfall row, LCP sub-segment, or legend item opens a contextual diagnostic drawer (e.g. full render-blocking CSS/JS list with DOM hints and 1-click URL copy, backend cache profile & Server-Timing breakdown, Brotli/Gzip HTML compression ratio, and 4-part LCP breakdown with pre-LCP Long Task culprits and 1-click Inspect Element handoff).
  • Theme & Responsive Styling (src/view/frontend/web/css/toolbar/_variables.css, _themes.css, _groups.css, _responsive.css)
    • Uses semantic --mageforge-* design tokens across Dark, Light, and Auto themes with zero raw rgba() rules outside _variables.css/_themes.css.

Verification

  • ddev phpcs (217/217 files clean)
  • ddev phpstan (0 errors)
  • ddev mago lint, ddev mago fmt --check, ddev mago analyze (0 issues)
  • trunk check (Prettier & git-diff-check clean)
  • Verified live in browser on https://mageforge.ddev.site/ across All / TTFB / LCP scopes, 1×/2×/4× zoom, phase detail drawers, and Dark/Light themes.

Replace the flat single-bar TTFB and LCP breakdown in the Toolbar Profiler with a staggered multi-row timeline waterfall featuring vertical gridlines, TTFB/FCP/LCP milestone markers, horizontal zoom (1x/2x/4x), All/TTFB/LCP scope switching, and a click-to-inspect phase detail drawer for render-blocking CSS/JS, Server-Timing, and LCP element diagnostics.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings December 1, 2026 18:51

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The profiler can exclude genuine storefront activity, plot misleading timing phases, and label slow LCP as healthy, undermining the accuracy of its performance diagnostics.

5 open issues
What changed in this PR

Replaces the MageForge Toolbar Profiler’s stacked TTFB/LCP bars with an interactive waterfall for investigating storefront loading performance.

Changes:

  • Extends navigation and resource telemetry with phase timestamps, separate TCP/TLS durations, and resource metadata.
  • Adds scoped timelines, horizontal zoom, milestone markers, and diagnostic drawers.
  • Adds theme-aware styling and responsive layouts for the new chart.
File Description
src/​view/​frontend/​web/​js/​toolbar/​ui/​profiler-waterfall.js Builds timeline rows, zoom controls, scope switching, and phase selection.
src/​view/​frontend/​web/​js/​toolbar/​ui/​profiler-waterfall-details.js Adds diagnostic drawers, resource details, and element inspection.
src/​view/​frontend/​web/​js/​toolbar/​ui/​profiler-sections.js Integrates the unified waterfall into the profiler.
src/​view/​frontend/​web/​js/​toolbar/​profiler-collector.js Enriches timing data and adjusts UI-node filtering.
src/​view/​frontend/​web/​css/​toolbar/​_variables.css Defines waterfall colours, gradients, and surface tokens.
src/​view/​frontend/​web/​css/​toolbar/​_themes.css Adds light and automatic-theme overrides.
src/​view/​frontend/​web/​css/​toolbar/​_responsive.css Adjusts phase labels and legend columns for smaller screens.
src/​view/​frontend/​web/​css/​toolbar/​_groups.css Styles the timeline, controls, drawers, and legends.

Review effort: Balanced

Restrict detached DevTools node detection to UI-owned selectors so audited storefront elements remain tracked, bound LCP resource phase intervals to [ttfbMs, totalMs], keep Server-Timing as duration-only diagnostics, validate total LCP thresholds before emitting healthy tips, and preserve waterfall scroll offset and keyboard focus across snapshot re-renders.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings December 1, 2026 19:13

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Active issues cause horizontal scroll position to reset when returning to the Profiler tab at 2×/4× zoom and can leave the storefront LCP highlight stuck after a refresh or chart replacement.

1 open issue
1 previously missed issue

In code that hasn't changed since last review

Medium severity Clear LCP preview before replacing profiler rows

src/​view/​frontend/​web/​js/​toolbar/​ui/​profiler-waterfall-details.js:510

A live refresh or chart replacement while the LCP target row is hovered can leave its storefront highlight stuck. Removing the row does not fire mouseleave, and inspector/ui.js:116–142 retains the preview independently of the drawer, taking precedence over the pinned highlight. Clear the preview before replacing the drawer or chart in profiler-waterfall.js / profiler-sections.js, and before clearing the full profiler body in profiler.js.

5 resolved since last review

Review effort: Balanced

Guard scrollLeft persistence and restoration behind a positive viewport clientWidth check and defer scroll/focus restoration via ResizeObserver and requestAnimationFrame when renderProfilerContent runs while the Profiler panel is still hidden.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot AI balanced review requested due to automatic review settings December 1, 2026 19:28

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔵 Needs a closer look

Outstanding issues misclassify compression, leave stale Inspector previews, allow keyboard focus to escape the toolbar, and add repeated document-wide scans during collection.

No open issues 🎉

4 previously missed issues

In code that hasn't changed since last review

Medium severity Reuse URL-to-element maps across blocking asset lookups

src/​view/​frontend/​web/​js/​toolbar/​profiler-collector.js:95

Each blocking stylesheet triggers a fresh document-wide query and array allocation; the JS branch repeats this for every blocking script. Every live snapshot repeats these scans even when the Profiler is closed, adding collector overhead that grows with both the blocking-asset count and the matching DOM nodes. Build URL-to-element maps once per collection pass and reuse them for all entries.

Medium severity Use encoded body size to measure document compression

src/​view/​frontend/​web/​js/​toolbar/​ui/​profiler-waterfall-details.js:299

transferSize includes HTTP response headers, so it cannot measure body compression. For example, a 1 KB decoded document compressed to 700 B with 500 B of headers is reported as “Uncompressed” here because its transfer size is 1,200 B. Expose navigation encodedBodySize in the collector and compare that with decodedBodySize; keep transferSize only for the separate transfer-size display.

Medium severity Clear waterfall preview before replacing the hovered row

src/​view/​frontend/​web/​js/​toolbar/​ui/​profiler-waterfall-details.js:510

A live collector update replaces the hovered LCP row without firing mouseleave, leaving its global Inspector preview active and masking the pinned selection. Clear any waterfall-owned preview before removing or replacing its drawer, including snapshot renders in profiler.js and scope/zoom refreshes in profiler-sections.js.

Medium severity Return focus to the selected row when closing the drawer

src/​view/​frontend/​web/​js/​toolbar/​ui/​profiler-waterfall.js:966

Closing the drawer with the keyboard removes the focused close button without moving focus elsewhere. Focus falls back to the document body, outside the toolbar, where the menu's keydown-based focus trap cannot intercept the next Tab. Return focus to the selected waterfall row after closing so keyboard navigation stays in the toolbar.

1 resolved since last review

Review effort: Balanced

@dermatz
dermatz merged commit 44ffc70 into main Dec 1, 2026
22 checks passed
@dermatz
dermatz deleted the feature/profiler-waterfall-chart branch December 1, 2026 20:03
@github-actions github-actions Bot mentioned this pull request Dec 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants