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

stream: hide afterWriteTickInfo property #31287

Closed
wants to merge 2 commits into from
Closed

stream: hide afterWriteTickInfo property #31287

wants to merge 2 commits into from

Conversation

Hakerh400
Copy link
Contributor

@Hakerh400 Hakerh400 commented Jan 9, 2020

Pull request #30710 has introduced afterWriteTickInfo property for optimizing synchronous write completions and it is backported to v12.x as a semver-minor release, but it breaks use case of JSON stringifying writable stream object. This PR hides that property behind a symbol.

Fixes #31277

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

@nodejs-github-bot nodejs-github-bot added the stream Issues and PRs related to the stream subsystem. label Jan 9, 2020
@nodejs-github-bot
Copy link
Collaborator

@BridgeAR BridgeAR added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Jan 9, 2020
@BridgeAR
Copy link
Member

BridgeAR commented Jan 9, 2020

@Hakerh400 maybe also add a regression test?

@mscdex
Copy link
Contributor

mscdex commented Jan 9, 2020

Perhaps we can find a better way to do this?

                                                  confidence improvement accuracy (*)   (**)  (***)
  streams/creation.js kind='duplex' n=50000000           ***    -51.76 %       ±0.96% ±1.27% ±1.66%
  streams/creation.js kind='transform' n=50000000        ***    -48.81 %       ±2.01% ±2.70% ±3.55%
  streams/creation.js kind='writable' n=50000000         ***    -64.69 %       ±2.57% ±3.47% ±4.59%

@BridgeAR
Copy link
Member

BridgeAR commented Jan 9, 2020

Using a symbol instead should have less performance impact.

@mscdex
Copy link
Contributor

mscdex commented Jan 9, 2020

This also needs a test.

@jasnell
Copy link
Member

jasnell commented Jan 10, 2020

This is also likely semver-major.

Copy link
Member

@jasnell jasnell left a comment

Choose a reason for hiding this comment

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

Moving to an internal symbol and aliasing afterWriteTickInfo is likely the better option here.

@Hakerh400
Copy link
Contributor Author

Changed to a symbol and added a test.

I don't think this should be a semver-major. The PR that introduced this property was released in a semver-minor release (and could propably be a semver-patch). This PR can be considered as a fix for a broken use case.

@mscdex
Copy link
Contributor

mscdex commented Jan 10, 2020

Benchmarks with symbol:

                                                  confidence improvement accuracy (*)   (**)  (***)
  streams/creation.js kind='duplex' n=50000000                   -1.51 %       ±2.24% ±2.99% ±3.93%
  streams/creation.js kind='transform' n=50000000          *      3.69 %       ±3.38% ±4.51% ±5.88%
  streams/creation.js kind='writable' n=50000000                  2.66 %       ±3.54% ±4.71% ±6.13%

@Trott
Copy link
Member

Trott commented Jan 12, 2020

@jasnell LGTY?

Copy link
Member

@ronag ronag left a comment

Choose a reason for hiding this comment

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

I'm a little curious about this stringify the stream state use case. That's not really something I believe we support and expecting stringify/parse to work could be a bit dangerous, e.g. if you have callbacks buffered.

I would at least like a test here to avoid similar regressions.

lib/_stream_writable.js Outdated Show resolved Hide resolved
@Hakerh400
Copy link
Contributor Author

I'm a little curious about this stringify the stream state use case. That's not really something I believe we support and expecting stringify/parse to work could be a bit dangerous, e.g. if you have callbacks buffered.

I agree, it is not documented anywhere that a stream object should not contain circular structures. That is why initially I didn't add any test, but @BridgeAR and @mscdex were explicit about adding a test. The point of this PR is to fix a use case in which a code stopped working after a semver-minor release, which may leave users unprepared. I am more than happy to remove the test if we all agree.

@ronag
Copy link
Member

ronag commented Jan 12, 2020

The test is fine. I’m actually asking whether we should add further tests.

@BridgeAR BridgeAR requested a review from jasnell January 13, 2020 08:47
lib/_stream_writable.js Outdated Show resolved Hide resolved
@nodejs-github-bot
Copy link
Collaborator

@nodejs-github-bot
Copy link
Collaborator

@Hakerh400
Copy link
Contributor Author

CI is green.

@jasnell @ronag Any objections left?

Copy link
Member

@ronag ronag left a comment

Choose a reason for hiding this comment

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

LGTM

lib/_stream_writable.js Outdated Show resolved Hide resolved
test/parallel/test-json-stringify-stdout.js Outdated Show resolved Hide resolved
Pull request #30710 has
introduced afterWriteTickInfo property for optimizing
synchronous write completions and it is backported
to v12.x as a semver-minor release, but it breaks
use case of JSON stringifying writable stream object.
This PR hides that property behind a symbol.
@nodejs-github-bot
Copy link
Collaborator

@Hakerh400
Copy link
Contributor Author

Hakerh400 commented Feb 14, 2020

Given that #31187 has landed without explicit enumerability, I tend to assume that we have decided what the consensus regarding this topic is to omit default values in object property definitions.

Removed default enumerable property. PTAL.

Copy link
Member

@addaleax addaleax left a comment

Choose a reason for hiding this comment

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

I fully agree with what @ronag said above – this is a hack to make something work that we don’t actually support. I’m okay with landing this with the understanding that a semver-major revert PR is opened afterwards.

@Hakerh400 Hakerh400 closed this Mar 6, 2020
@Hakerh400 Hakerh400 deleted the stdout branch March 6, 2020 21:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. stream Issues and PRs related to the stream subsystem.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

process.stdout cannot be JSON.stringify()ed because of circular dependency