From: eregontp@... Date: 2021-01-29T12:28:32+00:00 Subject: [ruby-core:102299] [Ruby master Feature#12607] Ruby needs an atomic integer Issue #12607 has been updated by Eregon (Benoit Daloze). ko1 (Koichi Sasada) wrote in #note-36: > But (I didn't measured yet) increment method call on VM needs method invocation overhead and it is relatively higher than `TVar#increment` overhead. Again, I didn't measure and it can be wrong. Why would the invocation of AtomicInteger#increment be more expensive than the invocation of TVar#increment? They are both method calls, and TVar doesn't doesn't use `Primitive` since it is a separate gem (currently at least). In general, method calls have no cost when inlined with a JIT that can see through the core library, e.g. on TruffleRuby, or I think with MJIT and leaf annotated methods, so I think for best performance AtomicInteger#increment is a clear winner. ---------------------------------------- Feature #12607: Ruby needs an atomic integer https://bugs.ruby-lang.org/issues/12607#change-90154 * Author: shyouhei (Shyouhei Urabe) * Status: Feedback * Priority: Normal * Assignee: ko1 (Koichi Sasada) ---------------------------------------- (This one was derived from bug #12463) Although I don't think += would become atomic, at the same time I understand Rodrigo's needs of _easier_ counter variable that resists inter-thread tampering. I don't think ruby's Integer class can be used for that purpose for reasons (mainly because it is not designed with threads in mind). Rather we should introduce a integer class which is carefully designed. Why not import Concurrent::AtomicFixnum into core? -- https://bugs.ruby-lang.org/ Unsubscribe: