forked from rails/rails
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve performance of JSON HTML entity escaping
Running gsub! 5 times with string arguments seems to be faster than running it once with a regex and Hash. When there are matches to the regex (there are characters to escape) this is faster in part because CRuby will allocate a new match object and string as a key to lookup in the map hash provided. It's possible that could be optimized upstream, but at the moment this avoids those allocations. Surprisingly (at least to me) this is still much faster when there is no replacement needed: in my test ~3x faster on a short ~200 byte string, and ~5x faster on a pre-escaped ~600k twitter.json.
- Loading branch information
Showing
3 changed files
with
23 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters