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

core-data: Memoize getEntitiesConfig selector #58393

Merged
merged 1 commit into from
Jan 30, 2024

Conversation

tyxla
Copy link
Member

@tyxla tyxla commented Jan 29, 2024

What?

This PR suggests memoizing the getEntitiesConfig() config selector. Spotted while reviewing some other PRs.

cc @jsnajdr and @ellatrix as I know they've been working to optimize some selectors (and remove some needlessly memoized ones).

Why?

Because it will return a new array on every call (only because .filter() returns a new array), and in many cases, that's wasteful, as the underlying data hasn't changed. Cases like this are some of the reasons why we're memoizing selectors in the first place.

In my testing, this reduces the selector calls by 5 times during a standard site editor load. Then a few more calls are completely removed when opening the inserter. I don't see substantial improvements in the performance test results, but the more different entities are requested, the better the improvement will be.

How?

We're straightforwardly using createSelector().

Testing Instructions

Verify all checks are green - this is well covered by tests.

Testing Instructions for Keyboard

None

Screenshots or screencast

None

@tyxla tyxla added [Type] Performance Related to performance efforts [Package] Core data /packages/core-data labels Jan 29, 2024
@tyxla tyxla self-assigned this Jan 29, 2024
@tyxla tyxla requested a review from nerrad as a code owner January 29, 2024 16:27
Copy link
Member

@Mamaduka Mamaduka left a comment

Choose a reason for hiding this comment

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

Makes sense.

@tyxla tyxla merged commit b99251a into trunk Jan 30, 2024
64 checks passed
@tyxla tyxla deleted the update/memoize-get-entities-config branch January 30, 2024 10:01
@github-actions github-actions bot added this to the Gutenberg 17.7 milestone Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Package] Core data /packages/core-data [Type] Performance Related to performance efforts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants