| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
instanceof should be very fast, is there any way to inspect why this speeds it up that much? |
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM after CI passes.
Sorry, something went wrong.
|
@Fishrock123 Actually, instanceof is usually quite slow from my experience, even in V8 5.4. The InstanceOf V8 C++ function is usually one of the top few functions that consume the most ticks when profiling anything that uses (Writable) streams. It's also avoiding a function call in case validChunk doesn't get inlined for some reason (most likely due to reaching max inline depth), so there is that too. |
Sorry, something went wrong.
|
Added another optimization that provides an additional ~30% increase. CI again: https://ci.nodejs.org/job/node-test-pull-request/5669/ |
Sorry, something went wrong.
|
@nodejs/streams |
Sorry, something went wrong.
|
Oh, maybe I was thinking about typeof. |
Sorry, something went wrong.
There was a problem hiding this comment.
@mscdex could chunk have changed before this is called?
Sorry, something went wrong.
There was a problem hiding this comment.
No. writeOrBuffer() is only called by write() and validChunk() does not return a modified chunk or anything.
Sorry, something went wrong.
There was a problem hiding this comment.
The code in itself is fine, and it's a very good catch. However the title in the PR and the commit message does not match the content.
The check is not skipped, it is just executed once.
Sorry, something went wrong.
There was a problem hiding this comment.
You should add back some comment here, explaining this change. validChunk now only checks if a chunk is valid when it is not a Buffer.
Sorry, something went wrong.
There was a problem hiding this comment.
I removed the comments here because they either duplicated what the inline comments already said or had nothing to do with validChunk() ('Otherwise stream chunks ...').
Sorry, something went wrong.
There was a problem hiding this comment.
Even the inline comments are pretty redundant as they just explain what the simple code below it is doing, not worth keeping IMHO. I have added a new comment above the function definition now.
Sorry, something went wrong.
I'm not sure what you mean by this. validChunk() is skipped when chunk is a Buffer. |
Sorry, something went wrong.
I mean that the chunk is validated, i.e. chunk instanceof Buffer is executed, just not on the validChunk method. |
Sorry, something went wrong.
There was a problem hiding this comment.
If this is going to be kept as new Buffer(...), can you add a comment explaining why (e.g. to allow comparison with older Node.js versions). That said, I'd prefer this to be changed to Buffer.alloc(...) given that Node.js 4 is the lowest currently supported version and the new constructors have been backported to that version already.
Sorry, something went wrong.
There was a problem hiding this comment.
Changed.
Sorry, something went wrong.
There was a problem hiding this comment.
Would switching to Buffer.isBuffer() have the same performance profile as instanceof? By removing the instanceof Buffer check here, this becomes a semver-major. If we can switch to Buffer.isBuffer() and still get a performance boost, then this can be semver-patch.
Sorry, something went wrong.
There was a problem hiding this comment.
@jasnell this PR is not removing the check (see my comment). It is still doing it, just in a different way. I would flag it semver-minor, and it can even be backported to v4 and v6.
Sorry, something went wrong.
There was a problem hiding this comment.
Buffer.isBuffer() is just an instanceof check, so that would not help. Also, @mcollina is correct, we're just avoiding duplicate instanceofs since it was already being done in write().
Sorry, something went wrong.
There was a problem hiding this comment.
Ah.. lol, forgot about that :-)
Sorry, something went wrong.
There was a problem hiding this comment.
@mscdex that's my point on the review. "remove duplicate instanceof checks" should be a good commit message/pr title.
Sorry, something went wrong.
There was a problem hiding this comment.
@mcollina It's not just that though, for example it would have also checked for null before getting to the second instanceof check. Anyway, I've changed the commit message. Let me know if it's more suitable.
Sorry, something went wrong.
There was a problem hiding this comment.
Shouldn't we use Buffer.alloc or Buffer.allocUnsafe here?
Sorry, something went wrong.
There was a problem hiding this comment.
I just copied from one of the other buffer benchmarks.
Sorry, something went wrong.
There was a problem hiding this comment.
Changed.
Sorry, something went wrong.
There was a problem hiding this comment.
LGTM
Sorry, something went wrong.
These changes result in ~50% improvement in the included benchmark. PR-URL: nodejs#10580 Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
These changes result in ~50% improvement in the included benchmark. PR-URL: nodejs#10580 Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
These changes result in ~50% improvement in the included benchmark. PR-URL: nodejs#10580 Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
These changes result in ~50% improvement in the included benchmark. PR-URL: nodejs#10580 Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
These changes result in ~50% improvement in the included benchmark. PR-URL: nodejs#10580 Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
|
@mscdex how long should these bake before LTS? |
Sorry, something went wrong.
|
I'm 👍 , but I think we should assemble a release of readable-stream first that embeds those in. |
Sorry, something went wrong.
|
I'm 👍 on backporting to v6. |
Sorry, something went wrong.
These changes result in ~50% improvement in the included benchmark. PR-URL: #10580 Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
These changes result in ~50% improvement in the included benchmark. PR-URL: #10580 Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
These changes result in ~50% improvement in the included benchmark. PR-URL: #10580 Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
These changes result in ~50% improvement in the included benchmark. PR-URL: #10580 Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
These changes result in ~50% improvement in the included benchmark. PR-URL: #10580 Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
These changes result in ~50% improvement in the included benchmark. PR-URL: nodejs/node#10580 Reviewed-By: Сковорода Никита Андреевич <chalkerx@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
| Back | FazBrowse Home | New Git URL |
These changes result in ~50% improvement in the included benchmark:
/cc @nodejs/streams
CI: https://ci.nodejs.org/job/node-test-pull-request/5668/
Checklist
Affected core subsystem(s)