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

Make State constructor private #650

Merged
merged 1 commit into from
Sep 28, 2018
Merged

Make State constructor private #650

merged 1 commit into from
Sep 28, 2018

Conversation

dmah42
Copy link
Member

@dmah42 dmah42 commented Aug 13, 2018

State is part of the public API but should not be instantiable outside the benchmark library.

@dmah42 dmah42 requested a review from EricWF August 13, 2018 15:06
@coveralls
Copy link

coveralls commented Aug 13, 2018

Coverage Status

Coverage increased (+0.02%) to 89.047% when pulling deae1d9 on private_ctor into eb8cbec on master.

@AppVeyorBot
Copy link

@AppVeyorBot
Copy link

Build benchmark 1420 failed (commit aa4eb0428f by @dominichamon)

@AppVeyorBot
Copy link

Build benchmark 1423 failed (commit ccfba5f3b5 by @dominichamon)

@dmah42
Copy link
Member Author

dmah42 commented Sep 10, 2018

@EricWF Do you think you'll have a chance to review this?

@EricWF
Copy link
Contributor

EricWF commented Sep 10, 2018 via email

src/benchmark.cc Outdated
State st(iters, b->arg, thread_id, b->threads, &timer, manager);
b->benchmark->Run(st);
CHECK(st.iterations() >= st.max_iterations)
std::unique_ptr<State> st = b->Run(iters, thread_id, &timer, manager);
Copy link
Collaborator

Choose a reason for hiding this comment

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

I personally somehow don't like this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Why?

std::unique_ptr<State> BenchmarkInstance::Run(
size_t iters, int thread_id, internal::ThreadTimer* timer,
internal::ThreadManager* manager) const {
auto st = std::unique_ptr<State>(new State(iters, arg, thread_id, threads,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Well, i should have commented here i guess.
Because it's a memory allocation.
I don't really expect this to matter in the normal usage, but if it can be avoided..

Copy link
Member Author

Choose a reason for hiding this comment

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

We could return a copy of the state from the stack. Or we could have a State* out param that the caller can populate with a stack version, but that moves the instantiation to elsewhere and breaks some of the encapsulation of the Run method.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a thought :) I haven't benchmarked this, so i'm likely just paranoid :)

Copy link
Member Author

Choose a reason for hiding this comment

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

Well that merge was brutal. It now doesn't have the allocation, but it copies. Given this happens once per instance run (ie, not per iteration) and isn't measured as part of the benchmark, i think this is fine. And simpler.

@googlebot
Copy link

So there's good news and bad news.

👍 The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so. Everything is all good there.

😕 The bad news is that it appears that one or more commits were authored or co-authored by someone other than the pull request submitter. We need to confirm that all authors are ok with their commits being contributed to this project. Please have them confirm that here in the pull request.

Note to project maintainer: This is a terminal state, meaning the cla/google commit status will not change from this state. It's up to you to confirm consent of all the commit author(s), set the cla label to yes (if enabled on your project), and then merge this pull request when appropriate.

@dmah42
Copy link
Member Author

dmah42 commented Sep 24, 2018

I think CLA is failing because it includes email addresses that aren't explicitly in my profile. Specifically dominichamon@users.noreply.github.com which is the github internal email address.

@AppVeyorBot
Copy link

Build benchmark 1457 failed (commit 4520662985 by @dominichamon)

@dmah42
Copy link
Member Author

dmah42 commented Sep 26, 2018

Double checked CLA and everything is fine. it's all me in the author list.

Review please?

@LebedevRI
Copy link
Collaborator

github really does not like such merges.
The diff not only contains the actual your changes,
but the changes that were merged from the master branch into this feature branch.

The State constructor should not be part of the public API. Adding a
utility method to BenchmarkInstance allows us to avoid leaking the
RunInThread method into the public API.
@googlebot
Copy link

CLAs look good, thanks!

Copy link
Collaborator

@LebedevRI LebedevRI left a comment

Choose a reason for hiding this comment

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

Hm, no more memory allocations as far i can see?
I like this.
Maybe wait for @EricWF's review, too.

@AppVeyorBot
Copy link

Build benchmark 1484 failed (commit 6d9e5ac45f by @dominichamon)

@dmah42
Copy link
Member Author

dmah42 commented Sep 28, 2018

appveyor failed due to expectation of 0-6 integers for user counter test time but it's up to 7.

@dmah42 dmah42 merged commit edc77a3 into master Sep 28, 2018
@dmah42 dmah42 deleted the private_ctor branch September 28, 2018 11:28
JBakamovic pushed a commit to JBakamovic/benchmark that referenced this pull request Dec 6, 2018
The State constructor should not be part of the public API. Adding a
utility method to BenchmarkInstance allows us to avoid leaking the
RunInThread method into the public API.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants