Skip to content

perf: Improved performance and reduced memory consumption #411

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

Merged
merged 14 commits into from
Jun 13, 2024
Merged

perf: Improved performance and reduced memory consumption #411

merged 14 commits into from
Jun 13, 2024

Conversation

negezor
Copy link
Contributor

@negezor negezor commented Jun 2, 2024

Hello. I profiled my application to eliminate micro lags in a large table. There are 3 fields in it that are Multiselect with a large number of options, and 100 rows per page. The table is reactive and updated via WebSocket, but each update was accompanied by micro lags, especially noticeable on mobile devices.

After reviewing the code, I identified several opportunities for improvement, here are some of them:

  • Avoid unnecessary array allocations, especially for functions like isNullish() and aria-* getters.
  • Eliminate prop checks after toRefs(), they are specified in SFC, so they will never be undefined. The same goes for resolveDeps(), a hook can't be undefined.
  • Quickly exit the arraysEqual() function if the array sizes do not match. In the current implementation, it sorts the array first and then checks.
  • Replace ref() with shallowRef() for binding HTML. This is a common use case for shallowRef(); it will only track the setting of the value, not every HTML property.
  • Replace most computed() with toRef(). Instead of having a cache for simple getters, it's cheaper to directly call them. Currently, a polyfill is used to implement toRef(). Since the change toRef() appeared only in Vue 3.3+, this polyfill is slightly slower than the standard implementation, but it's the same one used in VueUse.

After these changes and subsequent profiling, I conclude that the micro lags have disappeared, the average memory consumption per page has decreased, the page opening time has become approximately twice as fast on mobile devices, and the INP metric has also improved.

@adamberecz
Copy link
Collaborator

Impressive - thanks. These definitely improves the lib's performance.

@adamberecz adamberecz merged commit 21a912e into vueform:main Jun 13, 2024
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