-
Notifications
You must be signed in to change notification settings - Fork 3
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
Review #6
Review #6
Conversation
* implementing 'Writable' which has an Array of Buffers as an internal storage structure
…ich has an Buffer as an internal storage structure
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.
Use eslint
|
||
let ret = | ||
state.length < state.highWaterMark && | ||
state.bufferOffset + Buffer.from(chunk).length < state.internalBuffer.length; |
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.
- make separate variable for Buffer.from(chunk) to avoid unnecessary memory allocation and copying
- use state.highWaterMark instead of state.internalBuffer.length because they have the same value and in the 1st case you have less nesting
@SemenchenkoVitaliy please compare with @machendos implementation and choose better one |
If @Yone-e will fix everything that I said and add timer, i would consider it as a better one. @machendos implements stream.Writable interface only partially |
Also note that CI fails: https://travis-ci.org/metarhia/metastreams/jobs/412174568
|
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.
Check the code with eslint
this._writableState.bufferedArray = null; | ||
this._writableState.bufferedSize = 0; | ||
|
||
this._writableState.onwrite = onwrite.bind(undefined, this); |
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.
would be better onwrite.bind(null, this);
state.sync = false; | ||
}; | ||
|
||
const onwrite = (stream, error) => { |
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 is necessary to change all lambda functions to a functional declaration, or to raise lambdas to the top, since they are called above
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'd prefer reorder and use lambdas in all cases where this
not needed
const length = state.objectMode ? 1 : chunk.length; | ||
state.length += length; | ||
|
||
let ret = state.length < state.highWaterMark; |
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.
const
instead of let
delete this._writableState.lastBufferedRequest; | ||
delete this._writableState.corkedRequestsFree; | ||
|
||
this._writableState.internalBuffer = Buffer.alloc(this._writableState.highWaterMark); |
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.
We can use here Buffer.allocUnsafe
const callback = state.writecb; | ||
|
||
if (typeof callback !== 'function') { | ||
throw new Error('Callback called multiple times'); |
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.
@tshemsedinov Maybe we should not throw mistakes like this. For example, we can take all the error messages in constants, or at least create variables with them somewhere, and then turn to them? Or is it normal?
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.
For this certain purpose we have callback = common.once(callback)
in https://github.com/metarhia/common I do not think we should throw in such cases
fyi @machendos @SemenchenkoVitaliy this implementation is a somewhat reworked nodejs Writable stream implementation https://github.com/nodejs/node/blob/master/lib/_stream_writable.js. I believe it's not a good idea to inherit all of that, there is a lot of legacy and even nodejs members want to implement a new stream api that will be much more performant and clean (see links). Links: |
Now that I've run speed tests, I see that implementation of @Yone-e is about 1000% slower, maybe due to V8 optimizations of internal streams. |
The goal of this repository, as I understand it, was to rewrite the usual Writable streams to something faster working, and eventually offer our work in the node. But for now, I dont like this decision very much. I agree with @lundibundi that it's just a little overwritten Writable stream from the node. And I also agree with that we shouldnt inherit this decision. Perhaps someone should address this issue in more detail |
Closing for now due to inactivity. Also refs #6 (comment). |
No description provided.