Ticket #7156 (closed enhancement: duplicate)
html can be ~33% faster
| Reported by: | markg85 | Owned by: | |
|---|---|---|---|
| Priority: | low | Milestone: | |
| Component: | manipulation | Version: | 1.4.2 |
| Keywords: | html | Cc: | |
| Blocking: | Blocked by: |
Description (last modified by snover) (diff)
Hi,
I was playing a bit with the jquery source (1.4.3 RC1) and found that the "html:" function can be ~33% faster simply by removing the "shortcut" option...
here is the code part that i have now and is a consistently faster from 37ms to 21ms:
html: function( value ) {
if ( value === undefined ) {
return this[0] && this[0].nodeType === 1 ?
this[0].innerHTML.replace(rinlinejQuery, "") :
null;
} else if ( jQuery.isFunction( value ) ) {
this.each(function(i){
var self = jQuery(this);
self.html( value.call(this, i, self.html()) );
});
} else {
this.empty().append( value );
}
return this;
},
Apparently something in the "shortcut" path was draining cycles?
Regards, Mark
Change History
comment:1 Changed 3 years ago by addyosmani
- Keywords html added
- Type changed from bug to enhancement
comment:2 Changed 3 years ago by snover
- Priority changed from undecided to low
- Status changed from new to open
- Component changed from unfiled to manipulation
- Description modified (diff)
The more complex the HTML, the faster the “shortcut” method should be. How complex is the HTML that you are testing here?
comment:3 Changed 3 years ago by markg85
I actually tested this with the "taskspeed" benchmarking tool. I didn't add/change any text.. it's just that tool only with those lines removed.
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Two other people have suggested this idea quite recently but I'm currently trying to track down the tickets so we can reference them.
I'll see if I can find out why we're specifically using 'shortcut' in the above and follow up.
Moving to enhancements for now.