Skip to content
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

Avoid unnecessary copies in PromiseStream #2915

Merged
merged 5 commits into from Apr 14, 2020

Conversation

tclinken
Copy link
Contributor

@tclinken tclinken commented Apr 7, 2020

No description provided.

@tclinken tclinken requested review from mpilman and atn34 April 7, 2020 00:16
@xumengpanda
Copy link
Contributor

This is great. Do you have data on how much performance benefit this gives us?

@tclinken tclinken marked this pull request as ready for review April 7, 2020 23:36
Copy link
Contributor

@jzhou77 jzhou77 left a comment

Choose a reason for hiding this comment

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

LGTM. I'm kicking off a correctness run to verify.

@jzhou77
Copy link
Contributor

jzhou77 commented Apr 8, 2020

I see some test failures, e.g.,

-r simulation --crash -f ./foundationdb/tests/fast/RandomUnitTests.txt -s 335343273 -b on
-r simulation --crash -f ./foundationdb/tests/fast/RandomUnitTests.txt -s 164750788 -b off

Can you take a look?

Copy link
Collaborator

@atn34 atn34 left a comment

Choose a reason for hiding this comment

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

Looks good. Thanks for adding a unit test

flow/flow.h Outdated
@@ -1009,6 +1013,9 @@ struct ActorSingleCallback : SingleCallback<ValueType> {
virtual void fire(ValueType const& value) {
static_cast<ActorType*>(this)->a_callback_fire(this, value);
}
virtual void fire(ValueType &&value) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't think this has an effect currently since the callbacks generated by the actor compiler all take const references. Would you be ok with removing this for this PR and possibly including it in a followup that includes the actor compiler changes?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This change is necessary for this PR. a_callback_fire takes a parameter by value, not by const reference.

@tclinken
Copy link
Contributor Author

tclinken commented Apr 8, 2020

@jzhou77 I can't seem to replicate those failures locally.

$ bin/fdbserver -r simulation --crash -f ~/FDB6-Worktree/move-optimizations/tests/fast/RandomUnitTests.txt -s 335343273 -b on

passes for me. Do you know which unit test this is running for you?

@mpilman
Copy link
Contributor

mpilman commented Apr 8, 2020

did you build in the docker image? Simulation tests sometimes don't reproduce.

@jzhou77 did you build with make or cmake?

@tclinken
Copy link
Contributor Author

tclinken commented Apr 8, 2020

I built outside of docker, with cmake.

@jzhou77
Copy link
Contributor

jzhou77 commented Apr 8, 2020

@jzhou77 I can't seem to replicate those failures locally.

$ bin/fdbserver -r simulation --crash -f ~/FDB6-Worktree/move-optimizations/tests/fast/RandomUnitTests.txt -s 335343273 -b on

passes for me. Do you know which unit test this is running for you?

The error is here: <InternalError Backtrace="addr2line -e fdbserver.debug -p -C -f -i 0x1acf97c 0x1acf2a8 0x1acf371 0x1a88166 0x1a0b120 0x154c078 0x154d50e 0x10bf008 0x10bf248 0x6e5309 0x1a21f34 0x1a221d5 0x7c4c20 0x1a7b849 0x1a7bd53 0x1a7b93d 0x1a7bfd4 0x7c4c20 0x1b0fc60 0x1a7bee0 0x6a76a3 0x7f6879adaec5" Error=" internal_error" ErrorCode="4100" ErrorDescription="An internal error occurred" File="fdbrpc/FlowTests.actor.cpp" Line="554" LogGroup="default" Roles=" TS" Severity="40"/>

I think it's probably built with make for our correctness.

@mpilman
Copy link
Contributor

mpilman commented Apr 8, 2020

Can you please symbolize the stack trace for us? Maybe we can find the issue without rebuilding with make...

@jzhou77
Copy link
Contributor

jzhou77 commented Apr 8, 2020

Can you please symbolize the stack trace for us? Maybe we can find the issue without rebuilding with make...

Unfortunately, I used Jenkins to run correctness, which doesn't keep debug symbols around.

@tclinken
Copy link
Contributor Author

tclinken commented Apr 8, 2020

Thanks @jzhou77. "/flow/flow/promisestream callbacks" is always failing, so I can debug using SpecificUnitTest.txt.

@tclinken
Copy link
Contributor Author

tclinken commented Apr 8, 2020

Since this PR was approved, @atn34 found some additional optimizations which I've now added. So we should probably review again.

@tclinken tclinken requested review from atn34 and jzhou77 April 8, 2020 21:52
Copy link
Collaborator

@atn34 atn34 left a comment

Choose a reason for hiding this comment

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

LGTM

fdbrpc/FlowTests.actor.cpp Show resolved Hide resolved
@alexmiller-apple
Copy link
Contributor

@jzhou77 I can't seem to replicate those failures locally.

$ bin/fdbserver -r simulation --crash -f ~/FDB6-Worktree/move-optimizations/tests/fast/RandomUnitTests.txt -s 335343273 -b on

passes for me. Do you know which unit test this is running for you?

I've run into this before when helping Senthil and Neelam with correctness runs. As all of the Apple human and infra done builds are done within the build docker image, to reproduce the failures, you need to build and run fdbserver within the build docker image.

@tclinken
Copy link
Contributor Author

@xumengpanda We tested this with the Mako benchmark, and saw noticeable performance improvements:

Mako workload Throughput change (3a01d24 compared to cf81e34)
g16 +3.35%
g64 +2.42%
gr16:5 +3.25%
gr16:10 +5.14%
gr16:50 +7.04%
u8 +8.66%
i8 +6.54%
g8ui +9.28%

@xumengpanda
Copy link
Contributor

@xumengpanda We tested this with the Mako benchmark, and saw noticeable performance improvements:

Mako workload Throughput change (3a01d24 compared to cf81e34)
g16 +3.35%
g64 +2.42%
gr16:5 +3.25%
gr16:10 +5.14%
gr16:50 +7.04%
u8 +8.66%
i8 +6.54%
g8ui +9.28%

This is awesome!

@@ -247,6 +247,15 @@ class RequestStream {
else
queue->send(value);
}

void send(T&& value) const {
Copy link
Contributor

Choose a reason for hiding this comment

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

So, I think that this should work out that template<class T> T&& is a forwarding reference, so you can merge the const T& value and T&& cases into only the T&& case, and then use std::forward<T>(value) instead of std::move(value).

However, it's been... a while since I've had to look this up, so I'm going to merge this PR anyway, and if it turns out that we can shave some code off later, we can do that in a second PR.

Copy link
Collaborator

Choose a reason for hiding this comment

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

So, I think that this should work out that template<class T> T&& is a forwarding reference

I think since T is not a template type parameter of send, value is not a forwarding reference. Here's an example from forwarding reference

template<class T> struct A {
    template<class U>
    A(T&& x, U&& y, int* p); // x is not a forwarding reference: T is not a
                             // type template parameter of the constructor,
                             // but y is a forwarding reference
};

@alexmiller-apple alexmiller-apple merged commit 2e53c8c into apple:master Apr 14, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants