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

buffer: remove noAssert and improve performance #18395

Closed
wants to merge 6 commits into from

Conversation

BridgeAR
Copy link
Member

@BridgeAR BridgeAR commented Jan 26, 2018

This PR contains the following main changes:

  1. Remove the noAssert argument from all buffer functions.
  2. Port write float / double functions to JS.
  3. Improve write float / double performance significantly.
  4. Improve read float / double performance significantly.
  5. Remove implicit offset coercion to uin32.
  6. Remove implicit byteLength coercion to uint32.
  7. The code is mainly simpler to understand / read.
  8. Faster code in all regular cases.
  9. Renamed tests properly.

Update: There is no performance penalty in the regular case anymore. Instead there is a constant performance gain! Only while using noAssert = true some cases exist that got a minor performance penalty. This mainly applies to all Buffer#(write|read)U?Int\d\d?(B|L)E functions.

Now it will not be possible to insert any non integer numbers as offset or byteLength. Any other type than number of floats will throw.

Benchmarks:

Write performance (noAssert = false)
 buffers/buffer-write.js millions=1 type="DoubleBE" buffer="fast"    547.50 %        *** 1.473005e-44
 buffers/buffer-write.js millions=1 type="DoubleBE" buffer="slow"    524.33 %        *** 4.157901e-29
 buffers/buffer-write.js millions=1 type="DoubleLE" buffer="fast"    501.02 %        *** 9.582363e-78
 buffers/buffer-write.js millions=1 type="DoubleLE" buffer="slow"    485.32 %        *** 2.141028e-41
 buffers/buffer-write.js millions=1 type="FloatBE" buffer="fast"     690.22 %        *** 9.522191e-56
 buffers/buffer-write.js millions=1 type="FloatBE" buffer="slow"     652.43 %        *** 3.965170e-24
 buffers/buffer-write.js millions=1 type="FloatLE" buffer="fast"     609.68 %        *** 1.698944e-33
 buffers/buffer-write.js millions=1 type="FloatLE" buffer="slow"     624.15 %        *** 6.233158e-61
 buffers/buffer-write.js millions=1 type="Int16BE" buffer="fast"      14.59 %        *** 3.647589e-10
 buffers/buffer-write.js millions=1 type="Int16BE" buffer="slow"      12.88 %        *** 5.299119e-11
 buffers/buffer-write.js millions=1 type="Int16LE" buffer="fast"      13.30 %        *** 3.997040e-08
 buffers/buffer-write.js millions=1 type="Int16LE" buffer="slow"      15.29 %        *** 8.548797e-08
 buffers/buffer-write.js millions=1 type="Int32BE" buffer="fast"      16.65 %        *** 2.782185e-14
 buffers/buffer-write.js millions=1 type="Int32BE" buffer="slow"      18.25 %        *** 1.764580e-06
 buffers/buffer-write.js millions=1 type="Int32LE" buffer="fast"      12.16 %        *** 1.757401e-15
 buffers/buffer-write.js millions=1 type="Int32LE" buffer="slow"      14.56 %        *** 2.213862e-12
 buffers/buffer-write.js millions=1 type="Int8" buffer="fast"         17.96 %        *** 4.973449e-08
 buffers/buffer-write.js millions=1 type="Int8" buffer="slow"         12.73 %        *** 1.166677e-06
 buffers/buffer-write.js millions=1 type="IntBE" buffer="fast"        89.11 %        *** 1.256975e-52
 buffers/buffer-write.js millions=1 type="IntBE" buffer="slow"        96.61 %        *** 2.188901e-28
 buffers/buffer-write.js millions=1 type="IntLE" buffer="fast"       194.31 %        *** 1.748937e-32
 buffers/buffer-write.js millions=1 type="IntLE" buffer="slow"       193.16 %        *** 3.504647e-32
 buffers/buffer-write.js millions=1 type="UInt16BE" buffer="fast"     20.39 %        *** 5.301260e-15
 buffers/buffer-write.js millions=1 type="UInt16BE" buffer="slow"     18.02 %        *** 7.211474e-15
 buffers/buffer-write.js millions=1 type="UInt16LE" buffer="fast"     17.30 %        *** 3.353633e-13
 buffers/buffer-write.js millions=1 type="UInt16LE" buffer="slow"     20.73 %        *** 1.522262e-10
 buffers/buffer-write.js millions=1 type="UInt32BE" buffer="fast"     14.67 %        *** 2.330133e-15
 buffers/buffer-write.js millions=1 type="UInt32BE" buffer="slow"     12.86 %        *** 1.308623e-14
 buffers/buffer-write.js millions=1 type="UInt32LE" buffer="fast"     17.40 %        *** 1.317629e-07
 buffers/buffer-write.js millions=1 type="UInt32LE" buffer="slow"     16.39 %        *** 9.271141e-12
 buffers/buffer-write.js millions=1 type="UInt8" buffer="fast"        21.21 %        *** 1.878171e-28
 buffers/buffer-write.js millions=1 type="UInt8" buffer="slow"        21.76 %        *** 1.779790e-29
 buffers/buffer-write.js millions=1 type="UIntBE" buffer="fast"       73.04 %        *** 1.082285e-38
 buffers/buffer-write.js millions=1 type="UIntBE" buffer="slow"       70.07 %        *** 1.126729e-18
 buffers/buffer-write.js millions=1 type="UIntLE" buffer="fast"       43.87 %        *** 8.037962e-21
 buffers/buffer-write.js millions=1 type="UIntLE" buffer="slow"       48.81 %        *** 3.516764e-51
Write performance (noAssert = true)
 buffers/buffer-write.js millions=1 type="DoubleBE" buffer="fast"    538.62 %        *** 6.925496e-48
 buffers/buffer-write.js millions=1 type="DoubleBE" buffer="slow"    516.04 %        *** 3.666539e-23
 buffers/buffer-write.js millions=1 type="DoubleLE" buffer="fast"    496.81 %        *** 2.833039e-32
 buffers/buffer-write.js millions=1 type="DoubleLE" buffer="slow"    480.74 %        *** 2.489389e-31
 buffers/buffer-write.js millions=1 type="FloatBE" buffer="fast"     664.20 %        *** 4.724954e-35
 buffers/buffer-write.js millions=1 type="FloatBE" buffer="slow"     651.12 %        *** 1.613268e-25
 buffers/buffer-write.js millions=1 type="FloatLE" buffer="fast"     621.76 %        *** 2.581319e-52
 buffers/buffer-write.js millions=1 type="FloatLE" buffer="slow"     604.34 %        *** 1.104839e-39
 buffers/buffer-write.js millions=1 type="Int16BE" buffer="fast"     -17.65 %        *** 1.201012e-10
 buffers/buffer-write.js millions=1 type="Int16BE" buffer="slow"     -23.37 %        *** 3.580463e-20
 buffers/buffer-write.js millions=1 type="Int16LE" buffer="fast"     -20.16 %        *** 1.304260e-19
 buffers/buffer-write.js millions=1 type="Int16LE" buffer="slow"     -23.28 %        *** 2.205066e-16
 buffers/buffer-write.js millions=1 type="Int32BE" buffer="fast"     -24.65 %        *** 5.581517e-20
 buffers/buffer-write.js millions=1 type="Int32BE" buffer="slow"     -22.81 %        *** 2.986911e-09
 buffers/buffer-write.js millions=1 type="Int32LE" buffer="fast"     -24.62 %        *** 1.859184e-19
 buffers/buffer-write.js millions=1 type="Int32LE" buffer="slow"     -23.01 %        *** 2.205992e-16
 buffers/buffer-write.js millions=1 type="Int8" buffer="fast"        -20.87 %        *** 3.170830e-17
 buffers/buffer-write.js millions=1 type="Int8" buffer="slow"        -21.84 %        *** 7.265008e-21
 buffers/buffer-write.js millions=1 type="IntBE" buffer="fast"        65.97 %        *** 4.573662e-32
 buffers/buffer-write.js millions=1 type="IntBE" buffer="slow"        64.39 %        *** 4.635141e-26
 buffers/buffer-write.js millions=1 type="IntLE" buffer="fast"       149.00 %        *** 8.644140e-53
 buffers/buffer-write.js millions=1 type="IntLE" buffer="slow"       148.19 %        *** 2.590994e-43
 buffers/buffer-write.js millions=1 type="UInt16BE" buffer="fast"    -17.45 %        *** 1.546388e-26
 buffers/buffer-write.js millions=1 type="UInt16BE" buffer="slow"    -18.48 %        *** 1.214273e-15
 buffers/buffer-write.js millions=1 type="UInt16LE" buffer="fast"    -17.30 %        *** 2.101281e-17
 buffers/buffer-write.js millions=1 type="UInt16LE" buffer="slow"    -19.00 %        *** 3.511856e-10
 buffers/buffer-write.js millions=1 type="UInt32BE" buffer="fast"    -20.46 %        *** 7.723638e-16
 buffers/buffer-write.js millions=1 type="UInt32BE" buffer="slow"    -20.36 %        *** 6.687377e-17
 buffers/buffer-write.js millions=1 type="UInt32LE" buffer="fast"    -19.86 %        *** 4.411048e-35
 buffers/buffer-write.js millions=1 type="UInt32LE" buffer="slow"    -19.54 %        *** 9.967127e-13
 buffers/buffer-write.js millions=1 type="UInt8" buffer="fast"       -19.19 %        *** 2.120574e-13
 buffers/buffer-write.js millions=1 type="UInt8" buffer="slow"       -21.28 %        *** 3.871378e-18
 buffers/buffer-write.js millions=1 type="UIntBE" buffer="fast"       42.85 %        *** 2.754020e-16
 buffers/buffer-write.js millions=1 type="UIntBE" buffer="slow"       34.53 %        *** 2.243871e-18
 buffers/buffer-write.js millions=1 type="UIntLE" buffer="fast"      -20.97 %        *** 5.116851e-12
 buffers/buffer-write.js millions=1 type="UIntLE" buffer="slow"      -24.67 %        *** 1.945236e-17
Read performance (noAssert = false)
 buffers/buffer-read.js millions=1 type="DoubleBE" buffer="fast"    113.90 %        *** 1.911543e-52
 buffers/buffer-read.js millions=1 type="DoubleBE" buffer="slow"    114.34 %        *** 9.092115e-60
 buffers/buffer-read.js millions=1 type="DoubleLE" buffer="fast"    107.36 %        *** 3.662694e-29
 buffers/buffer-read.js millions=1 type="DoubleLE" buffer="slow"    105.93 %        *** 3.606574e-31
 buffers/buffer-read.js millions=1 type="FloatBE" buffer="fast"      91.33 %        *** 5.540396e-22
 buffers/buffer-read.js millions=1 type="FloatBE" buffer="slow"      90.81 %        *** 6.675094e-20
 buffers/buffer-read.js millions=1 type="FloatLE" buffer="fast"      90.40 %        *** 4.496193e-23
 buffers/buffer-read.js millions=1 type="FloatLE" buffer="slow"      97.02 %        *** 1.667359e-34
 buffers/buffer-read.js millions=1 type="Int16BE" buffer="fast"       7.29 %        *** 2.039006e-04
 buffers/buffer-read.js millions=1 type="Int16BE" buffer="slow"       9.44 %        *** 2.194688e-09
 buffers/buffer-read.js millions=1 type="Int16LE" buffer="fast"       9.26 %        *** 5.942048e-14
 buffers/buffer-read.js millions=1 type="Int16LE" buffer="slow"       9.13 %        *** 6.586184e-20
 buffers/buffer-read.js millions=1 type="Int32BE" buffer="fast"      41.57 %        *** 1.464605e-19
 buffers/buffer-read.js millions=1 type="Int32BE" buffer="slow"      40.12 %        *** 1.450548e-31
 buffers/buffer-read.js millions=1 type="Int32LE" buffer="fast"      40.56 %        *** 2.584747e-49
 buffers/buffer-read.js millions=1 type="Int32LE" buffer="slow"      40.08 %        *** 5.036330e-36
 buffers/buffer-read.js millions=1 type="Int8" buffer="fast"          8.87 %        *** 1.774984e-04
 buffers/buffer-read.js millions=1 type="Int8" buffer="slow"          6.47 %         ** 9.316969e-03
 buffers/buffer-read.js millions=1 type="UInt16BE" buffer="fast"     48.92 %        *** 2.578342e-19
 buffers/buffer-read.js millions=1 type="UInt16BE" buffer="slow"     45.00 %        *** 1.151413e-23
 buffers/buffer-read.js millions=1 type="UInt16LE" buffer="fast"     46.54 %        *** 1.281878e-29
 buffers/buffer-read.js millions=1 type="UInt16LE" buffer="slow"     42.38 %        *** 1.109386e-17
 buffers/buffer-read.js millions=1 type="UInt32BE" buffer="fast"     42.77 %        *** 1.002809e-17
 buffers/buffer-read.js millions=1 type="UInt32BE" buffer="slow"     45.23 %        *** 9.716449e-51
 buffers/buffer-read.js millions=1 type="UInt32LE" buffer="fast"     46.17 %        *** 2.835040e-31
 buffers/buffer-read.js millions=1 type="UInt32LE" buffer="slow"     43.88 %        *** 2.064203e-19
 buffers/buffer-read.js millions=1 type="UInt8" buffer="fast"        28.83 %        *** 3.009173e-09
 buffers/buffer-read.js millions=1 type="UInt8" buffer="slow"        27.84 %        *** 1.684045e-10
Read performance (noAssert = true)
 buffers/buffer-read.js millions=1 type="DoubleBE" buffer="fast"     96.18 %        *** 5.957149e-67
 buffers/buffer-read.js millions=1 type="DoubleBE" buffer="slow"     94.73 %        *** 8.555417e-45
 buffers/buffer-read.js millions=1 type="DoubleLE" buffer="fast"     92.88 %        *** 1.762136e-33
 buffers/buffer-read.js millions=1 type="DoubleLE" buffer="slow"     90.54 %        *** 1.342842e-22
 buffers/buffer-read.js millions=1 type="FloatBE" buffer="fast"      79.09 %        *** 2.014614e-31
 buffers/buffer-read.js millions=1 type="FloatBE" buffer="slow"      75.23 %        *** 1.030442e-23
 buffers/buffer-read.js millions=1 type="FloatLE" buffer="fast"      91.38 %        *** 5.992152e-37
 buffers/buffer-read.js millions=1 type="FloatLE" buffer="slow"      86.12 %        *** 5.738088e-29
 buffers/buffer-read.js millions=1 type="Int16BE" buffer="fast"      -6.74 %        *** 2.587222e-04
 buffers/buffer-read.js millions=1 type="Int16BE" buffer="slow"      -3.12 %            2.068941e-01
 buffers/buffer-read.js millions=1 type="Int16LE" buffer="fast"      -4.88 %          * 3.088108e-02
 buffers/buffer-read.js millions=1 type="Int16LE" buffer="slow"      -2.24 %            2.779313e-01
 buffers/buffer-read.js millions=1 type="Int32BE" buffer="fast"      -4.57 %         ** 1.824869e-03
 buffers/buffer-read.js millions=1 type="Int32BE" buffer="slow"      -3.24 %        *** 9.967019e-05
 buffers/buffer-read.js millions=1 type="Int32LE" buffer="fast"      -3.68 %        *** 1.375841e-06
 buffers/buffer-read.js millions=1 type="Int32LE" buffer="slow"      -0.82 %            3.765671e-01
 buffers/buffer-read.js millions=1 type="Int8" buffer="fast"         -5.11 %          * 2.676871e-02
 buffers/buffer-read.js millions=1 type="Int8" buffer="slow"         -3.54 %            7.050412e-02
 buffers/buffer-read.js millions=1 type="UInt16BE" buffer="fast"     -3.33 %        *** 4.430650e-07
 buffers/buffer-read.js millions=1 type="UInt16BE" buffer="slow"      0.59 %            8.373744e-01
 buffers/buffer-read.js millions=1 type="UInt16LE" buffer="fast"     -4.46 %          * 3.031628e-02
 buffers/buffer-read.js millions=1 type="UInt16LE" buffer="slow"     -1.96 %            6.235275e-02
 buffers/buffer-read.js millions=1 type="UInt32BE" buffer="fast"     -6.99 %         ** 1.140164e-03
 buffers/buffer-read.js millions=1 type="UInt32BE" buffer="slow"     -2.01 %            4.762397e-01
 buffers/buffer-read.js millions=1 type="UInt32LE" buffer="fast"     -0.74 %            6.419403e-01
 buffers/buffer-read.js millions=1 type="UInt32LE" buffer="slow"      0.93 %            6.486999e-01
 buffers/buffer-read.js millions=1 type="UInt8" buffer="fast"        -7.20 %        *** 4.627997e-06
 buffers/buffer-read.js millions=1 type="UInt8" buffer="slow"       -10.15 %        *** 1.535367e-22
Read performance floats (noAssert = false)
 buffers/buffer-read-float.js millions=1 value="big" endian="BE" type="Double"       95.89 %        *** 9.066634e-27
 buffers/buffer-read-float.js millions=1 value="big" endian="BE" type="Float"        88.07 %        *** 1.658029e-19
 buffers/buffer-read-float.js millions=1 value="big" endian="LE" type="Double"       92.99 %        *** 2.961614e-44
 buffers/buffer-read-float.js millions=1 value="big" endian="LE" type="Float"        99.96 %        *** 7.960766e-34
 buffers/buffer-read-float.js millions=1 value="inf" endian="BE" type="Double"       96.82 %        *** 7.438937e-45
 buffers/buffer-read-float.js millions=1 value="inf" endian="BE" type="Float"        97.98 %        *** 4.801808e-39
 buffers/buffer-read-float.js millions=1 value="inf" endian="LE" type="Double"       95.05 %        *** 1.743159e-59
 buffers/buffer-read-float.js millions=1 value="inf" endian="LE" type="Float"        92.51 %        *** 1.491572e-22
 buffers/buffer-read-float.js millions=1 value="nan" endian="BE" type="Double"      114.86 %        *** 8.687114e-48
 buffers/buffer-read-float.js millions=1 value="nan" endian="BE" type="Float"       109.15 %        *** 5.278654e-43
 buffers/buffer-read-float.js millions=1 value="nan" endian="LE" type="Double"      110.30 %        *** 3.773668e-54
 buffers/buffer-read-float.js millions=1 value="nan" endian="LE" type="Float"       101.27 %        *** 1.481442e-31
 buffers/buffer-read-float.js millions=1 value="small" endian="BE" type="Double"    113.31 %        *** 3.080025e-27
 buffers/buffer-read-float.js millions=1 value="small" endian="BE" type="Float"      87.55 %        *** 2.188483e-24
 buffers/buffer-read-float.js millions=1 value="small" endian="LE" type="Double"    109.67 %        *** 2.279337e-25
 buffers/buffer-read-float.js millions=1 value="small" endian="LE" type="Float"      89.58 %        *** 6.105007e-19
 buffers/buffer-read-float.js millions=1 value="zero" endian="BE" type="Double"     113.78 %        *** 1.112012e-35
 buffers/buffer-read-float.js millions=1 value="zero" endian="BE" type="Float"       94.85 %        *** 1.212354e-34
 buffers/buffer-read-float.js millions=1 value="zero" endian="LE" type="Double"     107.37 %        *** 1.747051e-29
 buffers/buffer-read-float.js millions=1 value="zero" endian="LE" type="Float"      104.06 %        *** 4.100876e-49
Read performance floats (noAssert = true)
 buffers/buffer-read-float.js millions=1 value="big" endian="BE" type="Double"       80.58 %        *** 1.055222e-26
 buffers/buffer-read-float.js millions=1 value="big" endian="BE" type="Float"        84.33 %        *** 2.986016e-25
 buffers/buffer-read-float.js millions=1 value="big" endian="LE" type="Double"       77.97 %        *** 7.124429e-26
 buffers/buffer-read-float.js millions=1 value="big" endian="LE" type="Float"        94.68 %        *** 4.546175e-49
 buffers/buffer-read-float.js millions=1 value="inf" endian="BE" type="Double"       72.64 %        *** 1.320828e-18
 buffers/buffer-read-float.js millions=1 value="inf" endian="BE" type="Float"        78.54 %        *** 1.537538e-30
 buffers/buffer-read-float.js millions=1 value="inf" endian="LE" type="Double"       76.42 %        *** 5.591856e-44
 buffers/buffer-read-float.js millions=1 value="inf" endian="LE" type="Float"        81.52 %        *** 2.768936e-30
 buffers/buffer-read-float.js millions=1 value="nan" endian="BE" type="Double"       94.16 %        *** 1.050472e-32
 buffers/buffer-read-float.js millions=1 value="nan" endian="BE" type="Float"        78.05 %        *** 1.960494e-27
 buffers/buffer-read-float.js millions=1 value="nan" endian="LE" type="Double"       92.07 %        *** 3.095763e-30
 buffers/buffer-read-float.js millions=1 value="nan" endian="LE" type="Float"        80.97 %        *** 1.393600e-30
 buffers/buffer-read-float.js millions=1 value="small" endian="BE" type="Double"     93.51 %        *** 2.107239e-23
 buffers/buffer-read-float.js millions=1 value="small" endian="BE" type="Float"      81.34 %        *** 1.662221e-30
 buffers/buffer-read-float.js millions=1 value="small" endian="LE" type="Double"     97.24 %        *** 7.042144e-30
 buffers/buffer-read-float.js millions=1 value="small" endian="LE" type="Float"      84.74 %        *** 4.624920e-27
 buffers/buffer-read-float.js millions=1 value="zero" endian="BE" type="Double"     101.43 %        *** 5.679133e-35
 buffers/buffer-read-float.js millions=1 value="zero" endian="BE" type="Float"       77.81 %        *** 4.755817e-39
 buffers/buffer-read-float.js millions=1 value="zero" endian="LE" type="Double"     101.23 %        *** 3.239133e-33
 buffers/buffer-read-float.js millions=1 value="zero" endian="LE" type="Float"       83.54 %        *** 1.523533e-17
Read performance U?Int(B|L)E (noAssert = false)
 buffers/buffer-read-with-byteLength.js byteLength=1 millions=1 type="IntBE" buffer="fast"      14.71 %        *** 2.643644e-07
 buffers/buffer-read-with-byteLength.js byteLength=1 millions=1 type="IntBE" buffer="slow"      11.32 %        *** 7.172494e-08
 buffers/buffer-read-with-byteLength.js byteLength=1 millions=1 type="IntLE" buffer="fast"       9.01 %        *** 2.802523e-10
 buffers/buffer-read-with-byteLength.js byteLength=1 millions=1 type="IntLE" buffer="slow"      12.31 %        *** 1.048382e-10
 buffers/buffer-read-with-byteLength.js byteLength=1 millions=1 type="UIntBE" buffer="fast"     37.94 %        *** 3.395681e-15
 buffers/buffer-read-with-byteLength.js byteLength=1 millions=1 type="UIntBE" buffer="slow"     44.59 %        *** 1.792566e-22
 buffers/buffer-read-with-byteLength.js byteLength=1 millions=1 type="UIntLE" buffer="fast"     35.88 %        *** 8.217277e-09
 buffers/buffer-read-with-byteLength.js byteLength=1 millions=1 type="UIntLE" buffer="slow"     44.89 %        *** 7.567703e-21
 buffers/buffer-read-with-byteLength.js byteLength=2 millions=1 type="IntBE" buffer="fast"      20.82 %        *** 6.847277e-12
 buffers/buffer-read-with-byteLength.js byteLength=2 millions=1 type="IntBE" buffer="slow"      17.31 %        *** 6.304545e-09
 buffers/buffer-read-with-byteLength.js byteLength=2 millions=1 type="IntLE" buffer="fast"      38.19 %        *** 1.321802e-20
 buffers/buffer-read-with-byteLength.js byteLength=2 millions=1 type="IntLE" buffer="slow"      38.83 %        *** 1.119840e-21
 buffers/buffer-read-with-byteLength.js byteLength=2 millions=1 type="UIntBE" buffer="fast"     84.49 %        *** 1.060500e-22
 buffers/buffer-read-with-byteLength.js byteLength=2 millions=1 type="UIntBE" buffer="slow"     82.50 %        *** 1.535273e-22
 buffers/buffer-read-with-byteLength.js byteLength=2 millions=1 type="UIntLE" buffer="fast"    107.86 %        *** 1.296005e-45
 buffers/buffer-read-with-byteLength.js byteLength=2 millions=1 type="UIntLE" buffer="slow"    110.61 %        *** 2.135937e-51
 buffers/buffer-read-with-byteLength.js byteLength=3 millions=1 type="IntBE" buffer="fast"      53.76 %        *** 1.185280e-16
 buffers/buffer-read-with-byteLength.js byteLength=3 millions=1 type="IntBE" buffer="slow"      49.06 %        *** 3.718414e-16
 buffers/buffer-read-with-byteLength.js byteLength=3 millions=1 type="IntLE" buffer="fast"      53.18 %        *** 9.260745e-26
 buffers/buffer-read-with-byteLength.js byteLength=3 millions=1 type="IntLE" buffer="slow"      51.86 %        *** 3.336253e-27
 buffers/buffer-read-with-byteLength.js byteLength=3 millions=1 type="UIntBE" buffer="fast"    169.80 %        *** 4.351320e-56
 buffers/buffer-read-with-byteLength.js byteLength=3 millions=1 type="UIntBE" buffer="slow"    164.78 %        *** 2.927265e-51
 buffers/buffer-read-with-byteLength.js byteLength=3 millions=1 type="UIntLE" buffer="fast"    155.65 %        *** 3.455920e-59
 buffers/buffer-read-with-byteLength.js byteLength=3 millions=1 type="UIntLE" buffer="slow"    166.69 %        *** 5.386096e-47
 buffers/buffer-read-with-byteLength.js byteLength=4 millions=1 type="IntBE" buffer="fast"     227.85 %        *** 6.249926e-63
 buffers/buffer-read-with-byteLength.js byteLength=4 millions=1 type="IntBE" buffer="slow"     216.86 %        *** 1.519343e-29
 buffers/buffer-read-with-byteLength.js byteLength=4 millions=1 type="IntLE" buffer="fast"     213.30 %        *** 8.223493e-30
 buffers/buffer-read-with-byteLength.js byteLength=4 millions=1 type="IntLE" buffer="slow"     214.14 %        *** 2.757804e-54
 buffers/buffer-read-with-byteLength.js byteLength=4 millions=1 type="UIntBE" buffer="fast"    190.51 %        *** 1.976842e-54
 buffers/buffer-read-with-byteLength.js byteLength=4 millions=1 type="UIntBE" buffer="slow"    184.19 %        *** 2.481297e-30
 buffers/buffer-read-with-byteLength.js byteLength=4 millions=1 type="UIntLE" buffer="fast"    188.55 %        *** 3.295982e-32
 buffers/buffer-read-with-byteLength.js byteLength=4 millions=1 type="UIntLE" buffer="slow"    180.37 %        *** 1.361985e-27
 buffers/buffer-read-with-byteLength.js byteLength=5 millions=1 type="IntBE" buffer="fast"     126.59 %        *** 3.541448e-28
 buffers/buffer-read-with-byteLength.js byteLength=5 millions=1 type="IntBE" buffer="slow"     128.81 %        *** 5.591153e-35
 buffers/buffer-read-with-byteLength.js byteLength=5 millions=1 type="IntLE" buffer="fast"     125.57 %        *** 4.573430e-27
 buffers/buffer-read-with-byteLength.js byteLength=5 millions=1 type="IntLE" buffer="slow"     131.62 %        *** 8.250501e-30
 buffers/buffer-read-with-byteLength.js byteLength=5 millions=1 type="UIntBE" buffer="fast"    231.82 %        *** 3.265581e-55
 buffers/buffer-read-with-byteLength.js byteLength=5 millions=1 type="UIntBE" buffer="slow"    239.73 %        *** 1.951249e-70
 buffers/buffer-read-with-byteLength.js byteLength=5 millions=1 type="UIntLE" buffer="fast"    234.62 %        *** 6.031666e-63
 buffers/buffer-read-with-byteLength.js byteLength=5 millions=1 type="UIntLE" buffer="slow"    232.60 %        *** 6.845493e-51
 buffers/buffer-read-with-byteLength.js byteLength=6 millions=1 type="IntBE" buffer="fast"     124.84 %        *** 2.607092e-34
 buffers/buffer-read-with-byteLength.js byteLength=6 millions=1 type="IntBE" buffer="slow"     124.90 %        *** 1.503038e-37
 buffers/buffer-read-with-byteLength.js byteLength=6 millions=1 type="IntLE" buffer="fast"     127.04 %        *** 3.788626e-28
 buffers/buffer-read-with-byteLength.js byteLength=6 millions=1 type="IntLE" buffer="slow"     109.71 %        *** 5.212568e-17
 buffers/buffer-read-with-byteLength.js byteLength=6 millions=1 type="UIntBE" buffer="fast"    272.46 %        *** 1.496965e-35
 buffers/buffer-read-with-byteLength.js byteLength=6 millions=1 type="UIntBE" buffer="slow"    268.37 %        *** 3.996840e-38
 buffers/buffer-read-with-byteLength.js byteLength=6 millions=1 type="UIntLE" buffer="fast"    266.41 %        *** 3.436060e-32
 buffers/buffer-read-with-byteLength.js byteLength=6 millions=1 type="UIntLE" buffer="slow"    274.94 %        *** 3.708211e-57
Read performance U?Int(B|L)E (noAssert = true)
 buffers/buffer-read-with-byteLength.js byteLength=1 millions=1 type="IntBE" buffer="fast"     -11.75 %        *** 5.434881e-27
 buffers/buffer-read-with-byteLength.js byteLength=1 millions=1 type="IntBE" buffer="slow"     -12.59 %        *** 8.445023e-11
 buffers/buffer-read-with-byteLength.js byteLength=1 millions=1 type="IntLE" buffer="fast"     -13.26 %        *** 7.432462e-05
 buffers/buffer-read-with-byteLength.js byteLength=1 millions=1 type="IntLE" buffer="slow"     -11.43 %        *** 1.598212e-08
 buffers/buffer-read-with-byteLength.js byteLength=1 millions=1 type="UIntBE" buffer="fast"    -12.28 %        *** 2.251288e-07
 buffers/buffer-read-with-byteLength.js byteLength=1 millions=1 type="UIntBE" buffer="slow"    -12.66 %        *** 2.005521e-27
 buffers/buffer-read-with-byteLength.js byteLength=1 millions=1 type="UIntLE" buffer="fast"    -11.25 %         ** 8.633406e-03
 buffers/buffer-read-with-byteLength.js byteLength=1 millions=1 type="UIntLE" buffer="slow"    -13.79 %        *** 4.185630e-08
 buffers/buffer-read-with-byteLength.js byteLength=2 millions=1 type="IntBE" buffer="fast"       5.65 %        *** 7.833097e-05
 buffers/buffer-read-with-byteLength.js byteLength=2 millions=1 type="IntBE" buffer="slow"       3.14 %            6.123062e-02
 buffers/buffer-read-with-byteLength.js byteLength=2 millions=1 type="IntLE" buffer="fast"      20.47 %        *** 3.392909e-05
 buffers/buffer-read-with-byteLength.js byteLength=2 millions=1 type="IntLE" buffer="slow"      18.76 %        *** 2.253595e-08
 buffers/buffer-read-with-byteLength.js byteLength=2 millions=1 type="UIntBE" buffer="fast"     47.07 %        *** 1.241779e-10
 buffers/buffer-read-with-byteLength.js byteLength=2 millions=1 type="UIntBE" buffer="slow"     52.97 %        *** 9.368908e-27
 buffers/buffer-read-with-byteLength.js byteLength=2 millions=1 type="UIntLE" buffer="fast"     73.68 %        *** 5.399862e-29
 buffers/buffer-read-with-byteLength.js byteLength=2 millions=1 type="UIntLE" buffer="slow"     71.15 %        *** 7.431925e-31
 buffers/buffer-read-with-byteLength.js byteLength=3 millions=1 type="IntBE" buffer="fast"      36.11 %        *** 1.537709e-21
 buffers/buffer-read-with-byteLength.js byteLength=3 millions=1 type="IntBE" buffer="slow"      32.52 %        *** 3.579312e-11
 buffers/buffer-read-with-byteLength.js byteLength=3 millions=1 type="IntLE" buffer="fast"      36.56 %        *** 8.804138e-21
 buffers/buffer-read-with-byteLength.js byteLength=3 millions=1 type="IntLE" buffer="slow"      38.13 %        *** 1.071394e-23
 buffers/buffer-read-with-byteLength.js byteLength=3 millions=1 type="UIntBE" buffer="fast"    154.15 %        *** 1.018753e-33
 buffers/buffer-read-with-byteLength.js byteLength=3 millions=1 type="UIntBE" buffer="slow"    147.62 %        *** 5.070713e-58
 buffers/buffer-read-with-byteLength.js byteLength=3 millions=1 type="UIntLE" buffer="fast"    129.54 %        *** 1.414803e-19
 buffers/buffer-read-with-byteLength.js byteLength=3 millions=1 type="UIntLE" buffer="slow"    150.85 %        *** 8.690505e-41
 buffers/buffer-read-with-byteLength.js byteLength=4 millions=1 type="IntBE" buffer="fast"     219.18 %        *** 5.574215e-59
 buffers/buffer-read-with-byteLength.js byteLength=4 millions=1 type="IntBE" buffer="slow"     205.96 %        *** 1.143638e-26
 buffers/buffer-read-with-byteLength.js byteLength=4 millions=1 type="IntLE" buffer="fast"     210.13 %        *** 2.327704e-29
 buffers/buffer-read-with-byteLength.js byteLength=4 millions=1 type="IntLE" buffer="slow"     205.14 %        *** 6.211261e-22
 buffers/buffer-read-with-byteLength.js byteLength=4 millions=1 type="UIntBE" buffer="fast"    193.70 %        *** 5.548951e-55
 buffers/buffer-read-with-byteLength.js byteLength=4 millions=1 type="UIntBE" buffer="slow"    194.62 %        *** 2.927599e-42
 buffers/buffer-read-with-byteLength.js byteLength=4 millions=1 type="UIntLE" buffer="fast"    193.46 %        *** 1.284468e-56
 buffers/buffer-read-with-byteLength.js byteLength=4 millions=1 type="UIntLE" buffer="slow"    180.99 %        *** 1.737886e-32
 buffers/buffer-read-with-byteLength.js byteLength=5 millions=1 type="IntBE" buffer="fast"     120.25 %        *** 1.464226e-60
 buffers/buffer-read-with-byteLength.js byteLength=5 millions=1 type="IntBE" buffer="slow"     121.19 %        *** 1.954336e-57
 buffers/buffer-read-with-byteLength.js byteLength=5 millions=1 type="IntLE" buffer="fast"     124.40 %        *** 7.956237e-45
 buffers/buffer-read-with-byteLength.js byteLength=5 millions=1 type="IntLE" buffer="slow"     114.87 %        *** 3.476079e-26
 buffers/buffer-read-with-byteLength.js byteLength=5 millions=1 type="UIntBE" buffer="fast"    222.33 %        *** 3.774128e-43
 buffers/buffer-read-with-byteLength.js byteLength=5 millions=1 type="UIntBE" buffer="slow"    224.60 %        *** 7.165524e-36
 buffers/buffer-read-with-byteLength.js byteLength=5 millions=1 type="UIntLE" buffer="fast"    233.35 %        *** 1.692817e-28
 buffers/buffer-read-with-byteLength.js byteLength=5 millions=1 type="UIntLE" buffer="slow"    241.92 %        *** 2.520403e-64
 buffers/buffer-read-with-byteLength.js byteLength=6 millions=1 type="IntBE" buffer="fast"     118.00 %        *** 4.480270e-54
 buffers/buffer-read-with-byteLength.js byteLength=6 millions=1 type="IntBE" buffer="slow"     114.99 %        *** 1.020603e-19
 buffers/buffer-read-with-byteLength.js byteLength=6 millions=1 type="IntLE" buffer="fast"     118.73 %        *** 3.168465e-28
 buffers/buffer-read-with-byteLength.js byteLength=6 millions=1 type="IntLE" buffer="slow"     118.74 %        *** 1.694586e-41
 buffers/buffer-read-with-byteLength.js byteLength=6 millions=1 type="UIntBE" buffer="fast"    246.70 %        *** 2.903501e-26
 buffers/buffer-read-with-byteLength.js byteLength=6 millions=1 type="UIntBE" buffer="slow"    268.76 %        *** 3.243999e-58
 buffers/buffer-read-with-byteLength.js byteLength=6 millions=1 type="UIntLE" buffer="fast"    256.27 %        *** 2.451812e-30
 buffers/buffer-read-with-byteLength.js byteLength=6 millions=1 type="UIntLE" buffer="slow"    267.32 %        *** 5.686033e-58

Fixes #18115
Fixes #12179
Fixes #8724

CI: https://ci.nodejs.org/job/node-test-pull-request/12751/
CI https://ci.nodejs.org/job/node-test-pull-request/12757/

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

buffer, benchmark, test

@BridgeAR BridgeAR added buffer Issues and PRs related to the buffer subsystem. c++ Issues and PRs that require attention from people who are familiar with C++. benchmark Issues and PRs related to the benchmark subsystem. performance Issues and PRs related to the performance of Node.js. labels Jan 26, 2018
@nodejs-github-bot nodejs-github-bot added buffer Issues and PRs related to the buffer subsystem. c++ Issues and PRs that require attention from people who are familiar with C++. labels Jan 26, 2018
@BridgeAR BridgeAR added semver-major PRs that contain breaking changes and should be released in the next major version. wip Issues and PRs that are still a work in progress. labels Jan 26, 2018
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.

This looks very good. I am a bit concerned by the perf regressions in a handful of the tests but given the overall change, I think those are reasonable and this is definitely something to get landed. As I mentioned on the phone with you, I'd like a version of this that we can backport without the semver-major changes but I'm definitely +1 on getting this PR landed. Great work.

assert.throws(function() {
fb.writeFloatLE(0);
}, TypeError);

Copy link
Member Author

Choose a reason for hiding this comment

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

Note: this does not throw anymore and works the same as any other regular buffer method from now on. This was only important for the c++ code that now does not exist anymore.

@BridgeAR
Copy link
Member Author

BridgeAR commented Jan 26, 2018

I marked it as in progress because I still have to clean up the commits. It also seems like some platforms behave weird when it comes to small and big endian but I already have a idea how to solve that. (Solved)

Please take a look nevertheless!

@BridgeAR
Copy link
Member Author

BridgeAR commented Jan 26, 2018

About the performance regressions:

This is very simple math and often the operations needed are very little. So any minimal check added will therefore regress the performance. That should not be important though as long as we are sure we have the best overall implementation in place for the mathematical operations on their own.

Most functions will see a significant performance boost and only a few functions work a tiny bit slower.

To outline what I mean:

const res = new Array(2)

function simpleMath(v) {
  v = +v
  res[0] = v
  res[1] = v << 8
  return res
}

That function is so small and there is so little to do that adding a check like typeof v === 'number' will already regress the performance.

@BridgeAR BridgeAR added the notable-change PRs with changes that should be highlighted in changelogs. label Jan 26, 2018
@BridgeAR
Copy link
Member Author

The endian issue is fixed.

@BridgeAR
Copy link
Member Author

I had another look at the code and found a elegant way to improve the performance in all cases significantly more. Now all noAssert = false cases are faster than before (partially significantly faster).
While using noAssert = true only some write functions have a penalty. The read function are all either almost on par or faster.

I updated the description above accordingly including the benchmarks.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

Good work! The PR description does not mention the implicit coercion change for floats (and maybe others).

LGTM pending a good CITGM run.

@BridgeAR
Copy link
Member Author

BridgeAR commented Jan 28, 2018

Copy link
Member

@apapirovski apapirovski left a comment

Choose a reason for hiding this comment

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

LGTM but I think this should get a number of reviews before landing given the extent of changes. I'll probably read it over another few times myself.

lib/buffer.js Outdated
checkOffset(offset, byteLength, this.length);
}
Buffer.prototype.readUIntLE = function readUIntLE(offset, byteLength) {
if (byteLength === 6)
Copy link
Member

Choose a reason for hiding this comment

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

This should be better as a switch statement, no?

Copy link
Member Author

Choose a reason for hiding this comment

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

I personally prefer this style as it is a bit less to read. The performance is the same. If you have a strong feeling about it, I'll change it, otherwise I would rather keep it.

lib/buffer.js Outdated
while (byteLength > 0 && (mul *= 0x100))
val += this[offset + --byteLength] * mul;
Buffer.prototype.readUIntBE = function readUIntBE(offset, byteLength) {
if (byteLength === 6)
Copy link
Member

Choose a reason for hiding this comment

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

Same as above, re: switch. More of these down below, won't mention every single one :)

kriskowal pushed a commit to thriftrw/thriftrw-node that referenced this pull request Mar 26, 2018
Support for the `noAssert` argument dropped in the upcoming Node.js
v.10. This removes the argument to make sure everything works as it
should.

Refs: nodejs/node#18395
@BridgeAR
Copy link
Member Author

BridgeAR commented Apr 1, 2018

Ping @ChALkeR @addaleax about #18395 (comment)

BridgeAR added a commit to BridgeAR/tedious that referenced this pull request Apr 1, 2018
Support for the `noAssert` argument dropped in the upcoming Node.js
v.10. This removes the argument to make sure everything works as it
should.

Refs: nodejs/node#18395
BridgeAR added a commit to BridgeAR/thriftrw-node that referenced this pull request Apr 1, 2018
Support for the `noAssert` argument dropped in the upcoming Node.js
v.10. This removes the argument to make sure everything works as it
should.

Refs: nodejs/node#18395
@addaleax
Copy link
Member

addaleax commented Apr 1, 2018

@BridgeAR Yes, we need to add back support for omitting the offset (or revert this PR). I’m okay with removing coercion support for other value types like strings, though.

@BridgeAR BridgeAR mentioned this pull request Apr 2, 2018
4 tasks
alexpenev-s pushed a commit to SAP/node-hdb that referenced this pull request Apr 3, 2018
Support for the `noAssert` argument dropped in the upcoming Node.js
v.10. This removes the argument to make sure everything works as it
should.

Refs: nodejs/node#18395
BridgeAR added a commit to BridgeAR/node that referenced this pull request Apr 13, 2018
If none is provided, use zero as a default offset for all read/write
operations on the buffer.

PR-URL: nodejs#19749
Refs: nodejs#18395
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
jasnell pushed a commit that referenced this pull request Apr 16, 2018
If none is provided, use zero as a default offset for all read/write
operations on the buffer.

PR-URL: #19749
Refs: #18395
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
The FIXME is obsolete as it was meant about a indentation issue
that got fixed a long time ago.

PR-URL: nodejs#18395
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
This ports the Buffer#write(Double|Float)(B|L)E functions to JS.
This fixes a security issue concerning type confusion and fixes
another possible crash in combination with `noAssert`.
In addition to that it will also significantly improve the write
performance.

Fixes: nodejs#12179
Fixes: nodejs#8724

PR-URL: nodejs#18395
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
PR-URL: nodejs#18395
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
There are a lot of changes in this commit:

1) Remove the `noAssert` argument from all read and write functions.
2) Improve the performance of all read floating point functions
   significantly. This is done by switching to TypedArrays as the
   write floating point write functions.
