-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
buffer: Fixing deopt when constructed with strings #3603
Conversation
/cc @trevnorris |
This seems to decrease performance of buffer creation for fast cases with a larger length pretty consistently...
|
Thanks, I wasn't aware of benchmark/compare.js, I will have a look to see why that is the case, thanks! |
When a buffer was created using `new Buffer('A String')`, internally within the buffer class we would read arguments[1], however in this case we would be reading outside of the array causing a deopt to occur. This fixes this issue by casting the type to a string before use, and removing the usage of the arguments object.
@evanlucas I have been running benchmarks against this, however I am unable to replicate. I am, however getting a high margin of slow on multiple tests for two identical versions of node, node 5.1.0 vs 5.1.0 even show the same discrepancies. (up to 10-5%) However even with that, my changes seem to be consistently positive, with a higher number of operations. |
Note, I have am using a patched version of the benchmarking tools to run all processes at a niceness value of -20 (highest priority). tomgco@King ~/Projects/contrib/node (master●)$ sudo nice -n -20 ./node benchmark/compare.js ../node-01d2798 ./node -- buffers buffer-creation
running ../node-01d2798
buffers/buffer-creation.js
running ./node
buffers/buffer-creation.js
buffers/buffer-creation.js type=fast len=10 n=1024: ../node-01d2798: 2771.4 ./node: 2707.5 ... 2.36%
buffers/buffer-creation.js type=fast len=1024 n=1024: ../node-01d2798: 1669.8 ./node: 1599.6 . 4.39%
buffers/buffer-creation.js type=slow len=10 n=1024: ../node-01d2798: 1598.6 ./node: 1452.6 .. 10.05%
buffers/buffer-creation.js type=slow len=1024 n=1024: ../node-01d2798: 1212.2 ./node: 1178.4 . 2.86%
tomgco@King ~/Projects/contrib/node (master●)$ sudo nice -n -20 ./node benchmark/compare.js ../node-01d2798 ./node -- buffers buffer-creation
running ../node-01d2798
buffers/buffer-creation.js
running ./node
buffers/buffer-creation.js
buffers/buffer-creation.js type=fast len=10 n=1024: ../node-01d2798: 2757.7 ./node: 2719.7 ... 1.40%
buffers/buffer-creation.js type=fast len=1024 n=1024: ../node-01d2798: 1672.1 ./node: 1594.1 . 4.89%
buffers/buffer-creation.js type=slow len=10 n=1024: ../node-01d2798: 1617.9 ./node: 1546.9 ... 4.59%
buffers/buffer-creation.js type=slow len=1024 n=1024: ../node-01d2798: 1192 ./node: 1136.2 ... 4.91%
tomgco@King ~/Projects/contrib/node (master●)$ sudo nice -n -20 ./node benchmark/compare.js ../node-01d2798 ./node -- buffers buffer-creation
running ../node-01d2798
buffers/buffer-creation.js
running ./node
buffers/buffer-creation.js
buffers/buffer-creation.js type=fast len=10 n=1024: ../node-01d2798: 2769.4 ./node: 2710.8 ... 2.16%
buffers/buffer-creation.js type=fast len=1024 n=1024: ../node-01d2798: 1690.8 ./node: 1603.1 . 5.47%
buffers/buffer-creation.js type=slow len=10 n=1024: ../node-01d2798: 1509.9 ./node: 1541.1 .. -2.02%
buffers/buffer-creation.js type=slow len=1024 n=1024: ../node-01d2798: 1171.5 ./node: 1145.3 . 2.29%
tomgco@King ~/Projects/contrib/node (master●)$ sudo nice -n -20 ./node benchmark/compare.js ../node-01d2798 ./node -- buffers buffer-creation
running ../node-01d2798
buffers/buffer-creation.js
running ./node
buffers/buffer-creation.js
buffers/buffer-creation.js type=fast len=10 n=1024: ../node-01d2798: 2743.8 ./node: 2710.5 ... 1.23%
buffers/buffer-creation.js type=fast len=1024 n=1024: ../node-01d2798: 1658.1 ./node: 1606.7 . 3.20%
buffers/buffer-creation.js type=slow len=10 n=1024: ../node-01d2798: 1614.5 ./node: 1448.5 .. 11.45%
buffers/buffer-creation.js type=slow len=1024 n=1024: ../node-01d2798: 1255.1 ./node: 1183.7 . 6.03%
tomgco@King ~/Projects/contrib/node (master●)$ sudo nice -n -20 ./node benchmark/compare.js ../node-01d2798 ./node -- buffers buffer-creation
running ../node-01d2798
buffers/buffer-creation.js
running ./node
buffers/buffer-creation.js
buffers/buffer-creation.js type=fast len=10 n=1024: ../node-01d2798: 2746.8 ./node: 2704.8 ... 1.55%
buffers/buffer-creation.js type=fast len=1024 n=1024: ../node-01d2798: 1639.9 ./node: 1603.9 . 2.24%
buffers/buffer-creation.js type=slow len=10 n=1024: ../node-01d2798: 1617.6 ./node: 1550.5 ... 4.33%
buffers/buffer-creation.js type=slow len=1024 n=1024: ../node-01d2798: 1200.5 ./node: 1170.6 . 2.55% node-01d2798 being this PR and node being master. |
For clarity, this is what I get when I run master vs master, with the As you can see the tests seem to like to deviate even on identical binarys. Now this could be due to kernel settings, the cpu scheduler, etc, I will investigate more into this.
|
@tomgco Those benchmarks need to be run at least a dozen times in order to get a good median result for comparison. Here's a one-liner:
|
@trevnorris lovely, would it be worth incorporating that into the tests? |
@tomgco I like that idea, but also think it should be done in a different way for all the benchmarks. i.e. the current benchmark package needs to be rewritten. |
@trevnorris I am going to close this issue as I am unable to create a reproducable benchmark. |
When a buffer was created using
new Buffer('A String')
, internallywithin the buffer class we would read arguments[1], however in this case
we would be reading outside of the array causing a deopt to occur.
This fixes this issue by casting the type to a string before use, and
removing the usage of the arguments object.