-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Fix performance regression for isEditedPostEmpty selector #52759
Conversation
Size Change: +59 B (0%) Total Size: 1.44 MB
ℹ️ View Unchanged
|
|
||
return ! getEditedPostContent( state ); | ||
} | ||
return ! getEditedPostContent( state ); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This last return value probably can be derived from record
, but we can also leave the selector for simplicity.
@@ -1660,7 +1665,7 @@ describe( 'selectors', () => { | |||
expect( isEditedPostEmpty( state ) ).toBe( true ); | |||
} ); | |||
|
|||
it( 'should return false if blocks, but empty content edit', () => { | |||
it( 'should return true if blocks, but empty content edit', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm guessing the original test assumption was incorrect.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, IMO, if there's an edit to "content", it should take priority.
@@ -1709,7 +1714,7 @@ describe( 'selectors', () => { | |||
expect( isEditedPostEmpty( state ) ).toBe( true ); | |||
} ); | |||
|
|||
it( 'should return true if edits include a non-empty content property, but blocks are empty', () => { | |||
it( 'should return false if edits include a non-empty content property', () => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
Fix performance regression introduced in #52417
What?
The
isEditedPostEmpty
is a super optimized selector and since it relied on thegetEditorBlocks
selector that was updated in #52417 to deal with the fact that the "blocks" edit might not always be present, the performance of the former degraded. This PR applies a small trick to theisEditedPostEmpty
selector to restore the previous performance.How?
The small trick is that when there are no edits, the "content" property of a post is a string and checking if the string is empty is actually faster than checking the blocks (which would require parsing).
Testing Instructions
Check that the "typing" metric in the results is actually giving the right results here.
Aside: To be honest the selector is only used to check whether to show the "save button" or not on empty posts. But I personally feel that the button should always be available if there are "edits" regardless of whether the content is empty or not. In other words, I think we can probably "deprecate"/remove/not use that selector entirely, but I'm leaving that separate.