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

fix(perf): remove usage of SearchParameters.clearRefinements #6004

Merged
merged 4 commits into from
Jan 22, 2024

Conversation

Haroenv
Copy link
Contributor

@Haroenv Haroenv commented Jan 17, 2024

This functions is much slower than individually clearing the specified refinements. In a test with DynamicWidgets + 118 RefinementLists the initial mount goes from 550ms to 350ms in my tests.

I've looked around to see if there's good tools for these improvements, to ensure we don't regress, but i couldn't find much (perf is mainly focused on apps).

Unfortunately I can't really deprecate the method as we still use it in a non-hot path inside the helper itself to create the right queries in queryBuilder. We'll just have to rely on "seeing other examples" to avoid using parameters.clearRefinements.

As widgets can't be mixed across the same attribute, there's no actual risk in this change as far as I can tell.

before after
Screenshot 2024-01-17 at 11 25 07 Screenshot 2024-01-17 at 11 25 16

This functions is much slower than individually clearing the specified refinements. In a test with DynamicWidgets + 118 RefinementLists the initial mount goes from 600ms to 350ms in my tests.

I've looked around to see if there's good tools for these improvements, to ensure we don't regress, but i couldn't find much (perf is mainly focused on apps).

Unfortunately I can't really deprecate the method as we still use it in a non-hot path inside the helper itself to create the right queries in queryBuilder. We'll just have to rely on "seeing other examples" to avoid using parameters.clearRefinements.

As widgets can't be mixed across the same attribute, there's no actual risk in this change AFAICT.
@Haroenv Haroenv requested review from a team, sarahdayan and aymeric-giraudet and removed request for a team January 17, 2024 10:26
Copy link

codesandbox-ci bot commented Jan 17, 2024

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit 3877bee:

Sandbox Source
InstantSearch.js Configuration
react-instantsearch-app Configuration
example-react-instantsearch-default-theme Configuration
example-react-instantsearch-next-app-dir-example Configuration
example-vue-instantsearch-default-theme Configuration

Haroenv and others added 3 commits January 18, 2024 12:25
* fix(perf): improve speed of setQueryParameters

inside setQueryParameters (used in many cases), we have _parseNumbers, which is always used with the arguments of setQueryParameters or new SearchParameters

TODO: find out why CurrentRefinements > RefinementList changes its order with this change. Not sure yet

* fix(requestBuilder): sort facet refinements in a non-mutating manner (#6007)

introduced in #5764, but wasn't an issue until merge/setQueryParameters doesn't make a new copy constantly of the parameters.

Essentially what's going on:
- when you build the requests, it's sorting the facet values
- this then gets updated in the parameters as well as it's the same object
- with this fix, the sorting is done non-mutating (similar to .toSorted) to avoid the sorting of the parameters for cache to have a potential impact on the UI
Copy link
Member

@dhayab dhayab left a comment

Choose a reason for hiding this comment

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

This is great!

@dhayab dhayab merged commit d9491e1 into master Jan 22, 2024
12 checks passed
@dhayab dhayab deleted the fix/perf-avoid-clear-refinements branch January 22, 2024 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants