Skip to content

Commit

Permalink
Fix memory leaks (#245)
Browse files Browse the repository at this point in the history
* Fix memory leaks

* enable CI
  • Loading branch information
victimsnino authored Aug 30, 2022
1 parent 650055d commit 4c4a0d7
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 27 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,6 @@ jobs:
file: build/coverage/coverage.info

sanitize:
# temporarly disabled
if: false
name: Sanitizer

needs: [download_deps]
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ include(cmake/prelude.cmake)

project(
ReactivePlusPlus
VERSION 0.1.0
VERSION 0.1.1
DESCRIPTION "ReactivePlusPlus is library for building asynchronous event-driven streams of data with help of sequences of primitive operators in the declarative form"
HOMEPAGE_URL "https://github.com/victimsnino/ReactivePlusPlus"
LANGUAGES CXX
Expand Down
43 changes: 28 additions & 15 deletions src/rpp/rpp/observables/connectable_observable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
#include <rpp/subscriptions/composite_subscription.hpp> // lifetime
#include <rpp/defs.hpp> // RPP_EMPTY_BASES

#include <rpp/operators/details/subscriber_with_state.hpp> // create_subscriber_with_state


#include <memory>
#include <mutex>
Expand All @@ -42,18 +44,18 @@ class RPP_EMPTY_BASES connectable_observable
connectable_observable(const OriginalObservable& original_observable, const Subject& subject = Subject{})
: base{subject.get_observable()}
, m_original_observable{original_observable}
, m_subject{subject} {}
, m_state{std::make_shared<state_t>(subject)} {}

connectable_observable(OriginalObservable&& original_observable, const Subject& subject = Subject{})
: base{subject.get_observable()}
, m_original_observable{std::move(original_observable)}
, m_subject{subject} {}
, m_state{std::make_shared<state_t>(subject)} {}

composite_subscription connect(const composite_subscription& subscription = composite_subscription{}) const
{
auto subscriber = m_subject.get_subscriber();
auto subscriber = m_state->subject.get_subscriber();
const auto& subscriber_subscription = subscriber.get_subscription();

{
std::lock_guard lock(m_state->mutex);

Expand All @@ -64,33 +66,44 @@ class RPP_EMPTY_BASES connectable_observable
m_state->sub = subscription;
}

subscription.add([state = m_state, subscriber_subscription]
subscription.add([state = std::weak_ptr{m_state}]
{
auto current_sub = composite_subscription::empty();
if (const auto locked = state.lock())
{
std::lock_guard lock(state->mutex);
std::swap(current_sub, state->sub);
auto current_sub = composite_subscription::empty();
{
std::lock_guard lock(locked->mutex);
std::swap(current_sub, locked->sub);
}
current_sub.unsubscribe();
locked->subject.get_subscriber().get_subscription().remove(current_sub);
}
current_sub.unsubscribe();
subscriber_subscription.remove(current_sub);
});

m_original_observable.subscribe(m_state->sub, subscriber.get_observer());

m_original_observable.subscribe(create_subscriber_with_state<Type>(m_state->sub,
utils::forwarding_on_next{},
utils::forwarding_on_error{},
utils::forwarding_on_completed{},
subscriber.get_observer(),
// capture state to be sure that state is alive while ANY subscriber is alive
m_state));

return subscription;
}

private:
OriginalObservable m_original_observable;
Subject m_subject;

OriginalObservable m_original_observable;
struct state_t
{
state_t(const Subject& subj) : subject{subj} {}

Subject subject;
std::mutex mutex{};
composite_subscription sub = composite_subscription::empty();
};

std::shared_ptr<state_t> m_state = std::make_shared<state_t>();
std::shared_ptr<state_t> m_state{};
};

template<constraint::observable OriginalObservable, subjects::constraint::subject Subject>
Expand Down
23 changes: 17 additions & 6 deletions src/rpp/rpp/operators/ref_count.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
#include <rpp/subscribers/constraints.hpp>
#include <rpp/sources/create.hpp>

#include <rpp/operators/details/subscriber_with_state.hpp> // create_subscriber_with_state


IMPLEMENTATION_FILE(ref_count_tag);

namespace rpp::details
Expand Down Expand Up @@ -53,16 +56,24 @@ struct ref_count_on_subscribe
std::shared_ptr<ref_count_state_t> state = std::make_shared<ref_count_state_t>();

template<constraint::subscriber_of_type<Type> TSub>
void operator()(const TSub &subscriber) const
void operator()(TSub&& subscriber) const
{
const bool need_to_connect = state->on_subscribe();

subscriber.get_subscription().add([state = state]
{
state->on_unsubscribe();
});
subscriber.get_subscription().add([state = std::weak_ptr{state}]
{
if (const auto locked = state.lock())
locked->on_unsubscribe();
});

observable.subscribe(subscriber);
auto sub = subscriber.get_subscription();
observable.subscribe(create_subscriber_with_state<Type>(std::move(sub),
utils::forwarding_on_next{},
utils::forwarding_on_error{},
utils::forwarding_on_completed{},
std::forward<TSub>(subscriber),
// capture state to be sure that state is alive while ANY subscriber is alive
state));
if (need_to_connect)
observable.connect(state->get_subscription());
}
Expand Down
2 changes: 1 addition & 1 deletion src/rpp/rpp/subjects/details/subject_state.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class subject_state : public std::enable_shared_from_this<subject_state<T>>
std::unique_lock lock{m_mutex};

process_state(m_state,
[&](shared_subscribers subs)
[&](const shared_subscribers& subs)
{
auto new_subs = make_copy_of_subscribed_subs(subs->size() + 1, subs);
new_subs->push_back(subscriber);
Expand Down
5 changes: 3 additions & 2 deletions src/rpp/rpp/subjects/publish_subject.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,10 @@ class publish_strategy
publish_strategy(const composite_subscription& sub)
: m_sub{sub}
{
m_sub.add([state = m_state]
m_sub.add([state = std::weak_ptr{m_state}]
{
state->on_unsubscribe();
if(const auto locked = state.lock())
locked->on_unsubscribe();
});
}

Expand Down

1 comment on commit 4c4a0d7

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ci-ubuntu-clang

Observable construction

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observable construction 0.28ns 0.321703 0.87 0.32ns
Dynamic observable construction 30.85ns 26.5683 1.16 24.77ns
Specific observable construction + as_dynamic 24.80ns 28.7171 0.86 21.70ns

Observable lift

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observable lift specific observer 116.11ns 113.596 1.02 285.40ns
Specific observable lift dynamic observer 139.87ns 136.69 1.02 330.85ns
Dynamic observable lift specific observer 217.18ns 196.727 1.10 294.84ns
Dynamic observable lift dynamic observer 176.70ns 198.515 0.89 278.93ns

Observable subscribe

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observable subscribe specific observer 108.18ns 109.049 0.99 287.29ns
Specific observable subscribe dynamic observer 90.63ns 125.809 0.72 275.67ns
Dynamic observable subscribe specific observer 147.41ns 149.839 0.98 386.12ns
Dynamic observable subscribe dynamic observer 147.43ns 142.031 1.04 315.62ns

Observable subscribe #2

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observable subscribe lambda 97.97ns 90.482 1.08 279.70ns
Dynamic observable subscribe lambda 133.22ns 193.655 0.69 356.03ns
Specific observable subscribe lambda without subscription 92.00ns 88.1306 1.04 273.85ns
Dynamic observable subscribe lambda without subscription 138.50ns 173.245 0.80 469.10ns
Specific observable subscribe specific subscriber 42.74ns 38.2036 1.12 217.10ns
Dynamic observable subscribe specific subscriber 104.87ns 114.836 0.91 250.35ns
Specific observable subscribe dynamic observer 38.39ns 47.5107 0.81 222.29ns
Dynamic observable subscribe dynamic observer 89.63ns 108.976 0.82 226.90ns

Observer construction

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observer construction 0.29ns 0.354616 0.82 0.35ns
Dynamic observer construction 29.06ns 24.8276 1.17 18.92ns
Specific observer construction + as_dynamic 29.36ns 36.2123 0.81 17.44ns

OnNext

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observer OnNext 0.62ns 0.767795 0.81 0.59ns
Dynamic observer OnNext 1.83ns 2.14812 0.85 2.27ns

Subscriber construction

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Make subsriber 41.26ns 42.6316 0.97 55.01ns
Make copy of subscriber 15.79ns 16.4398 0.96 5.45ns
Transform subsriber to dynamic 46.97ns 39.4834 1.19 24.03ns

Subscription

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
composite_subscription create 80.99ns 36.2655 2.23 54.33ns
composite_subscription add 51.18ns 47.7021 1.07 19.22ns
composite_subscription unsubscribe 11.98ns 12.7629 0.94 18.48ns

buffer

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
buffer 361.92ns 285.009 1.27 1734.57ns
sending of values from observable via buffer to subscriber 6.52ns 6.94258 0.94 29.80ns

chains creation test

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
long non-state chain creation + subscribe 279.00ns 362.769 0.77 479.13ns
long stateful chain creation + subscribe 366.45ns 367.394 1.00 799.02ns

combine_latest

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
combine_latest construction from observable via dot + subscribe 651.95ns 688.219 0.95 937.98ns
sending of values from observable via combine_latest to subscriber 20.86ns 18.4653 1.13 1.64ns

concat

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
concat 1262.10ns 1639.09 0.77 3561.54ns
concat_with 1682.37ns 1579.11 1.07 4197.71ns

distinct_until_changed

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
distinct_until_changed construction from observable via dot + subscribe 111.53ns 110.129 1.01 245.64ns
sending of values from observable via distinct_until_changed to subscriber 2.70ns 2.88671 0.94 1.24ns

first

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
first construction from observable via dot + subscribe 150.07ns 137.54 1.09 563.67ns
sending of values from observable via first to subscriber 0.53ns 0.451296 1.18 0.50ns

foundamental sources

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
empty 106.85ns 95.3093 1.12 657.12ns
error 153.03ns 148.659 1.03 936.29ns
never 50.70ns 48.0272 1.06 263.24ns

from

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
from vector with int 112.91ns 126.738 0.89 846.57ns

immediate scheduler

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
no any re-schedule 20.90ns 25.2835 0.83 98.19ns
re-schedule 10 times 28.56ns 29.9048 0.96 145.67ns

just

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
just send int 125.39ns 80.0385 1.57 687.79ns
just send variadic 111.74ns 111.52 1.00 880.89ns

map

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
map construction from observable via dot + subscribe 94.24ns 92.0239 1.02 235.97ns
sending of values from observable via map to subscriber 0.99ns 0.93984 1.05 1.68ns

merge

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
merge 1285.50ns 1432.94 0.90 3446.74ns
merge_with 2130.06ns 1829.49 1.16 4069.26ns

observe_on

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
observe_on construction from observable via dot + subscribe 566.82ns 559.183 1.01 2742.76ns
sending of values from observable via observe_on to subscriber 97.45ns 85.2071 1.14 290.21ns

publish_subject callbacks

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
on_next 31.76ns 33.6514 0.94 9.38ns
on_error 0.53ns 0.515287 1.03 17.27ns
on_completed 0.51ns 0.595157 0.85 0.56ns

publish_subject routines

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
construct 180.04ns 155.673 1.16 178.77ns
get_observable 25.73ns 31.9259 0.81 52.46ns
get_subscriber 54.67ns 68.5716 0.80 18.43ns

repeat

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
repeat construction from observable via dot + subscribe 4167.00ns 4907.14 0.85 2886.10ns

scan

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
scan construction from observable via dot + subscribe 109.64ns 119.18 0.92 262.28ns
sending of values from observable via scan to subscriber 2.35ns 2.21702 1.06 1.39ns

skip

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
skip construction from observable via dot + subscribe 114.28ns 127.034 0.90 470.52ns
sending of values from observable via skip to subscriber 2.29ns 2.91617 0.78 1.82ns

switch_on_next

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
switch_on_next construction from observable via dot + subscribe 1635.33ns 2157.65 0.76 3182.74ns
sending of values from observable via switch_on_next to subscriber 457.58ns 553.019 0.83 698.62ns

take

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
take construction from observable via dot + subscribe 194.65ns 203.251 0.96 477.84ns
sending of values from observable via take to subscriber 3.05ns 3.40935 0.90 2.22ns

trampoline scheduler

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
no any re-schedule 29.57ns 33.8058 0.87 168.98ns
re-schedule 10 times 44.90ns 55.355 0.81 173.03ns
recursively schedule 10 times 1827.72ns 1446.99 1.26 5142.48ns

window

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
window 1989.85ns 2073.13 0.96 3838.45ns
sending of values from observable via window to subscriber 477.65ns 663.434 0.72 345.79ns

with_latest_from

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
with_latest_from construction from observable via dot + subscribe 741.03ns 600.208 1.23 1193.79ns
sending of values from observable via with_latest_from to subscriber 16.50ns 21.2983 0.77 2.69ns

ci-ubuntu-gcc

Observable construction

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observable construction 0.36ns 0.402321 0.89 0.44ns
Dynamic observable construction 31.21ns 37.8597 0.82 27.57ns
Specific observable construction + as_dynamic 29.17ns 37.8389 0.77 23.96ns

Observable lift

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observable lift specific observer 146.04ns 151.798 0.96 334.65ns
Specific observable lift dynamic observer 176.31ns 183.531 0.96 437.02ns
Dynamic observable lift specific observer 239.84ns 249.867 0.96 389.61ns
Dynamic observable lift dynamic observer 235.64ns 264.24 0.89 383.55ns

Observable subscribe

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observable subscribe specific observer 101.90ns 107.081 0.95 424.39ns
Specific observable subscribe dynamic observer 120.06ns 121.464 0.99 380.34ns
Dynamic observable subscribe specific observer 173.54ns 188.23 0.92 471.58ns
Dynamic observable subscribe dynamic observer 205.41ns 192.197 1.07 457.40ns

Observable subscribe #2

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observable subscribe lambda 91.47ns 106.515 0.86 405.62ns
Dynamic observable subscribe lambda 168.66ns 188.636 0.89 458.73ns
Specific observable subscribe lambda without subscription 112.66ns 107.032 1.05 334.90ns
Dynamic observable subscribe lambda without subscription 170.80ns 188.206 0.91 437.07ns
Specific observable subscribe specific subscriber 48.88ns 60.2227 0.81 497.43ns
Dynamic observable subscribe specific subscriber 154.80ns 142.279 1.09 351.63ns
Specific observable subscribe dynamic observer 61.68ns 59.8932 1.03 306.79ns
Dynamic observable subscribe dynamic observer 131.47ns 123.343 1.07 311.44ns

Observer construction

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observer construction 0.35ns 0.431943 0.81 0.38ns
Dynamic observer construction 29.82ns 37.9376 0.79 22.74ns
Specific observer construction + as_dynamic 29.57ns 37.9182 0.78 23.00ns

OnNext

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observer OnNext 0.38ns 0.402742 0.95 0.41ns
Dynamic observer OnNext 2.07ns 2.41366 0.86 2.47ns

Subscriber construction

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Make subsriber 46.92ns 48.4379 0.97 57.60ns
Make copy of subscriber 20.16ns 20.0594 1.00 5.94ns
Transform subsriber to dynamic 52.70ns 54.7045 0.96 27.85ns

Subscription

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
composite_subscription create 46.58ns 45.23 1.03 57.16ns
composite_subscription add 69.28ns 55.8643 1.24 21.63ns
composite_subscription unsubscribe 13.58ns 16.4683 0.82 13.83ns

buffer

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
buffer 306.00ns 308.023 0.99 2134.77ns
sending of values from observable via buffer to subscriber 8.48ns 7.50363 1.13 30.75ns

chains creation test

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
long non-state chain creation + subscribe 441.52ns 362.029 1.22 724.44ns
long stateful chain creation + subscribe 505.19ns 524.457 0.96 1149.50ns

combine_latest

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
combine_latest construction from observable via dot + subscribe 707.88ns 801.119 0.88 1171.55ns
sending of values from observable via combine_latest to subscriber 23.15ns 22.0993 1.05 1.59ns

concat

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
concat 1771.91ns 1731.41 1.02 3950.94ns
concat_with 2019.70ns 2089.68 0.97 5226.05ns

distinct_until_changed

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
distinct_until_changed construction from observable via dot + subscribe 127.18ns 169.216 0.75 370.30ns
sending of values from observable via distinct_until_changed to subscriber 3.56ns 5.14394 0.69 1.16ns

first

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
first construction from observable via dot + subscribe 194.54ns 194.102 1.00 800.49ns
sending of values from observable via first to subscriber 0.95ns 1.60973 0.59 0.62ns

foundamental sources

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
empty 99.98ns 105.743 0.95 847.25ns
error 160.88ns 162.065 0.99 903.39ns
never 58.68ns 60.168 0.98 311.36ns

from

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
from vector with int 118.29ns 126.758 0.93 1024.42ns

immediate scheduler

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
no any re-schedule 37.96ns 35.3463 1.07 148.75ns
re-schedule 10 times 55.60ns 53.5357 1.04 202.66ns

just

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
just send int 215.80ns 109.174 1.98 859.07ns
just send variadic 124.24ns 158.586 0.78 914.05ns

map

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
map construction from observable via dot + subscribe 111.27ns 122.076 0.91 351.85ns
sending of values from observable via map to subscriber 0.98ns 1.07219 0.91 1.66ns

merge

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
merge 1566.87ns 1674.71 0.94 4289.31ns
merge_with 1979.32ns 2019.65 0.98 4750.93ns

observe_on

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
observe_on construction from observable via dot + subscribe 617.19ns 736.617 0.84 3777.17ns
sending of values from observable via observe_on to subscriber 100.58ns 108.02 0.93 263.34ns

publish_subject callbacks

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
on_next 25.64ns 27.3192 0.94 13.29ns
on_error 0.77ns 0.808823 0.96 18.05ns
on_completed 1.14ns 0.808592 1.41 0.68ns

publish_subject routines

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
construct 242.94ns 195.277 1.24 193.16ns
get_observable 36.44ns 35.3389 1.03 62.26ns
get_subscriber 64.41ns 68.8167 0.94 27.16ns

repeat

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
repeat construction from observable via dot + subscribe 6695.32ns 4996.46 1.34 3292.35ns

scan

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
scan construction from observable via dot + subscribe 199.91ns 164.422 1.22 454.92ns
sending of values from observable via scan to subscriber 3.31ns 3.62424 0.91 1.87ns

skip

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
skip construction from observable via dot + subscribe 135.59ns 168.378 0.81 542.88ns
sending of values from observable via skip to subscriber 4.43ns 3.61733 1.22 2.26ns

switch_on_next

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
switch_on_next construction from observable via dot + subscribe 2054.63ns 2325.04 0.88 5669.76ns
sending of values from observable via switch_on_next to subscriber 579.47ns 649.084 0.89 1156.84ns

take

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
take construction from observable via dot + subscribe 242.70ns 231.136 1.05 759.18ns
sending of values from observable via take to subscriber 7.08ns 4.04005 1.75 3.31ns

trampoline scheduler

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
no any re-schedule 49.58ns 51.9496 0.95 262.63ns
re-schedule 10 times 69.77ns 79.514 0.88 274.30ns
recursively schedule 10 times 1832.31ns 1781.13 1.03 7491.70ns

window

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
window 2222.27ns 2528.85 0.88 3366.73ns
sending of values from observable via window to subscriber 671.53ns 685.647 0.98 550.42ns

with_latest_from

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
with_latest_from construction from observable via dot + subscribe 744.39ns 801.202 0.93 2198.47ns
sending of values from observable via with_latest_from to subscriber 17.04ns 24.2511 0.70 4.53ns

ci-windows

Observable construction

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observable construction 1.82ns 2.01627 0.90 0.82ns
Dynamic observable construction 96.06ns 104.377 0.92 152.62ns
Specific observable construction + as_dynamic 93.51ns 95.4264 0.98 148.08ns

Observable lift

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observable lift specific observer 214.68ns 230.348 0.93 2196.00ns
Specific observable lift dynamic observer 247.50ns 245.484 1.01 2294.43ns
Dynamic observable lift specific observer 369.45ns 360.773 1.02 2498.92ns
Dynamic observable lift dynamic observer 309.41ns 331.957 0.93 2405.71ns

Observable subscribe

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observable subscribe specific observer 176.99ns 177.012 1.00 2144.33ns
Specific observable subscribe dynamic observer 187.98ns 187.424 1.00 2114.40ns
Dynamic observable subscribe specific observer 314.29ns 349.108 0.90 2367.79ns
Dynamic observable subscribe dynamic observer 253.17ns 247.944 1.02 2319.57ns

Observable subscribe #2

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observable subscribe lambda 176.53ns 177.5 0.99 2095.50ns
Dynamic observable subscribe lambda 319.02ns 324.857 0.98 2471.85ns
Specific observable subscribe lambda without subscription 160.97ns 301.206 0.53 2135.21ns
Dynamic observable subscribe lambda without subscription 331.62ns 334.297 0.99 2428.50ns
Specific observable subscribe specific subscriber 57.50ns 58.6336 0.98 972.77ns
Dynamic observable subscribe specific subscriber 198.02ns 203.19 0.97 1230.35ns
Specific observable subscribe dynamic observer 73.14ns 65.4773 1.12 2170.72ns
Dynamic observable subscribe dynamic observer 133.52ns 119.833 1.11 1978.68ns

Observer construction

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observer construction 1.80ns 1.92154 0.94 1.69ns
Dynamic observer construction 177.16ns 107.762 1.64 137.42ns
Specific observer construction + as_dynamic 98.38ns 106.676 0.92 140.45ns

OnNext

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Specific observer OnNext 0.82ns 0.724454 1.13 0.81ns
Dynamic observer OnNext 2.01ns 5.32623 0.38 2.70ns

Subscriber construction

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
Make subsriber 114.08ns 108.152 1.05 1124.48ns
Make copy of subscriber 20.07ns 21.985 0.91 35.92ns
Transform subsriber to dynamic 115.56ns 150.207 0.77 183.19ns

Subscription

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
composite_subscription create 111.22ns 113.08 0.98 1157.81ns
composite_subscription add 104.98ns 82.2656 1.28 78.96ns
composite_subscription unsubscribe 17.38ns 19.2453 0.90 28.48ns

buffer

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
buffer 461.76ns 461.309 1.00 5215.17ns
sending of values from observable via buffer to subscriber 7.95ns 8.1803 0.97 108.20ns

chains creation test

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
long non-state chain creation + subscribe 330.20ns 331.853 1.00 2010.20ns
long stateful chain creation + subscribe 808.95ns 818.485 0.99 3799.62ns

combine_latest

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
combine_latest construction from observable via dot + subscribe 1304.00ns 1815.5 0.72 4810.50ns
sending of values from observable via combine_latest to subscriber 42.96ns 41.6324 1.03 4.70ns

concat

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
concat 2416.31ns 2445.08 0.99 12029.30ns
concat_with 3228.90ns 3361.3 0.96 13760.00ns

distinct_until_changed

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
distinct_until_changed construction from observable via dot + subscribe 240.79ns 248.942 0.97 1241.08ns
sending of values from observable via distinct_until_changed to subscriber 4.32ns 5.70632 0.76 4.55ns

first

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
first construction from observable via dot + subscribe 172.08ns 178.103 0.97 3117.80ns
sending of values from observable via first to subscriber 3.24ns 3.14296 1.03 2.04ns

foundamental sources

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
empty 95.72ns 104.6 0.92 2888.09ns
error 165.44ns 175.37 0.94 3015.80ns
never 52.92ns 54.9568 0.96 1056.54ns

from

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
from vector with int 186.29ns 193.033 0.97 2945.80ns

immediate scheduler

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
no any re-schedule 33.34ns 31.4755 1.06 503.08ns
re-schedule 10 times 144.76ns 157.037 0.92 540.78ns

just

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
just send int 100.40ns 108.974 0.92 2847.82ns
just send variadic 148.48ns 149.304 0.99 2997.00ns

map

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
map construction from observable via dot + subscribe 122.30ns 122.456 1.00 1182.32ns
sending of values from observable via map to subscriber 4.01ns 3.81261 1.05 9.22ns

merge

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
merge 2200.23ns 2411.31 0.91 13490.30ns
merge_with 3063.00ns 3221.0 0.95 14014.00ns

observe_on

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
observe_on construction from observable via dot + subscribe 987.03ns 1145.61 0.86 6725.20ns
sending of values from observable via observe_on to subscriber 101.60ns 106.939 0.95 929.19ns

publish_subject callbacks

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
on_next 23.94ns 24.6021 0.97 38.91ns
on_error 4.68ns 3.04498 1.54 22.23ns
on_completed 3.24ns 2.96991 1.09 0.77ns

publish_subject routines

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
construct 426.97ns 351.825 1.21 737.89ns
get_observable 32.95ns 30.6228 1.08 188.79ns
get_subscriber 60.38ns 65.0197 0.93 109.29ns

repeat

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
repeat construction from observable via dot + subscribe 8095.80ns 7643.75 1.06 13350.70ns

scan

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
scan construction from observable via dot + subscribe 246.38ns 251.697 0.98 1486.48ns
sending of values from observable via scan to subscriber 6.41ns 6.83989 0.94 11.30ns

skip

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
skip construction from observable via dot + subscribe 228.81ns 242.048 0.95 1863.00ns
sending of values from observable via skip to subscriber 4.42ns 4.52265 0.98 5.27ns

switch_on_next

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
switch_on_next construction from observable via dot + subscribe 4324.00ns 9096.5 0.48 14008.30ns
sending of values from observable via switch_on_next to subscriber 964.73ns 988.194 0.98 3858.33ns

take

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
take construction from observable via dot + subscribe 293.80ns 354.126 0.83 2654.25ns
sending of values from observable via take to subscriber 6.54ns 6.78634 0.96 6.65ns

trampoline scheduler

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
no any re-schedule 51.00ns 47.8522 1.07 962.92ns
re-schedule 10 times 161.52ns 219.934 0.73 780.73ns
recursively schedule 10 times 4217.00ns 3547.89 1.19 23127.00ns

window

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
window 3702.90ns 3671.0 1.01 11633.30ns
sending of values from observable via window to subscriber 1005.31ns 1132.5 0.89 1924.38ns

with_latest_from

Table
Test Name Current, ns Prev, ns Ratio RxCpp current, ns
with_latest_from construction from observable via dot + subscribe 1293.17ns 1401.55 0.92 4548.67ns
sending of values from observable via with_latest_from to subscriber 35.14ns 34.5234 1.02 7.81ns

Please sign in to comment.