-
Notifications
You must be signed in to change notification settings - Fork 91
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(NcEmojiPicker): decrease mounting time and memory by moving large constants initialization and storing out from instance's reactive data #4479
Conversation
821f3ea
to
5ad5179
Compare
/backport to stable7 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Slow laptop here:
Metric | 🐌 Before | 🏎️ After |
---|---|---|
Mount time | 70 ms per instance |
1.5 - 2.3 ms per instance |
Memory | +- same results | +- same results |
Don't forget to collect garbage before looking into heap size in the memory tab |
I meant the same results as on your screenshots, only mounting time differs |
…om instance's reactive data Performance improvements: - Mounting time from ~40 ms to ~1 ms per instance - Memory per instance from 1.3 MB to (0.07 MB per instance + ~1 MB shared) Signed-off-by: Grigorii K. Shartsev <me@shgk.me>
5ad5179
to
fdeeb9c
Compare
Rebased onto For history: <template>
<div>
<button @click="key += 1">Re-mount {{ count }} NcEmojiPicker-s</button> See console output for the result
<ul :key="key">
<li v-for="i in count" :key="i">
<span>#{{ i }}</span>
<NcEmojiPicker @select="select" style="display: inline-block">
<NcButton>Select Emoji</NcButton>
</NcEmojiPicker>
<span>selected emoji: {{ emoji }}</span>
</li>
</ul>
</div>
</template>
<script>
let time;
export default {
data() {
return {
count: 100,
emoji: '',
key: 1,
}
},
beforeUpdate() {
time = performance.now()
},
updated() {
const allTime = performance.now() - time
console.log(`NcEmojiPicker ${this.count} instances re-mounting time: ${allTime.toFixed(2)} ms or ${(allTime / this.count).toFixed(2)} ms per instance`)
},
methods: {
select(emoji) {
this.emoji = emoji
},
},
}
</script> |
/backport to stable7 |
☑️ Resolves
NcEmojiPicker
mounts very slow.📝 PR
i18n
andemojiIndex
are not a part ofNcEmojiPicker
's data. They never change and are not reactive state but just constants. However, they were defined in thedata
. So each timeNcEmojiPicker
instance is created:emojiIndex
with constructornew EmojiIndex
andi18n
were createdDep
+Observer
instances for reactivity.While for
i18n
it's slightly noticeable (0.1ms
finally),emojiIndex
is very huge (with about 1MB data).🖼️ Result
Moving constants from
data
outside the component decreases mounting time and allocating memory.40 - 42 ms
per instance0.90 - 0.98 ms
per instance1.325 MB
per instance0.073 MB
per instance + 1 MB shared40ms
may sound nothing. But it multiplies on instances count. So mounting 100 pickers was 4 seconds of blocking time.It also saves about
1.3 MB RAM
per instance. Also sounds small, but it is 130 MB per tab with 100 pickers.Example: Conversations in Talk with many messages with reactions.
Alternative solution
Initialization of
emojiIndex
was moved tosetup
with a check if it was initialized before. So the index is not initialized before the first instance mounting.We can move it to the module, so index will be ready before the first instance is mounted.
P.S.
NcPicker
is still super slow on opening and it is still > 1MB in the bundle.🏁 Checklist