Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize Source renderer scroll performance [DRAFT] #9587

Merged
merged 8 commits into from Aug 21, 2023
Merged

Optimize Source renderer scroll performance [DRAFT] #9587

merged 8 commits into from Aug 21, 2023

Conversation

bvaughn
Copy link
Collaborator

@bvaughn bvaughn commented Aug 4, 2023

Final check list:

  • Smoke test
  • Make sure all of our e2e tests pass
  • Make sure all of the screenshot tests pass

How did the React components change?

  • The experimental column breakpoint UI has been removed. It was complicating a lot of things (search result highlights, execution point marker, syntax highlighting) and it wasn't clearly adding much value to offset this. (Jason and I spoke about this ahead of time.)
  • Arguably the most expensive rendering bit– the syntax highlighted tokens– have been moved into a sub component so that they can be memoized after initially rendering. Changes like mouse over highlights will no longer cause this component to be re-rendered.
  • Fewer ReactElements (and DOM nodes) are being created per row.
  • Memoization has been removed from itemData since "hot" actions (like scroll position, cursor position) were frequently invalidating the memoized values anyway.
  • Current line highlights (and the alternate source mapping that goes along with them) have been lifted out of the row rendering components and into the main SourceList.
  • Mouse interactions (e.g. token hover, add-log-point button) are ignored while the user is scrolling (to reduce the overall amount of work we have to do during this performance-sensitive time).

How has the DOM changed?

The React components have changed a lot (hopefully in a way that simplifies them and makes them more performant) but the underlying DOM also changes (to become flatter) with this PR. Hopefully this simplifies positioning and helps the browser render/layout a bit faster. Here's a before/after for a single row (the same row)

HTML before

<div class="SourceListRow_Row__UOalW" data-test-hit-counts-state="loaded" data-test-contents-state="parsed" data-test-id="SourceLine-2840" data-test-name="SourceLine" style="...">
  <div class="SourceListRow_LineWithHits__e7G7S">
    <div class="SourceListRow_LineNumber__TbrqD" data-test-id="SourceLine-LineNumber-2840">
      <span data-test-name="SourceRowLineNumber">2840</span>
      <div class="SourceListRow_BreakpointToggle__vCI_n" data-test-name="BreakpointToggle" data-test-state="off">2840</div>
    </div>
    <div class="SourceListRow_LineHitCountBar__7SxRJ SourceListRow_LineHitCountBar3__fGHGC"></div>
    <div class="SourceListRow_LineHitCountLabel__zYkzG SourceListRow_LineHitCountLabel3__nKp99">20k</div>
    <div class="SourceListRow_LineSegmentsAndPointPanel__IoUvD" data-test-name="SourceLine-Contents">
      <pre class="SourceListRow_LineSegment__XUkZ_">
        <span class="" data-column-index="0">  </span>
        <span class="tok-variableName" data-column-index="2" data-inspectable-token="true">a</span>
        <span class="" data-column-index="3"> </span>
        <span class="tok-operator" data-column-index="4">=</span>
        <span class="" data-column-index="5"> </span>
        <span class="tok-variableName" data-column-index="6" data-inspectable-token="true">c</span>
        <span class="tok-operator" data-column-index="7">.</span>
        <span class="tok-propertyName" data-column-index="8" data-inspectable-token="true">ref</span>
        <span class="tok-punctuation" data-column-index="11">;</span>
      </pre>
      <div class="SourceListRow_HoverButtonCompanion__L_PY9"></div>
    </div>
  </div>
</div>

HTML after

<div class="SourceListRow_Row__UOalW" data-test-line-number="2840" data-test-id="SourceLine-2840" data-test-name="SourceLine" style="...">
  <div class="SourceListRow_LineNumber__TbrqD" data-test-name="SourceLine-LineNumber">2840</div>
  <div class="SourceListRow_LineHitCount3__aE7dN" data-test-name="SourceLine-HitCount">20k</div>
  <span data-column-index="0"> </span>
  <span class="tok-variableName" data-column-index="2" data-inspectable-token="true">a</span>
  <span data-column-index="3"> </span>
  <span class="tok-operator" data-column-index="4">=</span>
  <span data-column-index="5"> </span>
  <span class="tok-variableName" data-column-index="6" data-inspectable-token="true">c</span>
  <span class="tok-operator" data-column-index="7">.</span>
  <span class="tok-propertyName" data-column-index="8" data-inspectable-token="true">ref</span>
  <span class="tok-punctuation" data-column-index="11">;</span>
</div>

Is the new Source viewer faster?

I think so, although it's difficult to measure this sort of stuff.

Scrolling before

Rough average scroll handler duration ~12ms maybe?
Screen Shot 2023-08-17 at 2 58 02 PM

Scrolling after

Rough average scroll handler duration ~5ms maybe?
Screen Shot 2023-08-17 at 2 58 11 PM

@vercel
Copy link

vercel bot commented Aug 4, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
devtools ✅ Ready (Inspect) Visit Preview 💬 Add feedback Aug 21, 2023 4:55pm

@replay-io
Copy link

replay-io bot commented Aug 4, 2023

E2E Tests

72 replays were recorded for edd0785.

image 1 Failed
  • react_devtools 02: RDT integrations (Chromium)
      locator.textContent: Error: strict mode violation: locator('[data-test-id^=SourceLine]').filter({ has: locator('[data-test-name="ViewSourceHighlight"]').or(locator('[data-testname="ViewSourceHighlight"]')) }).locator('[data-test-name="SourceLine-LineNumber"]').or(locator('[data-test-id^=SourceLine]').filter({ has: locator('[data-test-name="ViewSourceHighlight"]').or(locator('[data-testname="ViewSourceHighlight"]')) }).locator('[data-testname="SourceLine-LineNumber"]')) resolved to 2 elements:
          1) <div data-test-name="SourceLine-LineNumber" class="So…>280</div> aka getByText('280')
          2) <div data-test-name="SourceLine-LineNumber" class="So…>135</div> aka getByText('135')
      =========================== logs ===========================
      waiting for locator('[data-test-id^=SourceLine]').filter({ has: locator('[data-test-name="ViewSourceHighlight"]').or(locator('[data-testname="ViewSourceHighlight"]')) }).locator('[data-test-name="SourceLine-LineNumber"]').or(locator('[data-test-id^=SourceLine]').filter({ has: locator('[data-test-name="ViewSourceHighlight"]').or(locator('[data-testname="ViewSourceHighlight"]')) }).locator('[data-testname="SourceLine-LineNumber"]'))
      ============================================================
image 71 Passed

View test run on Replay ↗︎

Snapshot Tests

100 replays were recorded for edd0785.

image 0 Failed
image 100 Passed

View test run on Replay ↗︎

@bvaughn bvaughn force-pushed the FE-1790 branch 2 times, most recently from 8a27825 to 3f7b065 Compare August 17, 2023 14:53
@bvaughn bvaughn marked this pull request as ready for review August 18, 2023 21:35
@bvaughn
Copy link
Collaborator Author

bvaughn commented Aug 18, 2023

Couple of Delta tests failed. Probably helper methods need to be updated to account for markup changes. I'll pick those up Monday morning. I think this is ready to be reviewed, otherwise.

Copy link
Collaborator

@markerikson markerikson left a comment

Choose a reason for hiding this comment

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

No real feedback :) You've obviously put a lot of thought into this, and as usual the changes make sense at first glance based on the description.

@bvaughn
Copy link
Collaborator Author

bvaughn commented Aug 21, 2023

Thanks Mark!
The only test failing on this branch is react devtools 02 which is failing frequently on main, so I'm going to land this.

@bvaughn bvaughn merged commit 5500aff into main Aug 21, 2023
35 of 37 checks passed
@bvaughn bvaughn deleted the FE-1790 branch August 21, 2023 17:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants