Bug Tracker

Opened 14 years ago

Closed 14 years ago

#4036 closed bug (fixed)

Important performance improvement

Reported by: dimi Owned by:
Priority: major Milestone: 1.3.2
Component: core Version: 1.3.1
Keywords: performance Cc: dimi@…
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.diff (727 bytes) - added by dimi 14 years ago.
Patch implementing the .blank() function.
blank-1.diff (730 bytes) - added by dimi 14 years ago.
Smaller, much faster version of .blank()

Download all attachments as: .zip

Change History (4)

Changed 14 years ago by dimi

Attachment: blank.diff added

Patch implementing the .blank() function.

Changed 14 years ago by dimi

Attachment: blank-1.diff added

Smaller, much faster version of .blank()

comment:1 Changed 14 years ago by dimi

Read all about it here: http://zipalong.com/blog/?p=287

comment:2 Changed 14 years ago by john

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.

Note: See TracTickets for help on using tickets.