perf: improve memory usage for static vnodes
Use the already mounted nodes as cache instead of separate caching via template. This reduces memory usage by 30%+ in VitePress.
This commit is contained in:
@@ -82,5 +82,28 @@ describe('runtime-dom: node-ops', () => {
|
||||
expect((first as Element).namespaceURI).toMatch('svg')
|
||||
expect((last as Element).namespaceURI).toMatch('svg')
|
||||
})
|
||||
|
||||
test('cached insertion', () => {
|
||||
const content = `<div>one</div><div>two</div>three`
|
||||
const existing = `<div>existing</div>`
|
||||
const parent = document.createElement('div')
|
||||
parent.innerHTML = existing
|
||||
const anchor = parent.firstChild
|
||||
|
||||
const cached = document.createElement('div')
|
||||
cached.innerHTML = content
|
||||
|
||||
const nodes = nodeOps.insertStaticContent!(
|
||||
content,
|
||||
parent,
|
||||
anchor,
|
||||
false,
|
||||
cached.firstChild,
|
||||
cached.lastChild
|
||||
)
|
||||
expect(parent.innerHTML).toBe(content + existing)
|
||||
expect(nodes[0]).toBe(parent.firstChild)
|
||||
expect(nodes[1]).toBe(parent.childNodes[parent.childNodes.length - 2])
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user