-
Notifications
You must be signed in to change notification settings - Fork 20.6k
Data: move element cache to element[expando] #1428
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Ya know, this just might work. I'm thinking with this in place we may be able (in a separate commit) to optimize |
Rebased (waiting on travis at the moment) |
This is failing many tests in manipulation now |
Fixed issues with manipulation, these were caused by changes that didn't carry over after rebasing. |
@@ -167,12 +157,12 @@ Data.prototype = { | |||
}, | |||
hasData: function( owner ) { | |||
return !jQuery.isEmptyObject( | |||
this.cache[ owner[ this.expando ] ] || {} | |||
owner[ this.expando ] || {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than doing this, we should do something like
return this.expando in owner && !jQuery.isEmptyObject( owner[this.expando] );
Which avoids needlessly creating an empty object if the cache didn't exist on the element
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation is written to match the semantics of 1.x data; the object has no bindings and therefore no references to keep it in memory. Is there a real memory threat that exceeds the cost of using an in
operation?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In jquery/jquery-ui#1309 I'm trying to get them to use $.hasData
in the pseudo selectors that they've created in order to avoid potential memory leaks on sets containing detached nodes. Assuming that's accepted, this would avoid creating N objects where N is the # of DOM nodes that do not not currently have data in the case that you do something like $( this ).find( ":ui-spinner" );
If there's concern about the cost of the in
operator, you could also do
var cache = owner[ this.expando ];
return !!cache && !jQuery.isEmptyObject( cache );
which has no additional cost since both the old and new implementations both have a single property access in them.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, thanks for the reality check.
7989bab
to
9e7fd6c
Compare
Closes jquerygh-1668 Fixes jquerygh-1728 Ref jquerygh-1734 Ref jquerygh-1428
@rwaldron Could you resolve the conflicts. I think this is ready after that. |
9e7fd6c
to
5d001b4
Compare
5d001b4
to
812d99d
Compare
- avoid explicit data.discard() cleanup calls - explicitly remove the data.events property, only when private data exists - reduces code footprint Fixes #11570 Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
812d99d
to
880fdb7
Compare
|
You're right. @rwaldron was this intentional or is it alright to change back? |
Fixes #1734