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

lib,test: improve validateNumber and validators coverage #33288

Closed
wants to merge 2 commits into from

Conversation

jasnell
Copy link
Member

@jasnell jasnell commented May 7, 2020

Adds a min/max predicate to validateNumber (which will be used
by the QUIC impl, extracted from that PR) ... and improves test
coverage in test-validators.js

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

Adds a min/max predicate to validateNumber (which will be used
by the QUIC impl, extracted from that PR) ... and improves test
coverage in test-validators.js

Signed-off-by: James M Snell <jasnell@gmail.com>
@jasnell jasnell force-pushed the improve-validators-coverage branch from 89d8f25 to 9c44e2e Compare May 7, 2020 19:29
@nodejs-github-bot
Copy link
Collaborator

@jasnell jasnell added lib / src Issues and PRs related to general changes in the lib or src directory. test Issues and PRs related to the tests. labels May 7, 2020
Copy link
Contributor

@sam-github sam-github left a comment

Choose a reason for hiding this comment

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

Looks reasonable to me.

@BridgeAR
Copy link
Member

BridgeAR commented May 8, 2020

This has a pretty bad performance impact on Buffer functions:

https://ci.nodejs.org/view/Node.js%20benchmark/job/benchmark-node-micro-benchmarks/589/

buffers/buffer-read-float.js n=1000000 value='big' endian='LE' type='Double'                                                                      ***    -35.22 %       ±4.23%  ±5.65%  ±7.40%
buffers/buffer-read-float.js n=1000000 value='big' endian='LE' type='Float'                                                                       ***    -36.75 %       ±3.84%  ±5.11%  ±6.66%
buffers/buffer-read-float.js n=1000000 value='inf' endian='LE' type='Double'                                                                      ***    -34.00 %       ±2.78%  ±3.70%  ±4.82%
buffers/buffer-read-float.js n=1000000 value='inf' endian='LE' type='Float'                                                                       ***    -37.16 %       ±4.29%  ±5.74%  ±7.56%
buffers/buffer-read-float.js n=1000000 value='nan' endian='LE' type='Double'                                                                      ***    -34.50 %       ±3.77%  ±5.01%  ±6.52%
buffers/buffer-read-float.js n=1000000 value='nan' endian='LE' type='Float'                                                                       ***    -37.41 %       ±4.00%  ±5.34%  ±6.97%
buffers/buffer-read-float.js n=1000000 value='small' endian='LE' type='Double'                                                                    ***    -32.99 %       ±3.87%  ±5.15%  ±6.70%
buffers/buffer-read-float.js n=1000000 value='small' endian='LE' type='Float'                                                                     ***    -34.64 %       ±4.69%  ±6.24%  ±8.13%
buffers/buffer-read-float.js n=1000000 value='zero' endian='LE' type='Double'                                                                     ***    -30.59 %       ±3.59%  ±4.78%  ±6.23%
buffers/buffer-read-float.js n=1000000 value='zero' endian='LE' type='Float'                                                                      ***    -34.50 %       ±3.61%  ±4.81%  ±6.27%
buffers/buffer-read.js n=1000000 type='Int16BE' buffer='fast'                                                                                     ***    -41.94 %       ±3.18%  ±4.24%  ±5.54%
buffers/buffer-read.js n=1000000 type='Int16LE' buffer='fast'                                                                                     ***    -39.82 %       ±3.51%  ±4.67%  ±6.07%
buffers/buffer-read.js n=1000000 type='Int32BE' buffer='fast'                                                                                     ***    -43.80 %       ±7.97% ±10.71% ±14.16%
buffers/buffer-read.js n=1000000 type='Int32LE' buffer='fast'                                                                                     ***    -41.17 %       ±4.63%  ±6.20%  ±8.16%
buffers/buffer-read.js n=1000000 type='Int8' buffer='fast'                                                                                        ***    -42.80 %       ±3.62%  ±4.81%  ±6.27%
buffers/buffer-read.js n=1000000 type='UInt16BE' buffer='fast'                                                                                    ***    -42.47 %       ±5.39%  ±7.23%  ±9.50%
buffers/buffer-read.js n=1000000 type='UInt16LE' buffer='fast'                                                                                    ***    -41.85 %       ±5.25%  ±7.00%  ±9.14%
buffers/buffer-read.js n=1000000 type='UInt32BE' buffer='fast'                                                                                    ***    -39.86 %       ±4.67%  ±6.23%  ±8.12%
buffers/buffer-read.js n=1000000 type='UInt32LE' buffer='fast'                                                                                    ***    -36.64 %       ±4.27%  ±5.69%  ±7.41%
buffers/buffer-read.js n=1000000 type='UInt8' buffer='fast'                                                                                       ***    -41.45 %       ±4.46%  ±5.96%  ±7.81%
buffers/buffer-read-with-byteLength.js byteLength=1 n=1000000 type='UIntBE' buffer='fast'                                                         ***    -10.39 %       ±4.92%  ±6.55%  ±8.54%
buffers/buffer-read-with-byteLength.js byteLength=2 n=1000000 type='IntBE' buffer='fast'                                                          ***    -12.85 %       ±4.19%  ±5.61%  ±7.37%
buffers/buffer-read-with-byteLength.js byteLength=2 n=1000000 type='IntLE' buffer='fast'                                                          ***     -8.74 %       ±4.49%  ±5.99%  ±7.82%
buffers/buffer-read-with-byteLength.js byteLength=3 n=1000000 type='IntBE' buffer='fast'                                                          ***    -13.80 %       ±6.32%  ±8.44% ±11.05%
buffers/buffer-read-with-byteLength.js byteLength=4 n=1000000 type='IntLE' buffer='fast'                                                          ***     -7.69 %       ±3.86%  ±5.13%  ±6.68%
buffers/buffer-write.js n=1000000 type='DoubleBE' buffer='fast'                                                                                   ***    -46.12 %       ±4.99%  ±6.66%  ±8.72
buffers/buffer-write.js n=1000000 type='DoubleLE' buffer='fast'                                                                                   ***    -45.58 %       ±5.74%  ±7.67% ±10.03%
buffers/buffer-write.js n=1000000 type='FloatBE' buffer='fast'                                                                                    ***    -47.62 %       ±3.82%  ±5.10%  ±6.67%
buffers/buffer-write.js n=1000000 type='FloatLE' buffer='fast'                                                                                    ***    -49.72 %       ±3.31%  ±4.43%  ±5.82%
buffers/buffer-write.js n=1000000 type='Int32BE' buffer='fast'                                                                                    ***    -35.06 %       ±3.82%  ±5.08%  ±6.61%
buffers/buffer-write.js n=1000000 type='Int32LE' buffer='fast'                                                                                    ***    -34.62 %       ±4.09%  ±5.46%  ±7.12%
buffers/buffer-write.js n=1000000 type='Int8' buffer='fast'                                                                                       ***    -10.01 %       ±4.77%  ±6.36%  ±8.29%
buffers/buffer-write.js n=1000000 type='UInt8' buffer='fast'                                                                                      ***     -9.50 %       ±3.94%  ±5.24%  ±6.82%
buffers/buffer-write.js n=1000000 type='UIntBE' buffer='fast'                                                                                     ***     -8.20 %       ±4.69%  ±6.25%  ±8.17%
buffers/buffer-write-string.js n=1000000 len=2048 args='offset+length' encoding='latin1'                                                          ***      5.14 %       ±2.63%  ±3.52%  ±4.62%

I just copied the results with a high confidence level.


[1, false, '', {}, [], 1n, null, undefined].forEach((i) => {
assert.throws(() => validateBuffer(i, 'foo'), invalidArgTypeError);
});
Copy link
Member

Choose a reason for hiding this comment

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

Do we need these tests? I suggest to add more "integration" tests instead that test these functions where the code is actually implemented. That way we are certain that the code is properly executed by looking at the coverage report.

@jasnell
Copy link
Member Author

jasnell commented May 27, 2020

Closing. Will address a different way in the QUIC code to avoid the perf regression on Buffer.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lib / src Issues and PRs related to general changes in the lib or src directory. test Issues and PRs related to the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants