Bug Tracker

Opened 13 years ago

Closed 12 years ago

Last modified 12 years ago

#6823 closed enhancement (fixed)

Make .val(value) faster for common use case

Reported by: RandomInsano Owned by:
Priority: low Milestone: 1.6
Component: attributes Version: 1.4.3
Keywords: perf Cc:
Blocked by: Blocking:

Description

I've built a web application that creates a few hundered forms with about six select boxes each in one page (~1200 elements).

Using the built-in functionality, it would take the creation function nearly 10 seconds to complete in Firefox 3.6. My fix for the problem was to get the direct node from jQuery, and set it's .value property. Now the page builds in < 1 second.

Before:

$(".UserName", formNode).val(1)

After:

$(".UserName", formNode)[0].value = 1;

Change History (3)

comment:1 Changed 13 years ago by dmethvin

Component: dataattributes

From the code I can see that it would be faster to assign to the value property for that specific case. The general .val() code can take an array of values so that it can set select-multiple elements. I wonder if it would work to special-case the situation where the element was a select-one and the passed value was not an array.

comment:2 Changed 13 years ago by snover

Keywords: perf added
Milestone: 1.4.3
Priority: low
Status: newopen
Summary: .val() calls are much slower than direct value manipulationMake .val(value) faster for common use case
Type: bugenhancement
Version: 1.4.21.4.3

comment:3 Changed 12 years ago by john

Milestone: 1.6
Resolution: fixed
Status: openclosed

This has been resolved in 1.6 (the code is much faster now). Although, in general, I would recommend just doing: .attr("value", someValue) if you know that you want to assign to the value attribute.

Note: See TracTickets for help on using tickets.