This project is archived and is in readonly mode.

#3181 ✓committed
Beau Harrington

[PATCH] ActiveSupport::Multibyte.clean is very slow

Reported by Beau Harrington | September 10th, 2009 @ 06:32 AM

The addition of a call to ActiveSupport::Multibyte#clean in ActionView::Helpers::TagHelper.escape_once in the recent security patch and 2.4.3 (9a68c72b4 and its parent) has led to a substantial increase in CPU usage on our servers.

Running each specified through a valid-character regexp is obviously expensive, but the patch can be improved somewhat by making a small tweak to ActiveSupport::Multibyte#clean and ActiveSupport::Multibyte#verify.

For 10000 runs on a 90 character string on my MacBook Pro:

                          user     system      total        real
clean-orig            9.760000   2.220000  11.980000 ( 12.030811)
clean-patched         6.230000   1.480000   7.710000 (  7.734848)

                      user     system      total        real

verify-orig 9.360000 2.240000 11.600000 ( 11.697971) verify-patched 5.970000 1.510000 7.480000 ( 7.529034)

I've attached the patch, tests pass.

Comments and changes to this ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href=""></a>