-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
#7662 Make StringBiValue safe against mutations to the underlying RubyString #7663
Conversation
Interesting, I wasn't aware mutating the ruby string wouldn't cause the java one to mutate too. I guess that, like you said, we were working around it doing extra .dups and .clones. the code LGTM and I tested manually too, maybe @guyboertje can pitch in wrt to any impediment to have this merged? |
@jsvd yea this is a nasty one, unlike other Ruby types, |
@guyboertje ping (just in case this was forgotten :)) |
I have been looking for a mechanism to tell if the RubyString has been modified since it was set (from within the javaValue method) but alas there does not seem to be. Also, any form of comparison would probably be less performant than creating a new Java String each time its requested. Further, bear in mind that we have advised/documented that in place mutation of any Event value is not supported and that a get, modify and re-set strategy is the way to go. This is mainly to prevent invalidating the accessor path cache - e.g. in place replacement of an inner part of the tree with a leaf |
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.
LGTM
@guyboertje thanks for looking through this!
Yea sadly enough there doesn't seem to be any fast way of doing this (apart from simply offering a super fast Java API that returns the |
…ying RubyString
(had to rebase, didn't merge clean into |
@original-brownbear - Suggested on JRuby IRC, perhaps use |
Fixes #7662
Since
org.jruby.RubyString
is mutable we simply cannot cache itsString
representation, as much as this seems to hurts performance wise.In actuality there is no performance gain anyways since we're forced to
.dup
strings whenever we have shared Java and Ruby logic like in the UA filter:https://github.com/logstash-plugins/logstash-filter-useragent/blob/master/lib/logstash/filters/useragent.rb#L138
With this fix, we get consistency by simply computing the Java object on demand. The theoretical performance hit (in practice it seems this actually speeds up the Apache dataset, likely as a result of the
String
objects now living for a shorter time and hence being collected easier) we can completely alleviate in real life use cases, by removing the.dup
calls from plugins like the above.