Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Minor refactor: prevent string copying, list -> vector, shared_ptr by… #8872

Merged
merged 1 commit into from
Jan 31, 2018

Conversation

larroy
Copy link
Contributor

@larroy larroy commented Nov 29, 2017

Checklist

Essentials

  • Passed code style checking (make lint)
  • Changes are complete (i.e. I finished coding on this PR)
  • All changes have test coverage
  • For user-facing API changes, API doc string has been updated. For new C++ functions in header files, their functionalities and arguments are well-documented.
  • To my best knowledge, examples are either not affected by this change, or have been fixed to be compatible with this change

Changes

  • Functionally equivalent changes

@@ -122,7 +123,7 @@ class ThreadPool {
/*!
* \brief Startup synchronization objects
*/
std::list<std::shared_ptr<SimpleEvent>> ready_events_;
std::vector<std::shared_ptr<SimpleEvent> > ready_events_;
Copy link
Contributor

Choose a reason for hiding this comment

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

Are you sure about this? I think this is by design

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I checked the code several times, why use a list if we are just appending items, which are in addition pointers. I don't think it's a critical code path, correct me if I'm wrong, but in general a vector is faster,smaller and cache efficient. Do you see any problems with this?

Copy link
Contributor Author

@larroy larroy Nov 30, 2017

Choose a reason for hiding this comment

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

Checked again, should be fine.

Copy link
Member

Choose a reason for hiding this comment

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

Why did you change to vector?

Copy link
Member

Choose a reason for hiding this comment

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

This is by design

Copy link
Member

Choose a reason for hiding this comment

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

This is by design

Copy link
Member

Choose a reason for hiding this comment

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

Inserting arbitrarily into a vector can cause CPU spikes. These are not accessed in a way that cache matters and random access is not required. Please revert.

@piiswrong
Copy link
Contributor

please change type const -> const type

@larroy larroy force-pushed the refactor branch 8 times, most recently from b28050a to e139608 Compare December 4, 2017 18:40
@larroy larroy force-pushed the refactor branch 4 times, most recently from fb0e257 to 9360b04 Compare December 7, 2017 20:18
@piiswrong
Copy link
Contributor

LGTM.
Please resolve conflicts

@larroy larroy force-pushed the refactor branch 2 times, most recently from 3b19270 to dd62dbd Compare December 10, 2017 17:47
@larroy
Copy link
Contributor Author

larroy commented Dec 11, 2017

Done

@larroy
Copy link
Contributor Author

larroy commented Dec 12, 2017

@piiswrong please merge?

@larroy
Copy link
Contributor Author

larroy commented Dec 14, 2017

@cjolivier01 this should be good to go as well. Thank you so much for merging my PRs.

Copy link
Member

@cjolivier01 cjolivier01 left a comment

Choose a reason for hiding this comment

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

A lot of this looks like changing things just for the sake of changing them.

@@ -58,8 +57,8 @@ class ThreadPool {

/*! \brief Signal event upon destruction, even for exceptions (RAII) */
struct SetReadyOnDestroy {
explicit inline SetReadyOnDestroy(std::shared_ptr<SimpleEvent> *event)
: event_(*event) {
explicit inline SetReadyOnDestroy(const std::shared_ptr<SimpleEvent>& event)
Copy link
Member

Choose a reason for hiding this comment

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

Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

general practice is to pass shared pointers by reference to prevent copies and in this case the pointer to shared pointer could be null and is not being checked.

@larroy
Copy link
Contributor Author

larroy commented Dec 14, 2017

Changing the strings to references instead of unnecesary copies is not just for the sake of changing them.

@larroy
Copy link
Contributor Author

larroy commented Dec 14, 2017

changed the vector back to list

@larroy
Copy link
Contributor Author

larroy commented Dec 14, 2017

Actually I disagree with your statement about the vector. The size is fixed and known at construction time. There's not going to be any cpu spike. Please elaborate your claim.

@piiswrong piiswrong merged commit 376d47f into apache:master Jan 31, 2018
rahul003 pushed a commit to rahul003/mxnet that referenced this pull request Jun 4, 2018
zheng-da pushed a commit to zheng-da/incubator-mxnet that referenced this pull request Jun 28, 2018
@larroy larroy deleted the refactor branch November 15, 2018 18:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants