Skip to main content

Search and Top Navigation

#5756 closed enhancement (fixed)

Opened June 23, 2010 11:06AM UTC

Closed July 30, 2010 12:07PM UTC

Last modified November 19, 2010 06:26PM UTC

Widget: Use $.data instead of .data for performance reasons

Reported by: jzaefferer Owned by:
Priority: major Milestone: 1.8.3
Component: ui.widget Version: 1.8.2
Keywords: Cc:
Blocked by: Blocking:
Description

From http://forum.jquery.com/topic/please-try-not-use-element-data-in-widget:

The $(element).data() call is very expensive because it triggers setData/getData events, which in turn make some other .datat() calls. If the events are not needed, please use $.data(element, key, val) call which are much faster.


The jquery Widget has one expensive $(element).data() call on _createWidget:function(). This make creating hundreds of widget very slow. Please replace:
               this.element = $( element ).data( this.widgetName, this );
with
               this.element = $( element );
               $.data(element, this.widgetName, this );

Actually, many .data calls in the Widget use the $.data() form which is good.

But most such calls in the Draggable code use the evil $(this).data() call.

Someone should clean up all the other UI .js for the slow and unnecessary $(this).data() calls.

Setting the component to ui.widget for now, as optimizations in ui.widget, especially in the create method, affects everything.

Attachments (0)
Change History (5)

Changed July 20, 2010 12:39PM UTC by jzaefferer comment:1

The upcoming changeData event will likely make the problem worse: http://github.com/jquery/jquery/commit/2e10af143b7eafb7142524f6534a62aee1910bd1

Changed July 30, 2010 12:07PM UTC by jzaefferer comment:2

Fixed in b3940d2.

Created a new ticket for interactions: #5884.

Changed July 30, 2010 12:07PM UTC by jzaefferer comment:3

resolution: → fixed
status: newclosed

Changed August 04, 2010 01:24AM UTC by scottgonzalez comment:4

milestone: 1.91.8.3

Changed November 19, 2010 06:26PM UTC by jzaefferer comment:5

Replace element.data(...) with $.data(element, ...). Fixes #5756 - Widget: Use $.data instead of .data for performance reasons

Changeset: b3940d2f78dfcc37792ceb97e5659b78f156794c