Conversation
Member
Author
|
I should have GC'd first, but luckily the percent savings are about the same so I'll update the commit message: |
Member
Author
|
bump / @flori |
f458204 to
f1795d9
Compare
Member
Author
|
@flori I've rebased this against master and separated the .rl file change from the generated parser change. How can I help get this merged? |
The parser uses `rb_str_buf_new` to allocate new strings. `rb_str_buf_new` [has a minimum size of 128 and is not an embedded string](https://github.com/ruby/ruby/blob/9949407fd90c1c5bfe332141c75db995a9b867aa/string.c#L1119-L1135). This causes applications that parse JS to allocate extra memory when parsing short strings. For a real-world example, we can use the mime-types gem. The mime-types gem stores all mime types inside a JSON file and parses them when you require the gem. Here is a sample program: ```ruby require 'objspace' require 'mime-types' GC.start GC.start p ObjectSpace.memsize_of_all String ``` The example program loads the mime-types gem and outputs the total space used by all strings. Here are the results of the program before and after this patch: ** Before ** ``` [aaron@TC json (memuse)]$ ruby test.rb 5497494 [aaron@TC json (memuse)]$ ``` ** After ** ``` [aaron@TC json (memuse)]$ ruby -I lib:ext test.rb 3335862 [aaron@TC json (memuse)]$ ``` This change results in a ~40% reduction of memory use for strings in the mime-types gem. Thanks @matthewd for finding the problem, and @nobu for the patch!
Member
Author
|
@flori I've rebased this against master again. How can I help get this merged? Is there something more I need to do? Thanks. |
1 task
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The parser uses
rb_str_buf_newto allocate new strings.rb_str_buf_newhas a minimum size of 128 and is not an embeddedstring. This causes applications that parse JS to allocate extra memory when parsing short strings.
For a real-world example, we can use the mime-types gem. The mime-types
gem stores all mime types inside a JSON file and parses them when you
require the gem.
Here is a sample program:
The example program loads the mime-types gem and outputs the total space
used by all strings. Here are the results of the program before and
after this patch:
** Before **
** After **
This change results in a ~40% reduction of memory use for strings in the
mime-types gem.
Thanks @matthewd for finding the problem, and @nobu for the patch!