Bug Tracker

Ticket #6823 (closed enhancement: fixed)

Opened 4 years ago

Last modified 3 years ago

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:
Blocking: Blocked by:

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

comment:1 Changed 4 years ago by dmethvin

  • Component changed from data to attributes

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 4 years ago by snover

  • Status changed from new to open
  • Summary changed from .val() calls are much slower than direct value manipulation to Make .val(value) faster for common use case
  • Priority set to low
  • Version changed from 1.4.2 to 1.4.3
  • Milestone 1.4.3 deleted
  • Keywords perf added
  • Type changed from bug to enhancement

comment:3 Changed 4 years ago by john

  • Status changed from open to closed
  • Resolution set to fixed
  • Milestone set to 1.6

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.