buffer: slow buffer copy compatibility fix#4639
buffer: slow buffer copy compatibility fix#4639trevnorris wants to merge 3 commits intonodejs:masterfrom trevnorris:issue-4633
Conversation
|
Just as a side note, the reason for the extensive changes to the unit tests are because each buffer had the same values at the same intervals. So even if the copy failed silently, the asserts would still have passed. |
lib/buffer.js
Outdated
There was a problem hiding this comment.
Yeah, that was a stupid one. Should have just been placed in the return statement. Done.
|
This should be several small (atomic) commits, not a single big one. |
|
@bnoordhuis Can do. Should each of those be their own PR, or could they be |
|
Using this PR is fine. |
|
I've tried to split each set of changes as logically as possible. The first commit has the bare essentials necessary for fixing GH-4633. @TooTallNate requested the change be placed on the v0.8 branch, so I've made sure it can be |
|
Mostly LGTM but I don't know if I agree with changing everything that's not an unsigned int to 0, especially values < 0. It a) sounds like a potential source of obscure bugs in user code, and b) it could conceivably be used for something useful, like specifying from-end-of-buffer offsets. @isaacs, @TooTallNate: Thoughts? |
|
@bnoordhuis actually that comment is incorrect. It sets all non-number-y values that may be less than zero to 0, for And actually, it should be As for I agree it could be a way to obscure bugs, but don't feel more than it did before. Now the "from-end-of-buffer offsets" is a good point. Though currently all values are |
|
ok. took half a dozen rebases, but think it's taken care of. |
|
LGTM. Maybe check with the others if we want to leave room in the API for negative offsets. I like the idea but maybe there are good reasons not to. |
|
@bnoordhuis awesome. so, fixed the space issue I forgot. rebased off most recent master and @isaacs said no go on the negative offsets. think we're good. thanks a lot. Update: ah crap. changed the commit msg and the code comments, but forgot to change the api. give me 5 to fix it. |
|
@bnoordhuis ok. now I swear it's complete. updated the commit msg, api docs and code comment. also fixed a couple |
Fix issue where SlowBuffers couldn't be passed as target to Buffer copy(). Also included checks to see if Argument parameters are defined before assigning their values. This offered ~3x's performance gain.
Argument checks were simplified by setting all undefined/NaN or out of bounds values equal to their defaults. Also copy() tests had a flaw that each buffer had the same bit pattern at the same offset. So even if the copy failed, the bit-by-bit comparison would have still been true. This was fixed by filling each buffer with a unique value before copy operations.
Changed types of errors thrown to be more indicative of what the error represents. Also removed a few unnecessary uses of the v8 fully quantified typename.
There was a problem hiding this comment.
Small note: I wonder if calling IsUndefined() first is a minor deoptimization. Uint32Value() is only expensive when the value is not an SMI but that should be relatively rare.
|
@bnoordhuis You're correct. I was focused too much on another aspect. Here are my benchmarks that will help me explain: So at the time I was focused on performance of calling copy against a SlowBuffer with no arguments. For some reason @TooTallNate depending on what @bnoordhuis wants to do here, I know you wanted to |
Fix issue where SlowBuffers couldn't be passed as targets for fast
buffer copy().
Also included small cleanups:
There are many fixes here for
Buffer.copy()that, imho, needed to be done, but too many for the v0.8 branch. I'll backport the basic changes and make another pull request for that.Fix for GH-4633