This issue was moved to a discussion.
You can continue the conversation there. Go to discussion →
Memory usage statistics #2755
Labels
Area: Core
For anything dealing with Mithril core itself
Type: Meta/Feedback
For high-level discussion around the project and/or community itself
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.The text was updated successfully, but these errors were encountered: