-
Notifications
You must be signed in to change notification settings - Fork 331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement a freeze: parser option #447
Conversation
de7693a
to
94e4064
Compare
cc @marcandre @tenderlove could I interest one of you into this feature? |
94e4064
to
c9bbb5f
Compare
I went ahead and implemented it anyway. It wasn't that complicated actually. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Looks like a very useful addition to me 👍
Thanks @marcandre. cc @hsbt is this something you could consider merging? |
b0255ee
to
3a56c08
Compare
If set to true all parsed objects will be immediately frozen, and strings will be deduplicated if the Ruby implementation allows it.
3a56c08
to
9bf8aa2
Compare
It should be good to go now. CI is green. |
@hsbt anything else you'd like changed? |
If set to true all parsed objects will be immediately frozen, and strings will be deduplicated if the Ruby implementation allows it.
This option is useful if you plan to keep the parsed objects around, and want to reduce their memory footprint, and you know they contain duplicated string. It's common in says I18n data, or some database like configuration files (e.g. tax rates etc).
A similar option was added to YAML/Pysch: ruby/psych#414
MessagePack is also about to have it: msgpack/msgpack-ruby#194 (at least the principle was accepted).
Right now this option incur a small overhead because it has to call
String#-@
throughrb_funcall
, but hopefully Ruby 3.0 should soon exposerb_fstring_new(const char *ptr, long len) (likely under another name)
which should allow to reduce allocations by directly looking up existing strings without allocating a new one.NB: I presume that a java implementation is needed, I'm not too well versed into Java by I can try my hand at it. However I'd rather have your feedback on the MRI and "pure" implementations first.