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

layout: Dramatically improve performance of layout queries and `requestAnimationFrame()`. #14442

Closed
wants to merge 6 commits into from

Commits on Dec 2, 2016

  1. layout: Replace `ConstructionResult::swap_out()` with

    `ConstructionResult::get()`.
    
    It only actually swaps out in nonincremental mode (which isn't suitable
    for real world use), so the name is confusing.
    pcwalton committed Dec 2, 2016
  2. script: Detect when the page is using `requestAnimationFrame()` for

    non-animation purposes and back off to a timer if so.
    
    After this patch, when the page calls `requestAnimationFrame()` too many
    times in the row without actually mutating the DOM, further calls to
    `rAF` will actually perform the moral equivalent of `setTimeout(16)`.
    This saves a lot of CPU time compared to actually waiting for the
    vertical blanking interval, because waiting for that requires us to draw
    the page.
    
    Reduces CPU usage drastically on nytimes.com, which has a perpetual
    `requestAnimationFrame()` loop that checks whether ads are in view.
    pcwalton committed Dec 2, 2016
  3. query: Stop searching the entire flow tree to resolve script-to-layout

    queries.
    
    Instead of searching the entire tree to find the applicable fragment, we
    use the flow construction result of the nearest DOM node to find the
    flow we're looking for directly. We then recursively do this with
    ancestor DOM nodes in order to find the entire flow tree path,
    performing breadth first search to deal with anonymous flows in between.
    
    To fully eliminate the search, we will probably want some combination of
    (a) parent pointers in the flow tree and (b) rewritten script-to-layout
    queries that don't depend on visiting all ancestor flows of the query
    node. But this is a quick and dirty solution that dramatically improves
    the performance of layout queries.
    
    This is a large responsiveness increase on nytimes.com.
    pcwalton committed Dec 2, 2016
  4. layout_thread: Don't propagate dirty bits around the tree if no styles

    changed and no flows were reconstructed.
    
    This saves a tree traversal. It also has the side effect of making
    incremental reflow bugs of the form "a dirty bit is never cleared" less
    likely to ruin the performance of layout queries.
    pcwalton committed Dec 2, 2016
  5. layout_thread: Assert that we removed the `REPAINT` flag from the root

    after building display lists.
    pcwalton committed Dec 2, 2016
  6. layout_thread: Minor style cleanup.

    pcwalton committed Dec 2, 2016
You can’t perform that action at this time.