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

521 shared msg lambda elim #550

Merged
merged 7 commits into from
Nov 30, 2019
Merged

521 shared msg lambda elim #550

merged 7 commits into from
Nov 30, 2019

Conversation

pnstickne
Copy link
Contributor

No description provided.

@pnstickne pnstickne requested a review from lifflander November 5, 2019 07:38
@lifflander
Copy link
Collaborator

@pnstickne Random question, how do you manage to create PRs in "draft" mode. I can't find the way to do that!

@pnstickne
Copy link
Contributor Author

@lifflander Click the little "down arrow" in the right of the PR button - it's a context drop down. Not the most clear.

@pnstickne pnstickne marked this pull request as ready for review November 13, 2019 03:57
std::is_trivially_destructible<T>(),
"Message shall not be downcast unless trivially destructible"
);
// Establish type-erased deref if needed.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could just 'always' pass/down use the deref proxy, especially since such are created with global lifetimes.

return MsgSharedPtr<U>{*this};
return MsgSharedPtr<U>(
reinterpret_cast<U*>(ptr_), true,
deref_ ? deref_ : &statics::StaticMsgDerefs<T>);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Basically zero cost here to "create" the proxy.. and if counting CPU cycles, more branches might add up to more.

@@ -49,7 +49,7 @@ namespace vt { namespace messaging {

void PendingSend::sendMsg() {
if (send_action_ == nullptr) {
theMsg()->sendMsgSized(msg_.getShared(), msg_size_);
theMsg()->sendMsgSized(msg_, msg_size_);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Uh oh. "Feels" like there should be a to or the deref proxy should be universally consistent.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Anyway, to will have the same effect as getShared for a non-trivially-destructible type.

@pnstickne pnstickne requested review from nmm0 and uhetmaniuk November 21, 2019 04:11
@pnstickne
Copy link
Contributor Author

Copy link
Member

@PhilMiller PhilMiller left a comment

Choose a reason for hiding this comment

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

If you're open to rebasing before integration, there's a typo in the commit message: toVritual

@pnstickne
Copy link
Contributor Author

If you're open to rebasing before integration, there's a typo in the commit message: toVritual

I've no problem with such - although I've been scolded before. Amended the commit message for the typo (and improved the explanation in general).

@pnstickne pnstickne force-pushed the 521-shared-msg-lambda-elim branch from af56282 to 5e54643 Compare November 23, 2019 09:48
@pnstickne
Copy link
Contributor Author

pnstickne commented Nov 23, 2019

Now the message-deref will always be done on the original type, regardless of if a type is trivially destructible or not (so there is no special case at all).

Simplifies some checks (replaces one or more conditionals with a single virtual dispatch) and promotes generalized type-erasure support.

Only results in more [fast] t-instantiations for message types that do not use to<T> or toVirtual<T> (which, effectively is "very few").

@lifflander
Copy link
Collaborator

@pnstickne Did you try running valgrind after these changes on some examples or tests to make sure that we are not leaking memory as a check?

@pnstickne
Copy link
Contributor Author

pnstickne commented Nov 29, 2019

@pnstickne Did you try running valgrind after these changes on some examples or tests to make sure that we are not leaking memory as a check?

Nope. I probably should get in the habit :|
That said, all new objects are statically allocated.

pnstickne and others added 7 commits November 29, 2019 22:59
- Folded VirtualMsgPtr into MsgSharedPtr making
  'to' and 'toVirtual' synonyms.

  If the wrapped message type has a non-trivial destructor
  then a proxy 'deref' object is is used so that all derefs
  will apply to the original T-type (and thus invoke the
  delete-expression appropriately).

  This type-erasure ensures that 'messageDeref' is always
  invoked upon the correct T for expeted delete-expr behavior.

- Remove unused code and unified methods

- Ensure move contructor and added move-assignment operator
  (steal resources!!!!)

- Remove messageDeref<Msg<T>> templates; if having a MsgSharedPtr, use it..
- Reduce new-delete (and associated complexity) through use
  of static template objects.

- Use 'assert' for developer-code asserts (critical flaws,
  not logic usages).
- Copy, move, and such.. should all look the same, as
  easier to visualize by proximity.

- Improve comments and such.
- Envelop deref returns ref value (post-deref).

- Ordering, comments, type names, eg.
- Instead of 'sometimes using' an implementation, which
  involves several scattered conditional checks, the implementation
  is always used. Then "to" or "toVirtual" function as a virtue
  of propogating the object for the original Message type.

  Objects all exist with a static lifetime so there is effectively
  no additional cost (beyond the potential for a few more [cheap] template
  instantiations in cases where `to` or `toVirtual` where never
  invoked upon the original MsgT).

 - Renamed types and variables to reflect the larger scope;
   while messageDeref is the only current method, the implementation
   can be expanded (even more of a pimpl..) without name violation.
@lifflander lifflander force-pushed the 521-shared-msg-lambda-elim branch from aadb7e0 to 39ac08e Compare November 30, 2019 07:01
@lifflander lifflander merged commit a74cd43 into develop Nov 30, 2019
@lifflander lifflander added this to the 1.0.0-beta milestone Nov 30, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants