Skip to content

Commit

Permalink
Remove the DOM nodes recycling pool (fix #1653, fix #2023)
Browse files Browse the repository at this point in the history
  • Loading branch information
pygy committed Apr 16, 2018
1 parent 6f7f543 commit 203df39
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 183 deletions.
1 change: 1 addition & 0 deletions docs/change-log.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- API: `m.request` supports `timeout` as attr - ([#1966](https://github.com/MithrilJS/mithril.js/pull/1966))
- Mocks: add limited support for the DOMParser API ([#2097](https://github.com/MithrilJS/mithril.js/pull/2097))
- API: add support for raw SVG in `m.trust()` string ([#2097](https://github.com/MithrilJS/mithril.js/pull/2097))
- Internals: remove the DOM nodes recycling pool ([#2122](https://github.com/MithrilJS/mithril.js/pull/2122))

#### Bug fixes

Expand Down
9 changes: 1 addition & 8 deletions performance/test-perf.js
Original file line number Diff line number Diff line change
Expand Up @@ -358,16 +358,9 @@ var Root = {
}
}

suite.add({
name : "repeated trees (recycling)",
fn : function () {
m.render(scratch, [m(Root)])
m.render(scratch, [])
}
})

suite.add({
name : "repeated trees (no recycling)",
name : "repeated trees",
fn : function () {
m.render(scratch, [m(Root)])
m.render(scratch, [])
Expand Down
222 changes: 63 additions & 159 deletions render/render.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions render/tests/test-component.js
Original file line number Diff line number Diff line change
Expand Up @@ -808,7 +808,7 @@ o.spec("component", function() {
o(methods[hook].args.length).equals(attrs[hook].args.length)(hook)
})
})
o("recycled components get a fresh state", function() {
o("no recycling occurs (was: recycled components get a fresh state)", function() {
var step = 0
var firstState
var view = o.spy(function(vnode) {
Expand All @@ -827,7 +827,7 @@ o.spec("component", function() {
step = 1
render(root, [{tag: "div", children: [{tag: component, key: 1}]}])

o(child).equals(root.firstChild.firstChild)
o(child).notEquals(root.firstChild.firstChild) // this used to be a recycling pool test
o(view.callCount).equals(2)
})
})
Expand Down
2 changes: 1 addition & 1 deletion render/tests/test-onbeforeupdate.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ o.spec("onbeforeupdate", function() {
render(root, temp)
render(root, updated)

o(vnodes[0].dom).equals(updated[0].dom)
o(vnodes[0].dom).notEquals(updated[0].dom) // this used to be a recycling pool test
o(updated[0].dom.nodeName).equals("DIV")
o(onbeforeupdate.callCount).equals(0)
})
Expand Down
6 changes: 3 additions & 3 deletions render/tests/test-onremove.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ o.spec("onremove", function() {
o(vnode.dom.attributes["onremove"]).equals(undefined)
o(vnode.events).equals(undefined)
})
o("calls onremove on recycle", function() {
o("calls onremove on keyed nodes", function() {
var remove = o.spy()
var vnodes = [{tag: "div", key: 1}]
var temp = [{tag: "div", key: 2, attrs: {onremove: remove}}]
Expand All @@ -101,7 +101,7 @@ o.spec("onremove", function() {
render(root, temp)
render(root, updated)

o(vnodes[0].dom).equals(updated[0].dom)
o(vnodes[0].dom).notEquals(updated[0].dom) // this used to be a recycling pool test
o(remove.callCount).equals(1)
})
o("does not recycle when there's an onremove", function() {
Expand Down Expand Up @@ -211,7 +211,7 @@ o.spec("onremove", function() {
render(root, [temp])
render(root, [updated])

o(vnode.dom).equals(updated.dom)
o(vnode.dom).notEquals(updated.dom) // this used to be a recycling pool test
o(onremove.callCount).equals(1)
})
})
Expand Down
8 changes: 4 additions & 4 deletions render/tests/test-updateElement.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ o.spec("updateElement", function() {

o(updated.dom.firstChild.namespaceURI).equals("http://www.w3.org/2000/svg")
})
o("restores correctly when recycling", function() {
o("doesn't restore since we're not recycling", function() {
var vnode = {tag: "div", key: 1}
var updated = {tag: "div", key: 2}

Expand All @@ -250,9 +250,9 @@ o.spec("updateElement", function() {
var c = vnode.dom

o(root.childNodes.length).equals(1)
o(a).equals(c)
o(a).notEquals(c) // this used to be a recycling pool test
})
o("restores correctly when recycling via map", function() {
o("doesn't restore since we're not recycling (via map)", function() {
var a = {tag: "div", key: 1}
var b = {tag: "div", key: 2}
var c = {tag: "div", key: 3}
Expand All @@ -269,6 +269,6 @@ o.spec("updateElement", function() {
var y = root.childNodes[1]

o(root.childNodes.length).equals(3)
o(x).equals(y)
o(x).notEquals(y) // this used to be a recycling pool test
})
})
15 changes: 9 additions & 6 deletions render/tests/test-updateNodes.js
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ o.spec("updateNodes", function() {
o(root.childNodes[0].childNodes[1].childNodes.length).equals(1)
o(root.childNodes[1].childNodes.length).equals(0)
})
o("recycles", function() {
o("doesn't recycle", function() {
var vnodes = [{tag: "div", key: 1}]
var temp = []
var updated = [{tag: "div", key: 1}]
Expand All @@ -785,10 +785,10 @@ o.spec("updateNodes", function() {
render(root, temp)
render(root, updated)

o(vnodes[0].dom).equals(updated[0].dom)
o(vnodes[0].dom).notEquals(updated[0].dom) // this used to be a recycling pool test
o(updated[0].dom.nodeName).equals("DIV")
})
o("recycles when not keyed", function() {
o("doesn't recycle when not keyed", function() {
var vnodes = [{tag: "div"}]
var temp = []
var updated = [{tag: "div"}]
Expand All @@ -798,19 +798,22 @@ o.spec("updateNodes", function() {
render(root, updated)

o(root.childNodes.length).equals(1)
o(vnodes[0].dom).equals(updated[0].dom)
o(vnodes[0].dom).notEquals(updated[0].dom) // this used to be a recycling pool test
o(updated[0].dom.nodeName).equals("DIV")
})
o("recycles deep", function() {
o("doesn't recycle deep", function() {
var vnodes = [{tag: "div", children: [{tag: "a", key: 1}]}]
var temp = [{tag: "div"}]
var updated = [{tag: "div", children: [{tag: "a", key: 1}]}]

render(root, vnodes)

var oldChild = vnodes[0].dom.firstChild

render(root, temp)
render(root, updated)

o(vnodes[0].dom.firstChild).equals(updated[0].dom.firstChild)
o(oldChild).notEquals(updated[0].dom.firstChild) // this used to be a recycling pool test
o(updated[0].dom.firstChild.nodeName).equals("A")
})
o("mixed unkeyed tags are not broken by recycle", function() {
Expand Down

0 comments on commit 203df39

Please sign in to comment.