-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Faster generation of Symbols, Fixnums, and Hashes
This improves the JSON generation speed of Symbols, Fixnums, and Hashes. Symbols are made faster by checking for T_SYMBOL and calling rb_sym2str instead of calling Symbol#to_s. This avoids a string allocation and a method lookup. Fixnums are made faster by writing our own simple itoa (to a buffer). This avoids a string allocation, method lookup, and might be a tiny bit faster since the radix is hardcoded. Hashes are improved by avoiding calling to_s on the keys when we have a String or Symbol, and calling rb_hash_foreach instead of iterating over keys and using rb_hash_aref. In my quick test this was approximately 30% faster.
- Loading branch information
Showing
4 changed files
with
87 additions
and
13 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
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