Skip to content

Draw the function comparison's graphs when they come into view - #308

Open
r0ny123 wants to merge 1 commit into
masterfrom
perf/draw-comparison-graphs-in-view
Open

r0ny123 wants to merge 1 commit into
masterfrom
perf/draw-comparison-graphs-in-view

Conversation

@r0ny123

@r0ny123 r0ny123 commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

The function comparison page (/data/matches/function/<a>/<b>) lays out and draws both control flow graphs as soon as it loads. On a large pair that holds the main thread for seconds. Meanwhile the graphs start at the bottom edge of the first screen on desktop (927 px down in a 940 px window) and below it on a phone. On 549/2356, 237 and 240 blocks, Lighthouse counts 1.8 s of blocking time on desktop on master, and 0 with this branch. This draws the graphs once they come into view, or once a control above them is used.

Change.

  • result_compare_function_vs.html:53-90: window.onload no longer calls the two loaders.
    • drawGraphs() (:66) calls them once. It runs when any part of #xcfg_container enters the upper three quarters of the window, through an IntersectionObserver with rootMargin: "0px 0px -25% 0px".
    • It also runs on a pointerdown, focusin or keydown inside #xcfg_top, the controls above the graphs. Using one is a request for the graphs too.
    • Without IntersectionObserver, the graphs are drawn on load, as before.
  • main_duo.js:3791, bindDisplayControls(), binds Show Loops, Show Cycles, Show Loop Boundaries and Enable Tooltip.
    • showGraph() used to bind them, so a click made before the first graph was drawn did nothing, or left a checkbox saying the opposite of what the graphs showed. On master that window was the first seconds of the load; here it would be all the time before scrolling.
    • The template calls bindDisplayControls() at load.
    • Each panel picks up the controls' state as it draws, as it already did for a panel that finished after the other:
      • reapplyHighlight() runs after showGraph() (main_duo.js:1361, :1403);
      • setLoopBoundaryVisibility() runs at the end of renderLoopBoundaries() (:3779);
      • the hover handler reads isTooltipEnabled.
  • function_compare.js: onGraphShown() (:95) offers Combined only once both graphs are drawn.
    • A press on Combined before then starts the drawing. It is now remembered by its label's listener (:51) and acted on once the option is there (:109), unless Side by side is pressed after it.
    • Chromium sends a disabled radio only the pointerdown of a press, no click, so that is what the label listens for.

What this costs: the freeze moves from the load to the first scroll down to the graphs, and the panes are blank until the graphs are drawn. Master never showed the page's "Loading" text either, as nothing un-hides #loading_a and #loading_b. A Web Worker for the layout, as #292 does for the single function page, would remove the freeze itself. Nothing draws the graphs for printing, so printing the page before scrolling to them prints empty panes.

Verification. On the testbed, master (6564602) and this branch (0e6aa5f) ran as side instances against the live backend, logged in as analyst1. Apart from the logins and the findLoops POST the page itself sends, every request was a GET.

Lighthouse 12.8.2 on 549/2356, three runs a side, the two sides in turn. Performance is given for each run; the rest are means.

Performance TBT FCP LCP CLS
desktop, master -> this branch 44/44/44 -> 75/75/75 1,824 -> 0 ms 1.99 -> 1.96 s 2.75 -> 2.71 s 0.000 -> 0.003
mobile, master -> this branch 25/25/25 -> 25/25/25 7,534 -> 7,633 ms 12.69 -> 12.66 s 20.41 -> 17.39 s 0.000 -> 0.000
desktop, build -> with this branch 70/70/70 -> 100/100/100 1,238 -> 0 ms 0.43 -> 0.40 s 0.69 -> 0.62 s 0.003 -> 0.008
mobile, build -> with this branch 47/49/49 -> 91/97/91 5,711 -> 58 ms 1.56 -> 1.55 s 5.32 -> 3.06 s 0.000 -> 0.000

