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

Perf: improve useMemoized callback execution time #5190

Merged
merged 5 commits into from
May 17, 2024
Merged

Conversation

OEvgeny
Copy link
Collaborator

@OEvgeny OEvgeny commented May 17, 2024

Changelog Entry

  • Improved performance for useMemoized, in PR 5190, by @OEvgeny

Description

This PR reduces time spent in the memoized function created by useMemoized by 3-18 times. As this function is one of the primitives we use to improve performance, we should keep it as fast and simple as possible.

Design

The main idea is to reduce unnecessary object allocations and reuse existing objects where possible.

Changes are:

  • use a single lookup instead of combined array lookup
  • reuse cached object if found
  • do not create unnecessary objects
  • explicit branching for cached / non-cached conditions

Specific Changes

  • Updated memoizedFn implementation

-

  • I have added tests and executed them locally
  • I have updated CHANGELOG.md
  • I have updated documentation

Review Checklist

This section is for contributors to review your work.

  • Accessibility reviewed (tab order, content readability, alt text, color contrast)
  • Browser and platform compatibilities reviewed
  • CSS styles reviewed (minimal rules, no z-index)
  • Documents reviewed (docs, samples, live demo)
  • Internationalization reviewed (strings, unit formatting)
  • package.json and package-lock.json reviewed
  • Security reviewed (no data URIs, check for nonce leak)
  • Tests reviewed (coverage, legitimacy)

@OEvgeny OEvgeny marked this pull request as ready for review May 17, 2024 19:14
@OEvgeny OEvgeny changed the title Perf: improve useMemoized execution time Perf: improve useMemoized callback execution time May 17, 2024
@OEvgeny OEvgeny requested a review from compulim May 17, 2024 20:11
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.

2 participants