Walters (https://github.com/wmeissner/walters) is a jruby extension
optimised for fast html/xml/uri/url/href escaping. It originally
started as a Houdini wrapper to test XNI, but then I ported the
Houdini C code to java so JRuby would have a pure java implementation
(which makes it a lot easier to deploy in a WAR). It was named for
Norman Murray Walters, an Australian contemporary of Houdini’s.
The performance delta isn’t as impressive as Houdini/EscapeUtils is
for MRI, because JRuby has hotspot to do the heavy lifting, but you
still end up with at least a 3x speedup.
Escaping 1000 bytes of text requiring escaping 1000000 times under
Rack::Utils.escape_html 89.980000 0.230000 90.210000 ( 90.272000)
Haml::Helpers.html_escape 50.420000 0.170000 50.590000 ( 51.147000)
ERB::Util.html_escape 44.650000 0.130000 44.780000 ( 45.518000)
CGI.escapeHTML 36.230000 0.090000 36.320000 ( 36.358000)
String#gsub 35.490000 0.090000 35.580000 ( 35.587000)
Walters.escape_html 10.090000 0.030000 10.120000 ( 10.126000)
That equates to not quite 100MB/sec on a 2.26ghz core2duo. If your
web app is trying to push more than that through a 5 year old cpu, you
probably have other problems
You can also monkey patch any of the above methods (see the README) to
use Walters.escape_html, so you can get automagical speedups just with
a few lines in a rails initializer.