Ticket #8909 (closed enhancement: fixed)
$(element).data() will scan all attributes more than needed.
| Reported by: | gnarf | Owned by: | gnarf |
|---|---|---|---|
| Priority: | blocker | Milestone: | 1.7 |
| Component: | data | Version: | 1.5.2 |
| Keywords: | 1.7-discuss | Cc: | |
| Blocking: | Blocked by: |
Description
If you make more than one call to $(element).data() you end up having to loop over the attributes of the element looking for "data-" attributes every time you access it. I'd like to propose adding a simple flag in our private _data() that can stop us from having to check more than once...
Change History
comment:2 Changed 2 years ago by timmywil
- Status changed from new to open
- Type changed from bug to enhancement
- Component changed from unfiled to data
comment:4 Changed 2 years ago by john
- Keywords 1.7-discuss added
Nominating ticket for 1.7 discussion.
comment:6 Changed 2 years ago by rwaldron
+1, If I'm reading correctly, this seems to be a performance boost
comment:10 Changed 2 years ago by ajpiano
+1, Anything we can do to improve the perf of $(element).data("yesplease!")
comment:11 Changed 2 years ago by dmethvin
- Priority changed from undecided to blocker
- Milestone changed from 1.next to 1.7
comment:12 Changed 21 months ago by gnarf
Updated the pull request in comment #1 - http://jsperf.com/internal-data/3 has some perf data
comment:13 Changed 21 months ago by Corey Frang
- Status changed from assigned to closed
- Resolution set to fixed
Landing pull request 503. 1.7 data: set a flag in the private data cache to avoid having to scan attributes multiple times - Fixes #8909.
More Details:
Please follow the bug reporting guidlines and use jsFiddle when providing test cases and demonstrations instead of pasting the code in the ticket.

https://github.com/jquery/jquery/pull/503