Ticket #12269 (closed bug: wontfix)
width() and height() significantly slower in 1.8 in WebKit browsers
| Reported by: | twadzilla | Owned by: | mikesherov |
|---|---|---|---|
| Priority: | blocker | Milestone: | 1.8.1 |
| Component: | css | Version: | 1.8.0 |
| Keywords: | Cc: | ||
| Blocking: | Blocked by: |
Description
jQuery version: 1.8
Browsers affected: Chrome 21-23, Safari 5-6
Browsers not affected: IE, Firefox
Operating systems: Windows XP SP3, Windows 7 x64, Mac OS 10.7
Repro link: http://jsfiddle.net/jkvFN/
Expected result: when applying width() or height() over a large (500+) collection of elements, performance should be roughly equivalent to css().
Actual result: width() and height() perform several orders of magnitude slower than css() in 1.8.0 compared to 1.7.2. A trace in the timeline feature of Chrome seems to indicate a large number of layout/style recalculations happening in curCSS (line 6617).
Change History
comment:1 Changed 10 months ago by mikesherov
- Keywords needsdocs added
- Priority changed from undecided to high
- Status changed from new to closed
- Component changed from unfiled to css
- Resolution set to worksforme
comment:2 Changed 10 months ago by mikesherov
- Status changed from closed to reopened
- Resolution worksforme deleted
Actually, maybe I got it backwards here. Sorry for that.
comment:3 Changed 10 months ago by mikesherov
Yeah, this is interesting. I apologize for the hasty reply. I'm investigating now.
comment:4 Changed 10 months ago by mikesherov
Right, so, this is slower in every browser, but more noticeable in webkit. This is due to what I had originally mentioned. It's still true that I've actually sped up some code paths when box-sizing:border-box is true, but also, we've become more precise with .width() vs. .css('width').
Again, .width() accounts for which box-sizing model is being used, and .css('width') does not. As a consequence, we query the box-sizing property when using .width(), which is the cause of the slowdown. Use .css('width') if you'd like to avoid this.
I'll continue to investigate this in the mean time.
comment:5 Changed 9 months ago by mikesherov
- Owner set to mikesherov
- Priority changed from high to blocker
- Status changed from reopened to assigned
- Milestone changed from None to 1.8.1
comment:6 Changed 9 months ago by mikesherov
- Status changed from assigned to closed
- Resolution set to wontfix
We discussed this at length at the team meeting. We are keeping this behavior, as although it may be slower. If you are not using border-box, use .css('width'). If you need it to be content-width regardless of box-sizing, use .width().
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

Actually, you should be happy. Change your tests to use jquery 1.7.2, and you'll see just how slow the old methods were. In jquery 1.8, I've significantly sped up certain code paths. As well, .width() as a setter and .css('width') as a setter do different things. .wdith() sets content width, where as .css('width') sets the "width" attribute, which can be content-width if box-sizing is content box, or content-width plus padding plus border if box-sizing is border-box.
Adding needsdocs because we haven't properly publicized this change.