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)
Change History (4)
Changed 14 years ago by
Attachment: | blank.diff added |
---|
comment:2 Changed 14 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
Fixed in SVN rev [6189]. I didn't add the .blank() method - that's something that we can explore later on.
Patch implementing the .blank() function.