Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Fix Dropdown useMemo not detecting equal objects #2293

Merged
merged 6 commits into from
Nov 2, 2022

Conversation

mariusdkm
Copy link
Contributor

@mariusdkm mariusdkm commented Oct 28, 2022

This pull requests improves the performance of the dash core component dropdown.
The useMemo didn't recognize that the objects inside the options array of the dropdown stayed the same, so the useMemo got recalculated all the time.
Because of this Dropdowns with a lot of values inside (I have some with >1k) took a lot of time to render(>100ms).
Using the useRef the current options-object(and the address associated with that) are saved and compared with the new options-object is deep compared to that one using isEqual from react-fast-compare.
That way the persistentOptions is only changed when the options change, and that way the useMemo is only executed when needen.

Contributor Checklist

  • I have run the tests locally and they passed. (refer to testing section in contributing)

optionals

  • I have added entry in the CHANGELOG.md
  • If this PR needs a follow-up in dash docs, community thread, I have mentioned the relevant URLS as follows
    • this GitHub #PR number updates the dash docs
    • here is the show and tell thread in Plotly Dash community

Copy link
Contributor

@T4rk1n T4rk1n left a comment

Choose a reason for hiding this comment

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

💃 Looks good and worked well for me with a dropdown of 4k uuids.

@T4rk1n T4rk1n merged commit 0879395 into plotly:dev Nov 2, 2022
@mariusdkm mariusdkm deleted the fix-use-memo branch November 3, 2022 09:25
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants