Memory usage statistics #2951
dead-claudia
started this conversation in
Meta/Feedback
Replies: 3 comments
-
Very interesting and accurate findings! |
Beta Was this translation helpful? Give feedback.
0 replies
-
Great findings |
Beta Was this translation helpful? Give feedback.
0 replies
-
Also forgot to mention the part on reusing cached attributes will also moderately reduce object count and mildly memory usage on update. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I did some research into our memory allocation patterns within Chrome.
{a: 1}
) reduces that allocation to only 16 bytes, indicating it's allocating 4 slots by default for empty objects and only the minimum slots needed for non-empty objects.<div class="foo">foo</div>
inserted into the body as its first child requires 140 bytes for the<div>
and 96 bytes for the inner text node, resulting in 236 bytes total.m("div.foo", "foo")
allocates 80 bytesvnode.attrs
assembled from the selector cache entry, created from an empty object with 1 property addedm("div.container", m("div.foo", "foo"))
allocates 252 bytesm("div.container", m("div.foo", "foo"), m("div.bar", "bar"))
allocates 332 bytesm.render(root, m("div.foo", "foo"))
against an empty, pre-initialized detached DOM node allocates:<div>
vnode.state
object allocated for each vnodem.render(root, m("div.container", m("div.foo", "foo")))
against an empty, pre-initialized detached DOM node allocates:<div>
svnode.state
objects allocated for 2 vnodesm.render(root, m("div.container", m("div.foo", "foo"), m("div.bar", "bar"))
against an empty, pre-initialized detached DOM node allocates:<div>
svnode.state
objects allocated for 3 vnodesI see a few easy ways to cut down on memory allocation dramatically:
execSelector
to return the underlying frozen object directly rather than cloning it when no user-provided attributes existvnode.state
on DOM elements - it's rarely used anywaysm("tag", child)
(a relatively common case)In total, I predict that would reduce total memory consumption of front-end view code by roughly 5-20% along with a 20-30% reduction in object generation depending on the nature of the trees (I'm accounting for style rendering in that overestimate):
m.render(root, m("div.foo", "foo"))
against an empty, pre-initialized detached DOM node allocates:<div>
m.render(root, m("div.container", m("div.foo", "foo")))
against an empty, pre-initialized detached DOM node allocates:<div>
sm.render(root, m("div.container", m("div.foo", "foo"), m("div.bar", "bar"))
against an empty, pre-initialized detached DOM node allocates:<div>
sThis would be relatively straightforward to implement:
vnode.state
from DOM vnodes would be as simple as just moving that to the create component flow.Vnode.normalizeChildren
to special-case single-element arrays -hyperscriptVnode
already returns them, butVnode.normalizeChildren
doesn't check for that.if (input.length === 1) return [Vnode.normalize(input[0])]
. It wouldn't need to verify keys as it's a degenerate case, so a mild perf boost may also come out of it.Beta Was this translation helpful? Give feedback.
All reactions