In Chromium, master against the branch:

  • Anchor link: a #function_xcfg URL and the "Go to the control flow graphs" button at the top both end with the graphs drawn and their heading at the top of the window. That is scrollY 792 at 1440x900 and 772 at 412x823, the same on both sides, and the page height is the same too.
  • A browser review at 1440x900, 1350x940, 412x823 and 390x844 on 549/2356, also on 493/18696 at 1440x900 and 412x823 and on 357/1535 at 1440x900. On the code before the Combined change, it found:
    • After scrolling: block and edge counts, hover outlines, click-to-centre, synchronised zoom, Reset view, both highlights, the boundary toggle, the tooltip, Backspace and the combined view behave the same on both sides. Screenshots of the graph panes are identical, except for two pixels one colour level apart in one hovered block at 412x823 and 390x844.
    • Early clicks: each of the four display controls pressed before the graphs exist ends in the state a press after drawing gives on master. A press on Combined before drawing is covered by the tests below.
    • Keyboard, reload and resize:
      • tabbing into the controls draws;
      • a reload keeps its scroll position and draws;
      • a window resized before drawing fits the graphs to the new panes, where master keeps the fit from load.

Tests. In tests/testFunctionVsBrowser.py:

  • test_the_graphs_are_drawn_when_they_come_into_view[mobile|desktop]: at Lighthouse's two sizes, nothing is fetched or drawn after load, until the graphs are scrolled to.
  • test_using_a_control_above_the_graphs_draws_them[click|focus]: with an observer that never reports, a click on Reset view or focus on Sync graphs draws them, without a page error.
  • test_the_display_controls_used_before_the_graphs_are_drawn_hold_once_they_are[#showLoops-Hide Loops|#showCycles-Hide Cycles]: the graphs' answers are held while a highlight button, the boundary checkbox and the tooltip checkbox are used. Once drawn:
    • the button reads "Hide …";
    • blocks are painted in both panels;
    • the boundaries are hidden;
    • hovering shows the tooltip.
  • test_combined_pressed_before_the_graphs_are_drawn_is_shown_once_they_are[combined|taken-back].
  • test_without_intersection_observer_the_graphs_are_drawn_on_load.
  • The existing tests that need drawn graphs scroll to them first (comparison_page and page_with_a_dangerous_api_name).
  • Taking a piece of the change out makes a test fail. The pieces are:
    • the control listeners;
    • any one of the four bindings in bindDisplayControls();
    • the replay of a Combined press;
    • its take-back;
    • a rootMargin of 0px, which draws at load at the desktop size.
  • On master's code (6564602), 10 of the 27 tests in the file fail. The one new test that passes there too is a guard: test_without_intersection_observer_the_graphs_are_drawn_on_load, as master always draws on load.
  • Full suite with Chromium on 0e6aa5f: 2099 passed, none skipped; ruff check . is clean.

Relation to open PRs. A trial merge (git merge-tree) with each open PR head is clean. Five open PRs change this branch's files in their own commits: #160, #245, #264, #269 and #304. #304 is stacked on #245, and #266 on #264. Each was merged locally with this branch, and tests/testFunctionVsBrowser.py was run on the merge:

The comparison page laid out and drew both control flow graphs on load,
which holds the main thread for seconds on a large pair, for graphs that
start below the first screen at phone and desktop sizes alike. They are
now drawn once any part of them enters the upper three quarters of the
window, or a control above them is used by pointer or keyboard. Without
IntersectionObserver they are drawn on load, as before.

Show Loops, Show Cycles and the loop-boundary and tooltip checkboxes were
bound by showGraph(), so a click before the first graph was drawn did
nothing, or left a checkbox saying the opposite of what the graphs
showed. With the drawing deferred that is any click before scrolling, so
bindDisplayControls() binds them when the page loads; each panel picks
up their state as it draws, as it already did for a panel that finished
after the other.

The Combined view is offered once both graphs are drawn. Pressing it
before then starts the drawing, and is now remembered and acted on once
the option is there, unless Side by side is pressed after it.
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.

1 participant