Hi!
A couple of days ago I landed two[1][2] patches to fix a seemingly
fairly trivial spec issue with setting of document.title. The bug[3] had
been simmering in the webkit bug tracker for a couple of years.
Yesterday I got copied on a performance regression[4] which indeed
sounded scary, so I started to look into it.
It turns out that my fix has made case 1 of
http://jsperf.com/setting-document-title
a magnitude slower by removing an optimization to reuse text node
children because not being allowed by the spec. I filed for a revert[5]
which are currently on the way in.
So when widening the scope a bit, how does other similar attributes work
in Blink? Take <node>.textContent, that do follow the spec by not
reusing nodes. Imagine we we had the same optimization for that?
In
http://jsperf.com/setting-element-textcontent
you roughly see the same magnitude difference between the two cases in
Google Chrome (I use 33.0.1736.3 dev) as we had *after* my patch for
document.title.
Adding the same optimization to .textContent makes it 10x faster when
just replacing a string with another string! And <node>.textContent
should be a lot more performance sensitive than document.title. (It
would break the spec and perhaps would have web compat problems and what
not...)
So one line of thinking is that if we can have the slow but correct
.textContent, we should be able to have the slow and correct
document.title? Or should we focus on trying to make stuff like
.textContent fast and "wrong" but redefine "wrong"? I don't know how
realistic that it though.
Thoughts on this?
David
[1]
https://codereview.chromium.org/107513013/ - Remove children of title node before updating
[2]
https://codereview.chromium.org/128603002/ - Inhibit title update when removing children before setting new value
[3]
https://bugs.webkit.org/show_bug.cgi?id=28864 - Setting document.title reuses <title>'s textnode child
[4]
https://code.google.com/p/chromium/issues/detail?id=331076 - 3%-9% regression in dom_perf/Total/score at 242107:242126
[5]
https://codereview.chromium.org/138213005/ - Revert "Remove children of title node before updating"