Bug Tracker

Opened 11 years ago

Closed 11 years ago

Last modified 11 years ago

#2550 closed enhancement (fixed)

Try removing with() from offset.

Reported by: flesler Owned by: brandon
Priority: minor Milestone: 1.2.4
Component: offset Version: 1.2.3
Keywords: offset with Cc:
Blocked by: Blocking:

Description

Maybe, removing the with() call from offset() can improve its perfomance. The saving in bytes is really small, so if it does hit on perfomance, then it might be better to remove it.

Attachments (3)

offset.diff (2.3 KB) - added by flesler 11 years ago.
with() removed, jQuery browser is cached into a variable
offset-curCSS-getComp.diff (3.5 KB) - added by flesler 11 years ago.
Replacing css for curCSS inside offset, caching getComputedStyle
test.js (406 bytes) - added by flesler 11 years ago.
File to run the tests

Download all attachments as: .zip

Change History (6)

Changed 11 years ago by flesler

Attachment: offset.diff added

with() removed, jQuery browser is cached into a variable

Changed 11 years ago by flesler

Attachment: offset-curCSS-getComp.diff added

Replacing css for curCSS inside offset, caching getComputedStyle

comment:1 Changed 11 years ago by flesler

I made some real tests, the with() didn't seem to matter much. I tried replacing jQuery.css for jQuery.curCSS because that was a useless call. The time got lower and saved many calls. Then cached document.defaultView && document.defaultView.getComputedStyle in a var, and that reduced the time. I tried all this many many times back and forth to discard CPU interferences. The element that I called offset on, had 7 parents, and then the body. The latter was its third offsetParent.

Regular

Profile (21359.375ms, 186011 calls)
offset(500 times) - attempt 1: 5359ms test.js (line 17)
offset(500 times) - attempt 2: 5406ms test.js (line 17)
offset(500 times) - attempt 3: 5359ms test.js (line 17)
offset(500 times) - attempt 4: 5297ms

curCSS 4 css 

Profile (20296.875ms, 148011 calls)
offset(500 times) - attempt 1: 5093ms test.js (line 17)
offset(500 times) - attempt 2: 5000ms test.js (line 17)
offset(500 times) - attempt 3: 5109ms test.js (line 17)
offset(500 times) - attempt 4: 5109ms

curCSS 4 css, defaultView cached

Profile (16203.125ms, 148011 calls)
offset(500 times) - attempt 1: 3984ms test.js (line 17)
offset(500 times) - attempt 2: 3969ms test.js (line 17)
offset(500 times) - attempt 3: 4078ms test.js (line 17)
offset(500 times) - attempt 4: 4203ms

Changed 11 years ago by flesler

Attachment: test.js added

File to run the tests

comment:2 Changed 11 years ago by brandon

Resolution: fixed
Status: newclosed

Patch applied in [5274] and [5275].

comment:3 Changed 11 years ago by flesler

Added some modifications to this at [5609].

Note: See TracTickets for help on using tickets.