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

src: prevent extra copies of TimerWrap::TimerCb #40665

Conversation

@RaisinTen
Copy link
Member

@RaisinTen RaisinTen commented Oct 30, 2021

I noticed that we were taking TimerCb as a const& and then copying
that into the member. This is completely fine when the constructor is
called with an lvalue. However, when called with an rvalue, we can allow
the std::function to be moved into the member instead of falling back
to a copy, so I changed the constructors to take in universal
references. Also, std::function constructors can take in multiple
arguments, so I further modified the constructors to use variadic
templates.

Signed-off-by: Darshan Sen darshan.sen@postman.com

@nodejs-github-bot

This comment has been hidden.

@nodejs-github-bot

This comment has been hidden.

I noticed that we were taking `TimerCb` as a `const&` and then copying
that into the member. This is completely fine when the constructor is
called with an lvalue. However, when called with an rvalue, we can allow
the `std::function` to be moved into the member instead of falling back
to a copy, so I changed the constructors to take in universal
references. Also, `std::function` constructors can take in multiple
arguments, so I further modified the constructors to use variadic
templates.

Signed-off-by: Darshan Sen <darshan.sen@postman.com>
@RaisinTen RaisinTen force-pushed the src/prevent-extra-copies-of-TimerWrap-TimerCb branch from 6047d0a to bc7efeb Nov 2, 2021
@nodejs-github-bot

This comment has been hidden.

@nodejs-github-bot

This comment has been hidden.

@RaisinTen RaisinTen mentioned this pull request Nov 3, 2021
@nodejs-github-bot
Copy link
Contributor

@nodejs-github-bot nodejs-github-bot commented Nov 3, 2021

Loading

@RaisinTen
Copy link
Member Author

@RaisinTen RaisinTen commented Nov 7, 2021

I had to rebase on top of #40684 to fix the flaky tests. Can this get another review plz?

Loading

@github-actions
Copy link

@github-actions github-actions bot commented Nov 7, 2021

Commit Queue failed
- Loading data for nodejs/node/pull/40665
✔  Done loading data for nodejs/node/pull/40665
----------------------------------- PR info ------------------------------------
Title      src: prevent extra copies of `TimerWrap::TimerCb` (#40665)
Author     Darshan Sen  (@RaisinTen)
Branch     RaisinTen:src/prevent-extra-copies-of-TimerWrap-TimerCb -> nodejs:master
Labels     c++, lib / src, author ready
Commits    1
 - src: prevent extra copies of `TimerWrap::TimerCb`
Committers 1
 - Darshan Sen 
PR-URL: https://github.com/nodejs/node/pull/40665
Reviewed-By: Anna Henningsen 
Reviewed-By: Minwoo Jung 
------------------------------ Generated metadata ------------------------------
PR-URL: https://github.com/nodejs/node/pull/40665
Reviewed-By: Anna Henningsen 
Reviewed-By: Minwoo Jung 
--------------------------------------------------------------------------------
   ⚠  Commits were pushed since the last review:
   ⚠  - src: prevent extra copies of `TimerWrap::TimerCb`
   ℹ  This PR was created on Sat, 30 Oct 2021 15:56:09 GMT
   ✔  Approvals: 2
   ✔  - Anna Henningsen (@addaleax): https://github.com/nodejs/node/pull/40665#pullrequestreview-793747833
   ✔  - Minwoo Jung (@JungMinu): https://github.com/nodejs/node/pull/40665#pullrequestreview-794777797
   ✔  Last GitHub Actions successful
   ℹ  Last Full PR CI on 2021-11-03T13:44:37Z: https://ci.nodejs.org/job/node-test-pull-request/40683/
- Querying data for job/node-test-pull-request/40683/
✔  Build data downloaded
   ✔  Last Jenkins CI successful
--------------------------------------------------------------------------------
   ✔  Aborted `git node land` session in /home/runner/work/node/node/.ncu
https://github.com/nodejs/node/actions/runs/1431079248

Loading

aduh95
aduh95 approved these changes Nov 7, 2021
Copy link
Contributor

@aduh95 aduh95 left a comment

RSLGTM

Loading

@nodejs-github-bot nodejs-github-bot merged commit 2d368da into nodejs:master Nov 12, 2021
53 checks passed
Loading
@nodejs-github-bot
Copy link
Contributor

@nodejs-github-bot nodejs-github-bot commented Nov 12, 2021

Landed in 2d368da

Loading

@RaisinTen RaisinTen deleted the src/prevent-extra-copies-of-TimerWrap-TimerCb branch Nov 13, 2021
targos added a commit that referenced this issue Nov 21, 2021
I noticed that we were taking `TimerCb` as a `const&` and then copying
that into the member. This is completely fine when the constructor is
called with an lvalue. However, when called with an rvalue, we can allow
the `std::function` to be moved into the member instead of falling back
to a copy, so I changed the constructors to take in universal
references. Also, `std::function` constructors can take in multiple
arguments, so I further modified the constructors to use variadic
templates.

Signed-off-by: Darshan Sen <darshan.sen@postman.com>

PR-URL: #40665
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Minwoo Jung <nodecorelab@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants