performance increase by using internal unique_ptr for the sink instead of shared_pointer.

Better average (10-15%), and much, much, much better worst case
This commit is contained in:
KjellKod 2014-01-19 22:55:44 -07:00
parent d0045de73b
commit 63616d2acd
3 changed files with 8 additions and 10 deletions

View File

@ -65,8 +65,7 @@ public:
std::unique_ptr<g2::SinkHandle<T >> addSink(std::unique_ptr<T> real_sink, DefaultLogCall call) {
using namespace g2;
using namespace g2::internal;
auto shared_sink = std::shared_ptr<T>(real_sink.release());
auto sink = std::make_shared < Sink < T >> (shared_sink, call);
auto sink = std::make_shared < Sink < T >> (std::move(real_sink), call);
addWrappedSink(sink);
return std2::make_unique < SinkHandle < T >> (sink);
}

View File

@ -33,21 +33,21 @@ typedef std::function<void(LogMessageMover) > AsyncMessageCall;
template<class T>
struct Sink : public SinkWrapper {
std::shared_ptr<T> _real_sink;
std::unique_ptr<T> _real_sink;
std::unique_ptr<kjellkod::Active> _bg;
AsyncMessageCall _default_log_call;
template<typename DefaultLogCall >
Sink(std::shared_ptr<T> sink, DefaultLogCall call)
Sink(std::unique_ptr<T> sink, DefaultLogCall call)
: SinkWrapper (),
_real_sink{sink},
_real_sink{std::move(sink)},
_bg(kjellkod::Active::createActive()),
_default_log_call(std::bind(call, _real_sink.get(), std::placeholders::_1)) {
}
Sink(std::shared_ptr<T> sink, void(T::*Call)(std::string) )
Sink(std::unique_ptr<T> sink, void(T::*Call)(std::string) )
: SinkWrapper(),
_real_sink {sink},
_real_sink {std::move(sink)},
_bg(kjellkod::Active::createActive()) {
auto adapter = std::bind(Call, _real_sink.get(), std::placeholders::_1);
_default_log_call = [ = ](LogMessageMover m){adapter(m.get().toString());};

View File

@ -85,10 +85,8 @@ namespace g2 {
template<typename T, typename DefaultLogCall>
std::unique_ptr< SinkHandle<T> > addSink(std::unique_ptr<T> unique, DefaultLogCall call) {
auto shared = std::shared_ptr<T>(unique.release());
auto sink = std::make_shared < internal::Sink<T> > (shared, call);
auto sink = std::make_shared < internal::Sink<T> > (std::move(unique), call);
auto add_sink_call = [this, sink] { _container.push_back(sink); };
auto wait_result = g2::spawn_task(add_sink_call, _bg.get());
wait_result.wait();
@ -101,6 +99,7 @@ namespace g2 {
using namespace g2;
using namespace g2::internal;