Skip to content

Conversation

@youknowriad
Copy link
Contributor

While investigating #11782 I discovered that the getBlock selector is not very performant even memoized. This PR tries to tweak our components to avoid relying too much on the block objects and use the block Ids and discrete properties instead.

I honestly don't know if it did improve the slowness feeling or not. It's very hard to measure properly.

@youknowriad youknowriad added the [Type] Performance Related to performance efforts label Nov 13, 2018
@youknowriad youknowriad self-assigned this Nov 13, 2018
@youknowriad youknowriad requested review from a team and aduth November 13, 2018 12:53
const firstRemovedBlockClientId = action.clientIds[ 0 ];
const state = store.getState();
const currentSelectedBlock = getSelectedBlock( state );
const currentSelectedBlock = getSelectedBlockClientId( state );
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel this is a bug fix somehow because we're comparing the previous result with a clientId and not a block object.

Copy link
Member

Choose a reason for hiding this comment

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

I feel this is a bug fix somehow because we're comparing the previous result with a clientId and not a block object.

I agree. It's probably not made any difference only because selectBlock won't do anything if the ID hasn't changed. Maybe it's useless code? Can be good to avoid dispatching if we don't need it.

Perhaps pull out to a separate pull request?

* because we want the user to focus on the unregistered block warning, not block settings.
*/
if ( ! selectedBlock || isSelectedBlockUnregistered ) {
if ( ! blockType || ! selectedBlockClientId || isSelectedBlockUnregistered ) {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure why the blockType test was necessary here for e2e tests

return ( props ) => {
const { align } = props.block.attributes;
const validAlignments = getBlockValidAlignments( props.block.name );
const { align } = props.blockAttributes;
Copy link
Member

Choose a reason for hiding this comment

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

Based on build failures, I think the tests for this need to be updated.

isEmptyDefaultBlock: block && isUnmodifiedDefaultBlock( block ),
isPreviousBlockADefaultEmptyBlock: previousBlock && isUnmodifiedDefaultBlock( previousBlock ),
isEmptyDefaultBlock: blockName && isUnmodifiedDefaultBlock( { name: blockName, attributes: blockAttributes } ),
isPreviousBlockADefaultEmptyBlock: previousBlockClientId && isUnmodifiedDefaultBlock( {
Copy link
Member

Choose a reason for hiding this comment

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

We should never want to construct the object of a block. It seems we could use createBlock?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not really returned as a prop though, we just return a boolean.

Copy link
Member

Choose a reason for hiding this comment

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

I'm not concerned so much about what we expose to the component as a prop, just limiting the exposure to any code which makes an assumption about the block abstraction, should that abstraction come to change in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes, I don't like isUnmodifiedDefaultBlock either, I think I'd be fine with createBlock for now.

@youknowriad
Copy link
Contributor Author

I'm going to split this PR into smaller ones.

@youknowriad
Copy link
Contributor Author

Closing as this was exploded into smaller PRs.

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.

3 participants