-
Notifications
You must be signed in to change notification settings - Fork 98
Replace Refcounted with std::shared_ptr #845
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
d4ea30b
to
9451968
Compare
@@ -258,7 +258,7 @@ void coldResumer(uint32_t port, uint32_t client_num) { | |||
} | |||
} | |||
|
|||
TEST(ColdResumptionTest, SuccessfulResumption) { | |||
TEST(ColdResumptionTest, DISABLED_SuccessfulResumption) { |
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.
This test was constantly flaking on me. Disabling until we can rootcause why it's flaky.
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.
Just a comment.
message("Compiler lacks support std::atomic<std::shared_ptr>; wrapping with a mutex") | ||
elseif(YARPL_WRAP_SHARED_IN_ATOMIC) | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DYARPL_WRAP_SHARED_IN_ATOMIC") | ||
message("Compiler lacks std::shared_ptr atomic overloads; wrapping in std::atomic") |
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.
What is the difference between this and the above? Both mention the same thing lacking but different workarounds?
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.
Newer compilers/libstdc++ have std::atomic_{exchange,load,store}
specialized for std::shared_ptr<T>
directly, so the std::atomic
structure never shows up. If that's not supported, the code falls back to wrapping an std::shared_ptr
in std::atomic
structure. If that isn't supported either (my local clang doesn't like it), it falls back further to locking with a mutex and shimming {exchange,load,store}
.
@@ -9,7 +9,7 @@ namespace flowable { | |||
|
|||
class Subscription : public virtual Refcounted { | |||
public: | |||
virtual ~Subscription() = default; | |||
// virtual ~Subscription() = default; |
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.
remove?
So what are the side effects that we see when we use shared_ptr? Did we see any memory usage increase etc as @vjn mentioning? Is it possible to get some numbers that you can put to a potential post that declares replacing refcounted with shared_ptr? We can test this at the Presence Service and Ads Canary. They provide good stats. |
Added benchmark numbers, @phoad. Looks like a perf win (or at least no regression). 1 word of overhead per object likely won't show up much, so extra word will just consume padding when that happens? either that or, more likely, shared_ptr is just more optimized by the compiler/stdlib. |
@@ -156,10 +156,35 @@ set(GMOCK_LIBS | |||
set(CMAKE_CXX_STANDARD 14) | |||
|
|||
# Common configuration for all build modes. | |||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++14") |
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.
Huh, I'm surprised we didn't already have this, but sure, makes sense.
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.
I think this parameter is coming down from travis. Do we need to explicitly set it in cmake?
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -pedantic") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Woverloaded-virtual") | ||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g") | ||
|
||
# does the compiler support std::atomic_load(&std::shared_ptr<T>) ? | ||
try_compile(HAS_NATIVE_ATOMIC_SHARED_PTR ${CMAKE_BINARY_DIR}/has_shared_ptr_support_rs | ||
${CMAKE_CURRENT_SOURCE_DIR}/yarpl/test/test_has_shared_ptr_support.cpp) |
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.
You could use https://cmake.org/cmake/help/v3.0/module/CheckCXXSourceCompiles.html to write the C++ code inline here if you want. I wouldn't block the change on it though.
|
||
class enable_get_ref { | ||
class enable_get_ref : public std::enable_shared_from_this<enable_get_ref> { |
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.
Why do we need this as opposed to good ol' fashioned std::enable_shared_from_this<T>
? Is it because we need some base class to be the shared virtual class?
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.
Yep, we just need something to be the inherited class (not even virtual).
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.
Gonna bless this.
9451968
to
35ed41a
Compare
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.
@lexs has imported this pull request. If you are a Facebook employee, you can view this diff on Phabricator.
Summary: Manual import/rebase of #845 Reviewed By: lehecka Differential Revision: D6620084 fbshipit-source-id: ba3e44960c1cc18318767ca479e1e35449c0d51b
Summary: Manual import/rebase of rsocket/rsocket-cpp#845 Reviewed By: lehecka Differential Revision: D6620084 fbshipit-source-id: ba3e44960c1cc18318767ca479e1e35449c0d51b
Pulled in via b3f1927 |
Replaces the intrusive yarpl::Refcounted with std::shared_ptr. Inherit
enable_get_ref
from a few more classes.Benchmarks show ~5% or so perf improvement with
std::shared_ptr
. Finding the impact of/if there are any memory usage differences should be done via canary (this diff introduces 1 word of overhead per object).Original
Reference
implementationstd::shared_ptr
: