Repository navigation
Centralize internal reference counting logic - #8614
Conversation
|
Can one of the admins verify this patch? |
|
@netty-bot test this please |
|
@njhill I'm running AbstractReferenceCountedByteBufBenchmark pre/post this PR to check a "couple" of guesses related some performance impacts (and futher improvements) on JDK 8.
Let me know if you have already checked/evaluated some of them, you will save my machine to be on fire :P |
|
Thanks @franz1981, much appreciated! I wasn't sure the change would be desirable even without unanticipated performance implications. I didn't have a chance to do any meaningful benchmarks yet and maybe should have done prior to opening this; would be great if you have some comparisons already in progress. Re (1) using the updater for volatile loads is already done in the current version (although that was only changed recently) and was part of what motivated this refactor. If there are measurable advantages to direct access then maybe it's a showstopper. Re (3) I'd been hoping that since everything is still static and/or final that there wouldn't be a cost to extracting the logic from an inlining pov, but after reading the great article you referenced I see that's likely not the case given the introduction of non-static and therefore non-trusted finals. A possible workaround for this could be to move the |
|
Sadly I wasn't able to get some meaningful number yet :( On release: A similar picture is on the uncontended side: I'm not getting why I have such noisy numbers with no contention TBH.
True, but just having a single code that manage all the complex logic here means to have (ideally) just one unit test to be maintained, that's good per-se. Even if we can't rely on any object-oriented way to reuse the code I suppose that's a win. Re the perf I would wait some results, because in my experience when xadd or cmpxchg are involved (and are unavoidable), the biggest wins (and looses) are just due to them. Considering the article I have pointed, Alexey is focusing on a primitive usage of atomicXXX while on Netty I suppose that people will do something with the buffer whilst retain/release it and it could mean that having an additional null-check probably won't make a big difference here (just guessing). |
|
I think as long as the performance does not suffer we should pull this in... @njhill @franz1981 any updates here ? |
|
@normanmaurer thanks for the tentative approval and apologies for the delay. I haven't had a chance to dedicate time on my machine to running more benchmarks. Hopefully this isn't too urgent, I'll update as soon as I've managed to do more additional perf verification. |
|
@normanmaurer Apologies for the delay by me as well: haven't had enough time to run other benchs. Will try to do it ASAP :) |
|
@njhill @franz1981 thanks a lot! |
|
Here's some benchmarks, the |
Probably runinng the bench with the larger difference in perf using the LinuxPefAsmProfiler would help to check on the ASM if are performed extra checks due to the non-trusted finals (I could try to help on it with my limited knowledge of ASM) I suppose that the way to "fix" this using some static utility methods is the safer-way perf-wise: nontheless I have very noisy results from this bench (on 4.1 too) so I'm not 100% sure of it |
|
@njhill @normanmaurer Probably OT, but wdyt about finding a way (who said Netty 5?) to handle the usually common case where a ByteBuf life-cycle is bound exclusively to a single thread? |
|
@njhill @franz1981 what do we want to do with this one ? |
|
@normanmaurer I'm not super excited about it given the not-quite-negligible performance degradation and fact that it will make call stacks longer, but let me do a last refactor to see how convoluted it looks when non-static finals are avoided . |
|
👍
… Am 01.03.2019 um 04:15 schrieb Nick Hill ***@***.***>:
@normanmaurer I'm not super excited about it given the not-quite-negligible performance degradation and fact that it will make call stacks longer, but let me do a last refactor to see how convoluted it looks when non-static finals are avoided .
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
|
@normanmaurer @franz1981 I have reworked it slightly to avoid non-trusted finals and verified this closes the performance gap, PTAL. It's not as messy as I had expected so I'm now back on the side of thinking that the change is worthwhile. We can take the simplification even further with java 8 default methods (could do a follow-on for netty 5). |
|
@njhill nice one! I really like how it reduces code-duplication. |
normanmaurer
left a comment
There was a problem hiding this comment.
I really like this a lot!
franz1981
left a comment
There was a problem hiding this comment.
LGTM! Have u tried some bench right?
The code reduction is already a selling point for me ;)
|
@franz1981 as far as I understood @njhill said its the same speed.... |
|
@franz1981 yes, I confirmed the prior suspicion that it was use of non-trusted finals that caused a small perf regression before, and also confirmed that the latest change eliminates that. This also includes some minor tweaks to favour most common cases (inc/dec count == 1 and ref count == 1 or 2), and IIRC looked like there might even be a slight improvement in the numbers. |
|
Yep I was expecting a slight improvement too :) well done!!! |
|
Thanks @franz1981 I learnt some useful things from you in the process! |
Motivation AbstractReferenceCounted and AbstractReferenceCountedByteBuf contain duplicate logic for managing the volatile refcount in an optimized and consistent manner, which increased in complexity in netty#8583. It's possible to extract this into a common helper class now that all access is via an AtomicIntegerFieldUpdater. Modifications - Move duplicate logic into a shared ReferenceCountUpdater class - Incorporate some additional simplification for the most common single increment/decrement cases (fewer checks/operations) Result Less code duplication, better encapsulation of the "non-trivial" internal volatile refcount manipulation
|
@normanmaurer done! I also renamed a method for consistency, and tidied some comments. |
|
@netty-bot test this please |
|
@njhill thanks a lot! |
Motivation AbstractReferenceCounted and AbstractReferenceCountedByteBuf contain duplicate logic for managing the volatile refcount in an optimized and consistent manner, which increased in complexity in #8583. It's possible to extract this into a common helper class now that all access is via an AtomicIntegerFieldUpdater. Modifications - Move duplicate logic into a shared ReferenceCountUpdater class - Incorporate some additional simplification for the most common single increment/decrement cases (fewer checks/operations) Result Less code duplication, better encapsulation of the "non-trivial" internal volatile refcount manipulation
Motivation
AbstractReferenceCountedandAbstractReferenceCountedByteBufcontain duplicate logic for managing the volatile refcount in an optimized and consistent manner, which increased in complexity in #8583. It's possible to extract this into a common helper class now that all access is via anAtomicIntegerFieldUpdater.Modifications
ReferenceCountUpdaterclassResult
Less code duplication, better encapsulation of the "non-trivial" internal volatile refcount manipulation.