Fixes #10515 - Implementation of iAH #1200
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Based on @dmethvin idea.
By opening this PR, i want, one way or another, to close #10515, but i'm not sure what a resolution of that ticket should be.
Perf tests
jQuery.append
jQuery.prepend
jQuery.before
jQuery.after
What's the takeaway?
This is a difference between
iAH
methods and current DOM-manipulation tactics –jQuery#append/prepend
, big/small HTML-string, disconnected elementjQuery#before/after
, big HTML-string, disconnected elementjQuery#before/after
, small HTML-string, disconnected elementPerf hit
In some situations
insertAdjacentHTML
method could not be applied, guards for that cases will slow downjQuery#domManip
method –iAH
is eitherbeforebegin
orafterend
(affectjQuery#before/after
),insertAdjacentHTML
could not be applied if target element does not have parent element (obviously) or that element is document fragment (less obvious), althoughiAH
could be used if first argument isafterbegin
orbeforeend
(jQuery#append/prepend
) for such an element, but it would reguire additional check insidefor
loop. Perf hit forjQuery#append/prepend
methods applied to parentless element would be:jQuery#append
– big/small HTML-stringjQuery#prepend
– big/small HTML-stringtable
element throughinsertAdjacentHTML
method, plus in other browsers, that code path perform worse then current way. Perf hit for bypassingtable
element as target node would be – http://jsperf.com/iah-to-table/3tr
element, in such case ifinsertAdjacentHTML
is not applied totable
element that code would silently fail, therefore for that casesiAH
path must not be taken, perf hit will be the same as for abovetable
exampleiAH
could not takeobject
as an argument. Perf hit by circumventingobject
as an argument would be – http://jsperf.com/jq-iah-append-objectdocument fragment
(and all other types of an node) does not haveinsertAdjacentHTML
method, alsoscript
element should not be inserted that way. Perf hit for that cases would be – http://jsperf.com/jq-iah-append-to-documentfragmentAs conclusion
Performance ratio of WebKit
iAH
in case of big HTML-string relative to current DOM-manipulation way is utterly depressing, one might even suggest that this happens due to regexp check, but it's not the case – in that version of aiAH
implementation regexp check is removed, which does not heavily change the picture. Solution for that problem might be size check of HTML-string.Use of
jQuery#append
as an example of that idea – big/small HTML-string. This control is flatten disproportion in WebKit case, but it also decrease performance in other browsers.I suppose big HTML-string is rarely acts as argument in jQuery's DOM-manipulation methods, maybe only in case when whole page should be reflowed, besides, 184 operation per second might be fast enough for that task, ergo it might be more productive to dwell on more optimistic small HTML-string's cases, given the idea that if whether or not
iAH
should be employed was made only by proceeding outcome most of other samples then decision would be little more obvious? As of perf hit examples (see above) – some of them are rare edge cases, some of them do not matter that much and some of them aren't that conclusive.But considering all that, i'd say this research is showed a lot of arguments to not use
iAH
inside ofjQuery#domManip
at all.