Skip to main content

Bug Tracker

Side navigation

#6823 closed enhancement (fixed)

Opened July 23, 2010 03:35PM UTC

Closed April 16, 2011 03:56PM UTC

Last modified March 09, 2012 02:44AM UTC

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;

Attachments (0)
Change History (3)

Changed July 24, 2010 02:47AM UTC by dmethvin comment:1

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.

Changed October 31, 2010 01:33AM UTC by snover comment:2

keywords: → perf
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

Changed April 16, 2011 03:56PM UTC by john comment:3

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.