GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — lib,src: replace all C++ promises with JS promises by BridgeAR · Pull Request #20830 · nodejs/node

Conversation

@BridgeAR

@BridgeAR BridgeAR commented May 18, 2018

Copy link
Copy Markdown
Member

C++ promises can not be properly optimized by V8. They also behave
a tiny bit different than "regular" promises (they can not be monkey patched).

This was requested by @nodejs/v8.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bricss and Fishrock123 reacted with thumbs up emoji
All reactions
  • 👍 2 reactions
@BridgeAR
BridgeAR requested review from benjamingr, bmeurer and hashseed May 18, 2018 23:36
@nodejs-github-bot nodejs-github-bot added the lib / src Issues and PRs involving general changes in the lib/ or src/ directories. label May 18, 2018
addaleax
addaleax approved these changes May 18, 2018
View reviewed changes
devsnek
devsnek approved these changes May 18, 2018
View reviewed changes
@BridgeAR

BridgeAR commented May 19, 2018

Copy link
Copy Markdown
Member Author

CI https://ci.nodejs.org/job/node-test-pull-request/14968/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BridgeAR BridgeAR added the author ready PRs with CI started, the required approvals, and no outstanding review comments. label May 19, 2018
TimothyGu
TimothyGu approved these changes May 19, 2018
View reviewed changes
@TimothyGu

TimothyGu commented May 19, 2018

Copy link
Copy Markdown
Member

This was requested by @nodejs/v8.

Can you link where as a "Refs" in the commit message?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BridgeAR

BridgeAR commented May 19, 2018

Copy link
Copy Markdown
Member Author

@TimothyGu we discussed this in person (even though we have meeting notes) two weeks ago.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@TimothyGu

TimothyGu commented May 19, 2018

Copy link
Copy Markdown
Member

They also behave a tiny bit different than "regular" promises (they can not be monkey patched).

Isn't this a desirable property?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BridgeAR

BridgeAR commented May 19, 2018

Copy link
Copy Markdown
Member Author

@TimothyGu not really. Monkey patching is for example still important for APMs and there are probably a couple use cases where people rely on being able to monkey patch promises. Not being able to monkey patch those goes AFAIK against the spec.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@TimothyGu

TimothyGu commented May 19, 2018

Copy link
Copy Markdown
Member

Monkey patching is for example still important for APMs

Async Hooks are also important to APMs, and monkey patching Promise would not allow PROMISE hooks from being called as expected. (By saying this I'm not saying not monkeypatching is better for APMs – only APM developers can say for sure. I am saying this should not be listed as one of the pros for allowing monkeypatching.)

Not being able to monkey patch those goes AFAIK against the spec.

There is no spec for util.promisify, except the documentation and our previous behavior, the latter of which this PR is now breaking.

benjamingr reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@devsnek

devsnek commented May 19, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

a happy medium that can let changing these to be monkey-patchable in a separate pr could be using SafePromise from internal/safe_globals

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@TimothyGu

TimothyGu commented May 19, 2018

Copy link
Copy Markdown
Member

@devsnek We don't want to expose any Safe* objects to userland, as it would no longer be safe. Simply caching the Promise constructor at startup should suffice.

devsnek and benjamingr reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@benjamingr

benjamingr commented May 19, 2018

Copy link
Copy Markdown
Member

First - do we have benchmarks for this?

Second - monkey patching won’t work because of async functions anyway - the future for diagnostics is better hooks

Otherwise LGTM

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

benjamingr
benjamingr reviewed May 19, 2018
View reviewed changes
Comment thread lib/child_process.js Outdated

@benjamingr benjamingr May 19, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

It was written that way to avoid allocation of a closure and be speed-competitive with bluebird.

I’d like to make sure that the speed remains as fast

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@bmeurer bmeurer May 19, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Yes, we should measure the performance here.

I was suggesting to start with JS promises instead, since we spend some time recently to even inline the promise constructor into TurboFan optimized code. If that turns out to be too slow, then the other alternative is to use the createPromise and friends from v8-extras, which is also known to TurboFan, and significantly faster than going through C++.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@benjamingr benjamingr May 19, 2018

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

+1 for createPromise from v8-extras.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
benjamingr
benjamingr reviewed May 19, 2018
View reviewed changes
Comment thread lib/internal/util.js Outdated

This comment was marked as outdated.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

This comment was marked as outdated.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

bmeurer
bmeurer approved these changes May 19, 2018
View reviewed changes

@bmeurer bmeurer left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

LGTM if performance is okay.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
benjamingr
benjamingr requested changes May 19, 2018
View reviewed changes

@benjamingr benjamingr left a comment

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

I'm only blocking to make sure no one merges this by accident before benchmarks.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
apapirovski
apapirovski reviewed May 19, 2018
View reviewed changes

@apapirovski apapirovski left a comment •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This will be somewhere around 10-30% slower than the current version. I tested this fairly recently in relation to promisify. I'll leave it up to others to decide whether that's acceptable.

I chose to discard my own PR due to how much slower it was but perhaps others have a different opinion.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@benjamingr

benjamingr commented May 19, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

@apapirovski

This will be somewhere around 10-30% slower than the current version. I tested this fairly recently in relation to promisify. I'll leave it up to others to decide whether that's acceptable.

A 30% slower promisify would beat half the point of having promisify itself in core. While I personally find it a useful utility anyway the speed benefit was a big part of the reason people were convinced to add it.

That is, if this PR is significantly slower then I'm very -1 on it. However if the V8 team can make an in-javascript promisify as fast as the current version then I'm +1 on it - and in any case a v8-extras solution should be considered.

lpinca reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell

jasnell commented May 19, 2018

Copy link
Copy Markdown
Member

@BridgeAR ... would prefer the changes to different modules to at least be in separate commits.

BridgeAR and addaleax reacted with confused emoji
All reactions
  • 😕 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BridgeAR

BridgeAR commented May 19, 2018

Copy link
Copy Markdown
Member Author

@jasnell if this will land at all I would like to keep it in a single commit. I do not see a compelling reason for it to be split into smaller chunks.

@apapirovski do you still have the benchmark code you used? Any performance impact is heavily influenced by the task at hand. So benchmarking a promisified setTimeout should show the biggest impact if it has influence on the performance.


A general thing: I feel we block to many things for reasons that will have little to no effect on real world applications.

addaleax reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@jasnell

jasnell commented May 19, 2018

Copy link
Copy Markdown
Member

The compelling reason is to isolate distinct changes in case they need to be reverted or backported separately for any reason. It also makes the changes easier to review module by module.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@addaleax

addaleax commented May 19, 2018

Copy link
Copy Markdown
Member

@jasnell I think this is fine to land as a single commit – it’s not particularly huge or so, and I don’t think we want to backport any of this anyway because of the perf impact (adding dont-land-on labels).

ChALkeR reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@addaleax addaleax added dont-land-on-v6.x labels May 19, 2018
@jasnell

jasnell commented Jun 25, 2018

Copy link
Copy Markdown
Member

If that's the only module, then, +1 on proceeding as is without the deprecation.

benjamingr reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

TimothyGu
TimothyGu reviewed Jun 26, 2018
View reviewed changes
Comment thread lib/internal/http2/core.js Outdated

@TimothyGu TimothyGu Jun 26, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Actually, it seems we might be able to remove the custom promisifier entirely: what the getter is doing right now should be the exact things done by util.promisify.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jasnell reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@BridgeAR BridgeAR Jul 14, 2018

Copy link
Copy Markdown
Member Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

A test fails if that part is removed.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@BridgeAR
lib,src: replace all C++ promises with JS promises
fb1d667
C++ promises can not be properly optimized by V8. They also behave
a tiny bit different than "regular" promises.
@BridgeAR
BridgeAR force-pushed the replace-c-promises branch from 5627934 to fb1d667 Compare July 13, 2018 18:38
@BridgeAR

BridgeAR commented Jul 14, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member Author

CI https://ci.nodejs.org/job/node-test-pull-request/15870/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@TimothyGu

TimothyGu commented Jul 15, 2018

Copy link
Copy Markdown
Member

@BridgeAR Can you file a follow-up issue on #20830 (comment) when this PR gets landed?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BridgeAR

BridgeAR commented Jul 16, 2018

Copy link
Copy Markdown
Member Author

Landed in bd1f355 🎉

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

BridgeAR added a commit to BridgeAR/node that referenced this pull request Jul 16, 2018
@BridgeAR
lib,src: replace all C++ promises with JS promises
bd1f355
C++ promises can not be properly optimized by V8. They also behave
a tiny bit different than "regular" promises.

PR-URL: nodejs#20830
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: Benedikt Meurer <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
@BridgeAR BridgeAR closed this Jul 16, 2018
BridgeAR added a commit to BridgeAR/node that referenced this pull request Jul 16, 2018
@BridgeAR
http2: simplify custom promisify
ce447c3
This is just a small refactoring.

Refs: nodejs#20830 (comment)
@BridgeAR BridgeAR mentioned this pull request Jul 16, 2018
http2: simplify custom promisify #21835
Closed
4 tasks done
@BridgeAR

BridgeAR commented Jul 16, 2018

Copy link
Copy Markdown
Member Author

@TimothyGu I personally can not see how that custom promisify should be removed. It is a wrapper for an event and the first argument is always going to be the server. Therefore the http2 case relies on the return value of the function and not on the callback value as that would be registered as an error.
However, I saw that the function could be minified further and I did that: #21835

If there is something else you had in mind, please let me know!

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@targos targos added backport-requested-v10.x and removed author ready PRs with CI started, the required approvals, and no outstanding review comments. labels Jul 16, 2018
@targos

targos commented Jul 16, 2018

Copy link
Copy Markdown
Member

Should this be backported to v10.x-staging? If yes please follow the guide and raise a backport PR, if not let me know or add the dont-land-on label.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@targos targos mentioned this pull request Jul 19, 2018
test: make crashOnUnhandleRejection opt-out #21849
Closed
4 tasks done
targos pushed a commit to targos/node that referenced this pull request Jul 19, 2018
@BridgeAR @targos
lib,src: replace all C++ promises with JS promises
e637159
C++ promises can not be properly optimized by V8. They also behave
a tiny bit different than "regular" promises.

PR-URL: nodejs#20830
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: Benedikt Meurer <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
@targos targos mentioned this pull request Jul 19, 2018
[v10.x] lib,src: replace all C++ promises with JS promises #21879
Closed
@targos targos added backported-to-v10.x and removed backport-requested-v10.x labels Jul 24, 2018
targos pushed a commit that referenced this pull request Jul 24, 2018
@BridgeAR @targos
lib,src: replace all C++ promises with JS promises
9817e40
C++ promises can not be properly optimized by V8. They also behave
a tiny bit different than "regular" promises.

PR-URL: #20830
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: Gus Caplan <[email protected]>
Reviewed-By: Tiancheng "Timothy" Gu <[email protected]>
Reviewed-By: Benedikt Meurer <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>

Backport-PR-URL: #21879
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Benjamin Gruenbaum <[email protected]>
@targos targos mentioned this pull request Jul 31, 2018
v10.8.0 proposal #22040
Merged
This was referenced Aug 1, 2018
2018-08-01 Version 10.8.0 (Current) @targos beevelop/docker-nodejs#212
Closed
2018-08-01 Version 10.8.0 (Current) @targos beevelop/docker-android-nodejs#223
Closed
2018-08-01 Version 10.8.0 (Current) @targos beevelop/docker-android-nodejs#224
Closed
2018-08-01 Version 10.8.0 (Current) @targos beevelop/docker-android-nodejs#225
Closed
2018-08-01 Version 10.8.0 (Current) @targos beevelop/docker-android-nodejs#226
Closed
2018-08-01 Version 10.8.0 (Current) @targos beevelop/docker-android-nodejs#227
Closed
@benjamingr benjamingr mentioned this pull request Oct 11, 2018
Avoid the generic promisify. v8/promise-performance-tests#2
Merged
@BridgeAR
BridgeAR deleted the replace-c-promises branch January 20, 2020 11:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@jasnell jasnell jasnell left review comments
@addaleax addaleax addaleax approved these changes
@benjamingr benjamingr benjamingr approved these changes
@hashseed hashseed Awaiting requested review from hashseed
+4 more reviewers
@apapirovski apapirovski apapirovski left review comments
@TimothyGu TimothyGu TimothyGu approved these changes
@bmeurer bmeurer bmeurer approved these changes
@devsnek devsnek devsnek approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

lib / src Issues and PRs involving general changes in the lib/ or src/ directories. performance Issues and PRs related to the performance of Node.js. semver-minor PRs that contain new features and should be released in the next minor version.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

11 participants

@BridgeAR @TimothyGu @devsnek @benjamingr @jasnell @addaleax @apapirovski @bmeurer @ChALkeR @targos @nodejs-github-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.