Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #6937 (closed enhancement: fixed)

Opened 2 years ago

Last modified 1 year ago

[PATCH] String.escapeHTML optimization

Reported by: altblue Assigned to: sam
Priority: normal Milestone: 1.x
Component: Prototype Version:
Severity: normal Keywords:
Cc:

Description

As a result of the SAU/Prototype performance thread, here comes an enhanced version of our String.escapeHTML that caches created nodes (both the DIV and the textNode).

Testbed is available here: http://gfx.neohub.com/benchmark/t/escapeHTML.html

Here are the consolidated results:

Benchmarks run using 10000 iterations on these browsers:
A. Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.1) Gecko/20061222 Firefox/2.0.0.1
B. Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1
C. Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.8.1) Gecko/20061010 Firefox/2.0
D. Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.1) Gecko/20061204 Firefox/2.0.0.1
E. Opera/9.10 (X11; Linux i686; U; en)
F. Opera/9.10 (Windows NT 5.1; U; en)
G. Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 2.0.50727; FDM)
H. Mozilla/4.0 (compatible; MSIE 6.0; Windows 98)
I. Mozilla/5.0 (Macintosh; U; PPC Mac OS X; en) AppleWebKit/312.8.1 (KHTML, like Gecko) Safari/312.6
J. Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en) AppleWebKit/418 (KHTML, like Gecko) Safari/417.9.2
K. Mozilla/5.0 (compatible; Konqueror/3.5; Linux) KHTML/3.5.5 (like Gecko)

Method execution rate (per second) per browser:
           Method       AVG      A      B      C      D      E      F      G      H      I      J      K
Prototype.oneDiv2  23247.64   8170  14881   6588  16667  51020  72464  13405  10953  13477  39841   8258
     String.split  15701.09  10163  14164   6954  17241  27322  42553   9681  10373   1730  27548   4983
   String.replace  12587.09  15175   8418  10526  32051   6739   7210  15699  15949   1604  20619   4468
String.replaceMap  10634.55   8905   8540   6540  15221   9699   8772  12804  16584   1694  24213   4008
        Prototype   8887.82   3197   5666   3162   8803  17094  19305   4182   4704   3598  24096   3959
 Prototype.oneDiv   8098.36   2548   4292   1826   6017  16529  16892   5005   5283   5851  20833   4006

TOP method:
           Method    AVG   A   B   C   D   E   F   G   H   I   J   K
Prototype.oneDiv2   1.91   4   1   3   3   1   1   2   3   1   1   1
     String.split   2.55   2   2   2   2   2   2   4   4   4   2   2
   String.replace   3.36   1   4   1   1   6   6   1   2   6   6   3
String.replaceMap   3.64   3   3   4   4   5   5   3   1   5   3   4
        Prototype   4.64   5   5   5   5   3   3   6   6   3   4   6
 Prototype.oneDiv   4.91   6   6   6   6   4   4   5   5   2   5   5

Attachments

escapeHTML-optimization-rev5871.diff (0.8 kB) - added by altblue on 01/07/07 10:06:01.

Change History

01/07/07 10:06:01 changed by altblue

  • attachment escapeHTML-optimization-rev5871.diff added.

01/27/07 18:33:04 changed by sam

  • status changed from new to closed.
  • resolution set to fixed.

(In [6046]) prototype: Improve performance of String.prototype.escapeHTML by using a cached div and text node. Closes #6937.