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

Performance: Assign block list refs by constant reference #3171

Merged
merged 1 commit into from
Oct 27, 2017

Conversation

aduth
Copy link
Member

@aduth aduth commented Oct 26, 2017

Related: #3170

This pull request seeks to optimize to eliminate a render cascade which occurs to every block when the VisualEditorBlockList component renders. Previously, we would assign a new function as the ref prop to every rendered VisualEditorBlock element, thereby incurring a new render to every block rendered in the post.

The changes here seek to use a single constant reference of setBlockRef, eliminating the custom blockRef component passed to VisualEditorBlock in favor of findDOMNode to access the DOM node from the component instance.

Testing instructions:

Verify there are no regressions in the behavior of block multi-selection.

@aduth aduth added the [Type] Performance Related to performance efforts label Oct 26, 2017
@@ -65,21 +65,24 @@ class VisualEditorBlockList extends Component {
this.lastClientY = clientY;
}

setBlockRef( ref, uid ) {
setBlockRef( ref ) {
const uid = ref.props.uid;
Copy link
Contributor

Choose a reason for hiding this comment

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

The only thing that bothers me about this, is that it's not obvious that we need to change this if we rename/remove the uid prop (or if React changes the element object shape)

Copy link
Member Author

Choose a reason for hiding this comment

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

The only thing that bothers me about this, is that it's not obvious that we need to change this if we rename/remove the uid prop (or if React changes the element object shape)

Sure, I can see this. I imagine if we did change the uid prop, there'd be much more impacted code than just what's referenced here. I don't love reaching into the element props, but don't necessarily see it as an unstable API.

How could this be improved? Would a comment help clarify?

I had considered removing the ref entirely and passing the node from the block component itself when selection starts, but this isn't sufficient since the block list needs to compare the selection with all rects of blocks in the list, so it needs access to every block's DOM node.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's add a comment. Anyway nice improvement 👍

Copy link
Contributor

@youknowriad youknowriad left a comment

Choose a reason for hiding this comment

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

👍 I like how we got rid of blockRef using findDOMNode

Creating new function reference would cascade render to VisualEditorBlock on every render
@aduth aduth force-pushed the update/perf-block-list-ref branch from a23ad07 to 68f6cbe Compare October 27, 2017 12:17
@codecov
Copy link

codecov bot commented Oct 27, 2017

Codecov Report

Merging #3171 into master will decrease coverage by <.01%.
The diff coverage is 0%.

Impacted file tree graph

@@            Coverage Diff            @@
##           master   #3171      +/-   ##
=========================================
- Coverage   31.51%   31.5%   -0.01%     
=========================================
  Files         221     221              
  Lines        6305    6306       +1     
  Branches     1120    1120              
=========================================
  Hits         1987    1987              
- Misses       3630    3631       +1     
  Partials      688     688
Impacted Files Coverage Δ
editor/modes/visual-editor/block.js 0% <ø> (ø) ⬆️
editor/modes/visual-editor/block-list.js 0% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 18dfb29...68f6cbe. Read the comment docs.

@aduth aduth merged commit 2d37deb into master Oct 27, 2017
@aduth aduth deleted the update/perf-block-list-ref branch October 27, 2017 12:27
@aduth
Copy link
Member Author

aduth commented Oct 27, 2017

This introduced a regression where an error is logged when removing a block, since ref is called with null. A solution is not entirely obvious, since we expected to be able to remove a node from the cached set by its UID when unmounted, but we can't get the UID for the unmounting element.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Type] Performance Related to performance efforts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants