Skip to main content

Bug Tracker

Side navigation

#4036 closed bug (fixed)

Opened February 01, 2009 08:11AM UTC

Closed February 09, 2009 03:35PM UTC

Important performance improvement

Reported by: dimi Owned by:
Priority: major Milestone: 1.3.2
Component: core Version: 1.3.1
Keywords: performance Cc: dimi@lattica.com
Blocked by: Blocking:
Description

While investigating poor .trim() performance, I discovered that there are only 2 places in core where trim() is used.

One place only needs to test if a string is blank, which can be done a *lot* faster than trimming. As a result this current patch does the following:

  • adds a new .blank() function to core that test for empty string.
  • uses the new function where appropriate to eliminate the .trim() function.

In my tests with a 660K string I got the following numbers:

.trim() .blank()

FF2/Linux 2353ms 9ms

FF3/Windows 1571ms 8ms

At a very fundamental level .blank() is a much easier function to implement, does not require any memory allocation, and as a result I think it should be part of

the core so others can make use of it. Moreover it only

adds a tiny bit of code, basically just a few bytes.

That is, the minified code is only 47 bytes bigger. When gzipes, that drops to only 18bytes. This is a tiny price to pay for a >100x speedup in some cases.

Attachments (2)
  • blank-1.diff (0.7 KB) - added by dimi February 01, 2009 04:15PM UTC.

    Smaller, much faster version of .blank()

  • blank.diff (0.7 KB) - added by dimi February 01, 2009 08:12AM UTC.

    Patch implementing the .blank() function.

Change History (2)

Changed February 01, 2009 04:16PM UTC by dimi comment:1

Read all about it here:

http://zipalong.com/blog/?p=287

Changed February 09, 2009 03:35PM UTC by john comment:2

resolution: → fixed
status: newclosed

Fixed in SVN rev [6189]. I didn't add the .blank() method - that's something that we can explore later on.