perf: Improved performance and reduced memory consumption #411
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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:
isNullish()
andaria-*
getters.toRefs()
, they are specified in SFC, so they will never be undefined. The same goes forresolveDeps()
, a hook can't be undefined.arraysEqual()
function if the array sizes do not match. In the current implementation, it sorts the array first and then checks.ref()
withshallowRef()
for binding HTML. This is a common use case forshallowRef()
; it will only track the setting of the value, not every HTML property.computed()
withtoRef()
. Instead of having a cache for simple getters, it's cheaper to directly call them. Currently, a polyfill is used to implementtoRef()
. Since the changetoRef()
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.