3) No implicit type coercion for offset and byteLength anymore.
4) Adds a lot of tests.
5) Moves the read and write functions to the internal buffer file
   to split the files in smaller chunks.
6) Reworked a lot of existing tests.
7) Improve the performane of all all read write functions by using
   a faster input validation and by improving function logic.
8) Significantly improved the performance of all read int functions.
   This is done by using a implementation without a loop.
9) Improved error handling.
10) Rename test file to use the correct subsystem.

PR-URL: nodejs#18395
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
This removes the `noAssert` argument and also adds some more tests.

PR-URL: nodejs#18395
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
MayaLekova pushed a commit to MayaLekova/node that referenced this pull request May 8, 2018
PR-URL: nodejs#18395
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Anatoli Papirovski <apapirovski@mac.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
@tniessen tniessen added the deprecations Issues and PRs related to deprecations. label Sep 7, 2018
@BridgeAR BridgeAR deleted the stricter-buffer branch April 1, 2019 23:39

function boundsError(value, length, type) {
if (Math.floor(value) !== value) {
checkNumberType(value, type);
Copy link
Contributor

Choose a reason for hiding this comment

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

That's a little confused. In other constructions where type is used offset is default value.
Meanwhile checkNumberType (currently validateNumber) will throw AssertionError if type is undefined, because ERR_INVALID_ARG_TYPE have assert which check that type should be a string.
Should it be changed to: function boundsError(value, length, type = 'offset') { ?
@BridgeAR

Copy link
Member Author

Choose a reason for hiding this comment

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

The default value is set in checkNumberType in this PR. Seems like it regressed in #24815. I'll open a PR to fix this. Thanks for reporting it!

Copy link
Member Author

Choose a reason for hiding this comment

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

I just checked this again and all call sites seem fine, even with the PR I mentioned. Do you have any case that actually throws an AssertionError? I can't come up with any case.

Copy link
Contributor

Choose a reason for hiding this comment

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

There is no way to receive AssertionError right now. It's only about readability, when I checked code and found that type passed as undefined I asked myself "is it possible that some error will be thrown?", then I found assert and start looked for real case when error can be thrown. But then I realized that validateNumber will never throw error here because always called before.
If default value will be exists probably this will be easier for reading.

Copy link
Contributor

Choose a reason for hiding this comment

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

What about such change? Or will be reject because not fix anything?

diff --git a/lib/internal/buffer.js b/lib/internal/buffer.js
index f3bc0e48d1..5a6dddf9f8 100644
--- a/lib/internal/buffer.js
+++ b/lib/internal/buffer.js
@@ -60,17 +60,18 @@ function checkInt(value, min, max, buf, offset, byteLength) {
   checkBounds(buf, offset, byteLength);
 }
 
-function boundsError(value, length, type) {
+function boundsError(value, length, type = 'offset') {
   if (Math.floor(value) !== value) {
     validateNumber(value, type);
-    throw new ERR_OUT_OF_RANGE(type || 'offset', 'an integer', value);
+    throw new ERR_OUT_OF_RANGE(type, 'an integer', value);
   }
 
   if (length < 0)
     throw new ERR_BUFFER_OUT_OF_BOUNDS();
 
-  throw new ERR_OUT_OF_RANGE(type || 'offset',
-                             `>= ${type ? 1 : 0} and <= ${length}`,
+  const lowerBound = type === 'offset' ? 0 : 1;
+  throw new ERR_OUT_OF_RANGE(type,
+                             `>= ${lowerBound} and <= ${length}`,
                              value);
 }

kriskowal pushed a commit to thriftrw/thriftrw-node that referenced this pull request Dec 6, 2019
Support for the `noAssert` argument dropped in the upcoming Node.js
v.10. This removes the argument to make sure everything works as it
should.

Refs: nodejs/node#18395
kriskowal pushed a commit to thriftrw/thriftrw-node that referenced this pull request Dec 6, 2019
Support for the `noAssert` argument dropped in the upcoming Node.js
v.10. This removes the argument to make sure everything works as it
should.

Refs: nodejs/node#18395
kriskowal pushed a commit to thriftrw/thriftrw-node that referenced this pull request Dec 6, 2019
Support for the `noAssert` argument dropped in the upcoming Node.js
v.10. This removes the argument to make sure everything works as it
should.

Refs: nodejs/node#18395
kriskowal pushed a commit to thriftrw/thriftrw-node that referenced this pull request Dec 6, 2019
Support for the `noAssert` argument dropped in the upcoming Node.js
v.10. This removes the argument to make sure everything works as it
should.

Refs: nodejs/node#18395
ankon added a commit to ankon/node-lz4 that referenced this pull request Jun 21, 2020
* Use Buffer.alloc/Buffer.from instead of "new Buffer"
* Remove the 'noAssert' parameter from the write calls
  This got removed with nodejs/node#18395

Fixes pierrec#91
ankon added a commit to ankon/node-lz4 that referenced this pull request Jun 21, 2020
* Use Buffer.alloc/Buffer.from instead of "new Buffer"
* Remove the 'noAssert' parameter from the write calls
  This got removed with nodejs/node#18395

Fixes pierrec#91
pierrec pushed a commit to pierrec/node-lz4 that referenced this pull request Jun 22, 2020
* Use Buffer.alloc/Buffer.from instead of "new Buffer"
* Remove the 'noAssert' parameter from the write calls
  This got removed with nodejs/node#18395

Fixes #91
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. benchmark Issues and PRs related to the benchmark subsystem. buffer Issues and PRs related to the buffer subsystem. c++ Issues and PRs that require attention from people who are familiar with C++. deprecations Issues and PRs related to deprecations. notable-change PRs with changes that should be highlighted in changelogs. performance Issues and PRs related to the performance of Node.js. semver-major PRs that contain breaking changes and should be released in the next major version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet