-
Notifications
You must be signed in to change notification settings - Fork 419
Adds a JRuby optimized version of Concurrent::Atom #441
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
Conversation
require 'concurrent/concern/observable' | ||
require 'java' | ||
|
||
java_import 'java.util.concurrent.atomic.AtomicReference' |
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.
Out of curiosity, how big is the perf hit of using Concurrent::Reference versus the Java one?
@lucasallan Thank you very much for working on this. I'm having difficulty following the differences between the implementations. AFAICT the main difference is that the newer version simply uses |
@jdantonio This version is directly based on Clojure code[1], but I guess we should be using [1] - https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Atom.java |
I didn't look at the Clojure code before implementing this or Agent. I worked entirely from the documented behavior. I probably should have looked at the Clojure source. :-) If the implementation can be improved following that example I'm all for it, but can we improve it for the base implementation? Do we need a JRuby-specific version? |
If we build an implementation around I'll work on it during this week and let you know the results. |
@lucasallan Thank you! |
@jdantonio Results: JRuby Using
|
Thank you! |
Adds a JRuby optimized version of Concurrent::Atom
@lucasallan I very appreciate your contributions but this particular change is unsafe. The @State instance variable is not properly initialized. Generally speaking I think all of our abstractions should use synchronisation layer to avoid this type of problems. It also helps greatly to solve issues across the gem if one is found. I know the benchmark shows improvement but when the number of iterations is taken into-account it's not big gain. It's also best to avoid optimisations of a method inlining kind, that's a job for the Ruby interpreter. We should prefer code clarity and algorithmic optimisations. I would suggest to revert this change. |
@pitr-ch Could you clarify what you meant by |
Compiler or processor can reorder writes, in particular it may choose to reorder write to There is nothing bad about |
Fair enough. Thanks for the awesome explanation @pitr-ch - I'll revert it later today. |
Thanks @lucasallan. |
Non-optimized version
Optimized version
Benchmark script: