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

src: refactor EndsInANumber in node_url.cc and adds IsIPv4NumberValid #46227

Merged
merged 14 commits into from
Jan 23, 2023

Conversation

miguelteixeiraa
Copy link
Contributor

Removes the use of vector in EndsInANumber and uses IsIPv4NumberValid instead of parsing the number to check if it is valid.

Fixes: nodejs/performance#36
Refs: ada-url/ada#36

Removes the use of vector in EndsInANumber and uses
IsIPv4NumberValid instead of parsing the number to check
if it is valid.

Fixes: nodejs/performance#36
Refs: ada-url/ada#36
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. needs-ci PRs that need a full CI run. whatwg-url Issues and PRs related to the WHATWG URL implementation. labels Jan 16, 2023
@miguelteixeiraa
Copy link
Contributor Author

hello everyone!
@anonrig I was using nvim with ycm (YouCompleteMe) and I didn't realize it but maybe it was formatting the code automatically when I was saving during development,
make lint-cpp isn't catching these things, so can it go on like this or should I change it to be what it was before?

@anonrig
Copy link
Member

anonrig commented Jan 16, 2023

@miguelteixeiraa please use the following command: CLANG_FORMAT_START=main make format-cpp

@miguelteixeiraa
Copy link
Contributor Author

Done! It hasn't changed that much : /
I can try to make it more like what it was before if that's still an issue.

@anonrig
Copy link
Member

anonrig commented Jan 16, 2023

Yeah, it seems format-cpp is not the correct command. Can you remove the unrelated changes from this pull request? @miguelteixeiraa

@miguelteixeiraa
Copy link
Contributor Author

Of course!

@miguelteixeiraa
Copy link
Contributor Author

Done!

src/node_url.cc Outdated Show resolved Hide resolved
src/node_url.cc Outdated Show resolved Hide resolved
src/node_url.cc Outdated Show resolved Hide resolved
src/node_url.cc Outdated Show resolved Hide resolved
src/node_url.cc Outdated Show resolved Hide resolved
src/node_url.cc Outdated Show resolved Hide resolved
@anonrig anonrig self-assigned this Jan 16, 2023
src/node_url.cc Outdated Show resolved Hide resolved
src/node_url.cc Outdated Show resolved Hide resolved
@anonrig
Copy link
Member

anonrig commented Jan 17, 2023

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

Results
url/legacy-vs-whatwg-url-get-prop.js e=1 method='legacy' type='auth'                                                      0.27 %       ±2.74%  ±3.65%  ±4.75%
url/legacy-vs-whatwg-url-get-prop.js e=1 method='legacy' type='dot'                                                       4.09 %       ±4.47%  ±5.99%  ±7.88%
url/legacy-vs-whatwg-url-get-prop.js e=1 method='legacy' type='file'                                                     -0.55 %       ±3.87%  ±5.16%  ±6.72%
url/legacy-vs-whatwg-url-get-prop.js e=1 method='legacy' type='idn'                                                      -0.88 %       ±2.28%  ±3.03%  ±3.94%
url/legacy-vs-whatwg-url-get-prop.js e=1 method='legacy' type='javascript'                                               -1.69 %       ±3.45%  ±4.60%  ±5.98%
url/legacy-vs-whatwg-url-get-prop.js e=1 method='legacy' type='long'                                                     -2.52 %       ±3.64%  ±4.87%  ±6.40%
url/legacy-vs-whatwg-url-get-prop.js e=1 method='legacy' type='percent'                                                  -0.90 %       ±3.80%  ±5.06%  ±6.59%
url/legacy-vs-whatwg-url-get-prop.js e=1 method='legacy' type='short'                                                    -0.96 %       ±4.62%  ±6.17%  ±8.08%
url/legacy-vs-whatwg-url-get-prop.js e=1 method='legacy' type='wpt'                                                       1.14 %       ±2.08%  ±2.76%  ±3.60%
url/legacy-vs-whatwg-url-get-prop.js e=1 method='legacy' type='ws'                                                        0.45 %       ±2.40%  ±3.19%  ±4.16%
url/legacy-vs-whatwg-url-get-prop.js e=1 method='whatwg' type='auth'                                                     -0.90 %       ±1.27%  ±1.70%  ±2.23%
url/legacy-vs-whatwg-url-get-prop.js e=1 method='whatwg' type='dot'                                                      -1.87 %       ±2.65%  ±3.54%  ±4.63%
url/legacy-vs-whatwg-url-get-prop.js e=1 method='whatwg' type='file'                                                     -2.85 %       ±3.42%  ±4.56%  ±5.96%
url/legacy-vs-whatwg-url-get-prop.js e=1 method='whatwg' type='idn'                                                       0.15 %       ±1.39%  ±1.85%  ±2.42%
url/legacy-vs-whatwg-url-get-prop.js e=1 method='whatwg' type='javascript'                                                0.24 %       ±5.75%  ±7.67% ±10.03%
url/legacy-vs-whatwg-url-get-prop.js e=1 method='whatwg' type='long'                                                      1.06 %       ±2.40%  ±3.20%  ±4.18%
url/legacy-vs-whatwg-url-get-prop.js e=1 method='whatwg' type='percent'                                                   3.71 %       ±4.40%  ±5.87%  ±7.69%
url/legacy-vs-whatwg-url-get-prop.js e=1 method='whatwg' type='short'                                              *      3.04 %       ±2.66%  ±3.58%  ±4.73%
url/legacy-vs-whatwg-url-get-prop.js e=1 method='whatwg' type='wpt'                                                       0.21 %       ±0.90%  ±1.20%  ±1.57%
url/legacy-vs-whatwg-url-get-prop.js e=1 method='whatwg' type='ws'                                                 *     -3.83 %       ±3.13%  ±4.20%  ±5.55%
url/legacy-vs-whatwg-url-parse.js method='legacy' e=1 type='auth' withBase='false'                                       -0.42 %       ±2.96%  ±3.96%  ±5.17%
url/legacy-vs-whatwg-url-parse.js method='legacy' e=1 type='auth' withBase='true'                                         0.18 %       ±2.94%  ±3.91%  ±5.09%
url/legacy-vs-whatwg-url-parse.js method='legacy' e=1 type='dot' withBase='false'                                        -0.87 %       ±3.51%  ±4.67%  ±6.08%
url/legacy-vs-whatwg-url-parse.js method='legacy' e=1 type='dot' withBase='true'                                         -0.40 %       ±2.76%  ±3.68%  ±4.79%
url/legacy-vs-whatwg-url-parse.js method='legacy' e=1 type='file' withBase='false'                                       -1.86 %       ±4.74%  ±6.30%  ±8.20%
url/legacy-vs-whatwg-url-parse.js method='legacy' e=1 type='file' withBase='true'                                        -0.87 %       ±6.11%  ±8.14% ±10.62%
url/legacy-vs-whatwg-url-parse.js method='legacy' e=1 type='idn' withBase='false'                                        -2.87 %       ±4.33%  ±5.76%  ±7.49%
url/legacy-vs-whatwg-url-parse.js method='legacy' e=1 type='idn' withBase='true'                                         -2.18 %       ±3.69%  ±4.91%  ±6.39%
url/legacy-vs-whatwg-url-parse.js method='legacy' e=1 type='javascript' withBase='false'                                  0.56 %       ±5.57%  ±7.40%  ±9.64%
url/legacy-vs-whatwg-url-parse.js method='legacy' e=1 type='javascript' withBase='true'                                   2.96 %       ±7.62% ±10.15% ±13.23%
url/legacy-vs-whatwg-url-parse.js method='legacy' e=1 type='long' withBase='false'                                        0.66 %       ±1.34%  ±1.79%  ±2.33%
url/legacy-vs-whatwg-url-parse.js method='legacy' e=1 type='long' withBase='true'                                        -0.60 %       ±1.51%  ±2.00%  ±2.61%
url/legacy-vs-whatwg-url-parse.js method='legacy' e=1 type='percent' withBase='false'                                     0.14 %       ±4.64%  ±6.18%  ±8.04%
url/legacy-vs-whatwg-url-parse.js method='legacy' e=1 type='percent' withBase='true'                                     -1.50 %       ±4.11%  ±5.48%  ±7.14%
url/legacy-vs-whatwg-url-parse.js method='legacy' e=1 type='short' withBase='false'                               **      4.73 %       ±3.46%  ±4.60%  ±5.99%
url/legacy-vs-whatwg-url-parse.js method='legacy' e=1 type='short' withBase='true'                                        2.02 %       ±3.19%  ±4.25%  ±5.54%
url/legacy-vs-whatwg-url-parse.js method='legacy' e=1 type='wpt' withBase='false'                                        -0.76 %       ±1.04%  ±1.38%  ±1.81%
url/legacy-vs-whatwg-url-parse.js method='legacy' e=1 type='wpt' withBase='true'                                         -0.17 %       ±1.07%  ±1.43%  ±1.86%
url/legacy-vs-whatwg-url-parse.js method='legacy' e=1 type='ws' withBase='false'                                         -0.48 %       ±1.85%  ±2.46%  ±3.20%
url/legacy-vs-whatwg-url-parse.js method='legacy' e=1 type='ws' withBase='true'                                           0.77 %       ±3.22%  ±4.29%  ±5.60%
url/legacy-vs-whatwg-url-parse.js method='whatwg' e=1 type='auth' withBase='false'                               ***     10.62 %       ±5.01%  ±6.67%  ±8.68%
url/legacy-vs-whatwg-url-parse.js method='whatwg' e=1 type='auth' withBase='true'                                 **      6.51 %       ±4.55%  ±6.06%  ±7.90%
url/legacy-vs-whatwg-url-parse.js method='whatwg' e=1 type='dot' withBase='false'                                ***     12.21 %       ±6.36%  ±8.47% ±11.03%
url/legacy-vs-whatwg-url-parse.js method='whatwg' e=1 type='dot' withBase='true'                                  **      9.06 %       ±5.30%  ±7.05%  ±9.18%
url/legacy-vs-whatwg-url-parse.js method='whatwg' e=1 type='file' withBase='false'                                        4.08 %       ±6.44%  ±8.57% ±11.16%
url/legacy-vs-whatwg-url-parse.js method='whatwg' e=1 type='file' withBase='true'                                        -3.04 %       ±5.43%  ±7.23%  ±9.41%
url/legacy-vs-whatwg-url-parse.js method='whatwg' e=1 type='idn' withBase='false'                                 **     10.78 %       ±6.81%  ±9.06% ±11.80%
url/legacy-vs-whatwg-url-parse.js method='whatwg' e=1 type='idn' withBase='true'                                 ***     10.46 %       ±4.88%  ±6.49%  ±8.46%
url/legacy-vs-whatwg-url-parse.js method='whatwg' e=1 type='javascript' withBase='false'                                 -2.47 %       ±6.45%  ±8.58% ±11.17%
url/legacy-vs-whatwg-url-parse.js method='whatwg' e=1 type='javascript' withBase='true'                                   2.89 %       ±5.55%  ±7.39%  ±9.62%
url/legacy-vs-whatwg-url-parse.js method='whatwg' e=1 type='long' withBase='false'                                        5.01 %       ±5.40%  ±7.19%  ±9.37%
url/legacy-vs-whatwg-url-parse.js method='whatwg' e=1 type='long' withBase='true'                                ***     11.50 %       ±3.95%  ±5.26%  ±6.84%
url/legacy-vs-whatwg-url-parse.js method='whatwg' e=1 type='percent' withBase='false'                              *      8.46 %       ±6.38%  ±8.50% ±11.06%
url/legacy-vs-whatwg-url-parse.js method='whatwg' e=1 type='percent' withBase='true'                             ***     11.78 %       ±5.53%  ±7.36%  ±9.58%
url/legacy-vs-whatwg-url-parse.js method='whatwg' e=1 type='short' withBase='false'                              ***     20.33 %       ±6.83%  ±9.09% ±11.83%
url/legacy-vs-whatwg-url-parse.js method='whatwg' e=1 type='short' withBase='true'                                        4.60 %       ±4.63%  ±6.16%  ±8.01%
url/legacy-vs-whatwg-url-parse.js method='whatwg' e=1 type='wpt' withBase='false'                                ***     14.11 %       ±2.15%  ±2.87%  ±3.74%
url/legacy-vs-whatwg-url-parse.js method='whatwg' e=1 type='wpt' withBase='true'                                 ***      5.62 %       ±1.85%  ±2.46%  ±3.21%
url/legacy-vs-whatwg-url-parse.js method='whatwg' e=1 type='ws' withBase='false'                                 ***     16.45 %       ±7.14%  ±9.51% ±12.37%
url/legacy-vs-whatwg-url-parse.js method='whatwg' e=1 type='ws' withBase='true'                                   **      8.74 %       ±5.76%  ±7.66%  ±9.97%
url/legacy-vs-whatwg-url-searchparams-parse.js n=1000000 method='legacy' searchParam='altspaces'                          1.04 %       ±2.32%  ±3.09%  ±4.02%
url/legacy-vs-whatwg-url-searchparams-parse.js n=1000000 method='legacy' searchParam='encodefake'                         0.88 %       ±2.39%  ±3.18%  ±4.14%
url/legacy-vs-whatwg-url-searchparams-parse.js n=1000000 method='legacy' searchParam='encodelast'                         0.46 %       ±3.51%  ±4.68%  ±6.10%
url/legacy-vs-whatwg-url-searchparams-parse.js n=1000000 method='legacy' searchParam='encodemany'                         0.70 %       ±2.54%  ±3.39%  ±4.41%
url/legacy-vs-whatwg-url-searchparams-parse.js n=1000000 method='legacy' searchParam='manyblankpairs'                    -0.07 %       ±3.54%  ±4.73%  ±6.18%
url/legacy-vs-whatwg-url-searchparams-parse.js n=1000000 method='legacy' searchParam='manypairs'                         -1.39 %       ±2.63%  ±3.51%  ±4.60%
url/legacy-vs-whatwg-url-searchparams-parse.js n=1000000 method='legacy' searchParam='multicharsep'                       0.33 %       ±2.64%  ±3.53%  ±4.63%
url/legacy-vs-whatwg-url-searchparams-parse.js n=1000000 method='legacy' searchParam='multivalue'                         0.14 %       ±2.57%  ±3.43%  ±4.49%
url/legacy-vs-whatwg-url-searchparams-parse.js n=1000000 method='legacy' searchParam='multivaluemany'              *     -2.82 %       ±2.44%  ±3.26%  ±4.27%
url/legacy-vs-whatwg-url-searchparams-parse.js n=1000000 method='legacy' searchParam='noencode'                           0.19 %       ±2.25%  ±3.00%  ±3.92%
url/legacy-vs-whatwg-url-searchparams-parse.js n=1000000 method='whatwg' searchParam='altspaces'                          2.11 %       ±2.40%  ±3.19%  ±4.15%
url/legacy-vs-whatwg-url-searchparams-parse.js n=1000000 method='whatwg' searchParam='encodefake'                         0.22 %       ±3.16%  ±4.21%  ±5.48%
url/legacy-vs-whatwg-url-searchparams-parse.js n=1000000 method='whatwg' searchParam='encodelast'                        -0.50 %       ±3.02%  ±4.02%  ±5.23%
url/legacy-vs-whatwg-url-searchparams-parse.js n=1000000 method='whatwg' searchParam='encodemany'                         0.46 %       ±3.34%  ±4.45%  ±5.82%
url/legacy-vs-whatwg-url-searchparams-parse.js n=1000000 method='whatwg' searchParam='manyblankpairs'                     0.17 %       ±6.82%  ±9.08% ±11.82%
url/legacy-vs-whatwg-url-searchparams-parse.js n=1000000 method='whatwg' searchParam='manypairs'                          0.79 %       ±2.23%  ±2.98%  ±3.90%
url/legacy-vs-whatwg-url-searchparams-parse.js n=1000000 method='whatwg' searchParam='multicharsep'                       2.08 %       ±2.64%  ±3.51%  ±4.58%
url/legacy-vs-whatwg-url-searchparams-parse.js n=1000000 method='whatwg' searchParam='multivalue'                        -1.00 %       ±2.29%  ±3.05%  ±3.97%
url/legacy-vs-whatwg-url-searchparams-parse.js n=1000000 method='whatwg' searchParam='multivaluemany'                    -1.06 %       ±2.72%  ±3.62%  ±4.72%
url/legacy-vs-whatwg-url-searchparams-parse.js n=1000000 method='whatwg' searchParam='noencode'                          -0.86 %       ±3.35%  ±4.46%  ±5.80%
url/legacy-vs-whatwg-url-searchparams-serialize.js n=1000000 method='legacy' searchParam='altspaces'                      0.20 %       ±1.35%  ±1.80%  ±2.35%
url/legacy-vs-whatwg-url-searchparams-serialize.js n=1000000 method='legacy' searchParam='encodefake'                     1.77 %       ±2.00%  ±2.67%  ±3.47%
url/legacy-vs-whatwg-url-searchparams-serialize.js n=1000000 method='legacy' searchParam='encodelast'                    -0.48 %       ±3.50%  ±4.65%  ±6.06%
url/legacy-vs-whatwg-url-searchparams-serialize.js n=1000000 method='legacy' searchParam='encodemany'                    -0.64 %       ±1.87%  ±2.51%  ±3.31%
url/legacy-vs-whatwg-url-searchparams-serialize.js n=1000000 method='legacy' searchParam='manyblankpairs'                 5.12 %       ±6.33%  ±8.52% ±11.30%
url/legacy-vs-whatwg-url-searchparams-serialize.js n=1000000 method='legacy' searchParam='manypairs'                     -0.56 %       ±1.80%  ±2.41%  ±3.15%
url/legacy-vs-whatwg-url-searchparams-serialize.js n=1000000 method='legacy' searchParam='multicharsep'                  -0.58 %       ±2.77%  ±3.69%  ±4.80%
url/legacy-vs-whatwg-url-searchparams-serialize.js n=1000000 method='legacy' searchParam='multivalue'                     2.95 %       ±3.34%  ±4.45%  ±5.79%
url/legacy-vs-whatwg-url-searchparams-serialize.js n=1000000 method='legacy' searchParam='multivaluemany'                 0.37 %       ±1.29%  ±1.71%  ±2.23%
url/legacy-vs-whatwg-url-searchparams-serialize.js n=1000000 method='legacy' searchParam='noencode'                       0.96 %       ±1.92%  ±2.56%  ±3.34%
url/legacy-vs-whatwg-url-searchparams-serialize.js n=1000000 method='whatwg' searchParam='altspaces'                      0.73 %       ±2.08%  ±2.77%  ±3.62%
url/legacy-vs-whatwg-url-searchparams-serialize.js n=1000000 method='whatwg' searchParam='encodefake'                     1.21 %       ±2.48%  ±3.30%  ±4.31%
url/legacy-vs-whatwg-url-searchparams-serialize.js n=1000000 method='whatwg' searchParam='encodelast'                    -1.40 %       ±4.39%  ±5.84%  ±7.61%
url/legacy-vs-whatwg-url-searchparams-serialize.js n=1000000 method='whatwg' searchParam='encodemany'                     3.34 %       ±3.45%  ±4.59%  ±5.98%
url/legacy-vs-whatwg-url-searchparams-serialize.js n=1000000 method='whatwg' searchParam='manyblankpairs'                -0.32 %       ±3.17%  ±4.22%  ±5.49%
url/legacy-vs-whatwg-url-searchparams-serialize.js n=1000000 method='whatwg' searchParam='manypairs'                     -0.66 %       ±1.12%  ±1.49%  ±1.95%
url/legacy-vs-whatwg-url-searchparams-serialize.js n=1000000 method='whatwg' searchParam='multicharsep'                   2.62 %       ±3.85%  ±5.13%  ±6.70%
url/legacy-vs-whatwg-url-searchparams-serialize.js n=1000000 method='whatwg' searchParam='multivalue'              *     -3.59 %       ±3.06%  ±4.08%  ±5.33%
url/legacy-vs-whatwg-url-searchparams-serialize.js n=1000000 method='whatwg' searchParam='multivaluemany'                 0.92 %       ±1.76%  ±2.34%  ±3.05%
url/legacy-vs-whatwg-url-searchparams-serialize.js n=1000000 method='whatwg' searchParam='noencode'                       3.73 %       ±4.05%  ±5.40%  ±7.07%
url/legacy-vs-whatwg-url-serialize.js e=1 method='legacy' type='auth'                                                    -3.02 %       ±9.63% ±12.81% ±16.68%
url/legacy-vs-whatwg-url-serialize.js e=1 method='legacy' type='dot'                                                     -3.07 %      ±10.33% ±13.75% ±17.90%
url/legacy-vs-whatwg-url-serialize.js e=1 method='legacy' type='file'                                                     4.93 %      ±10.35% ±13.77% ±17.92%
url/legacy-vs-whatwg-url-serialize.js e=1 method='legacy' type='idn'                                                      6.37 %      ±10.02% ±13.33% ±17.36%
url/legacy-vs-whatwg-url-serialize.js e=1 method='legacy' type='javascript'                                               3.60 %      ±10.12% ±13.46% ±17.53%
url/legacy-vs-whatwg-url-serialize.js e=1 method='legacy' type='long'                                                    -0.73 %       ±9.21% ±12.25% ±15.95%
url/legacy-vs-whatwg-url-serialize.js e=1 method='legacy' type='percent'                                                  2.81 %       ±8.27% ±11.01% ±14.35%
url/legacy-vs-whatwg-url-serialize.js e=1 method='legacy' type='short'                                            **    -11.48 %       ±8.16% ±10.88% ±14.20%
url/legacy-vs-whatwg-url-serialize.js e=1 method='legacy' type='wpt'                                                      0.03 %       ±3.33%  ±4.46%  ±5.85%
url/legacy-vs-whatwg-url-serialize.js e=1 method='legacy' type='ws'                                                       3.65 %       ±9.66% ±12.85% ±16.73%
url/legacy-vs-whatwg-url-serialize.js e=1 method='whatwg' type='auth'                                                    -6.70 %       ±9.63% ±12.82% ±16.68%
url/legacy-vs-whatwg-url-serialize.js e=1 method='whatwg' type='dot'                                                      2.12 %      ±10.86% ±14.44% ±18.80%
url/legacy-vs-whatwg-url-serialize.js e=1 method='whatwg' type='file'                                                     1.08 %      ±10.48% ±13.95% ±18.16%
url/legacy-vs-whatwg-url-serialize.js e=1 method='whatwg' type='idn'                                                      2.94 %       ±9.27% ±12.33% ±16.05%
url/legacy-vs-whatwg-url-serialize.js e=1 method='whatwg' type='javascript'                                               8.10 %       ±8.71% ±11.61% ±15.16%
url/legacy-vs-whatwg-url-serialize.js e=1 method='whatwg' type='long'                                                    -6.84 %       ±9.92% ±13.21% ±17.19%
url/legacy-vs-whatwg-url-serialize.js e=1 method='whatwg' type='percent'                                                  0.99 %       ±8.42% ±11.20% ±14.59%
url/legacy-vs-whatwg-url-serialize.js e=1 method='whatwg' type='short'                                                   -4.84 %       ±9.68% ±12.88% ±16.77%
url/legacy-vs-whatwg-url-serialize.js e=1 method='whatwg' type='wpt'                                                      1.07 %       ±2.14%  ±2.85%  ±3.72%
url/legacy-vs-whatwg-url-serialize.js e=1 method='whatwg' type='ws'                                                      -6.14 %      ±10.33% ±13.75% ±17.90%
url/url-format.js n=25000000 type='file'                                                                                  1.62 %       ±2.11%  ±2.81%  ±3.67%
url/url-format.js n=25000000 type='slashes'                                                                               0.42 %       ±1.14%  ±1.53%  ±1.99%
url/url-parse.js n=10000000 type='escaped'                                                                               -1.73 %       ±2.45%  ±3.26%  ±4.25%
url/url-parse.js n=10000000 type='normal'                                                                                 1.66 %       ±2.97%  ±3.96%  ±5.15%
url/url-resolve.js n=100000 path='down' href='auth'                                                                       0.24 %       ±3.04%  ±4.05%  ±5.27%
url/url-resolve.js n=100000 path='down' href='dot'                                                                       -0.47 %       ±2.42%  ±3.23%  ±4.21%
url/url-resolve.js n=100000 path='down' href='file'                                                                       1.33 %       ±2.96%  ±3.94%  ±5.13%
url/url-resolve.js n=100000 path='down' href='idn'                                                                 *     -3.15 %       ±3.06%  ±4.08%  ±5.33%
url/url-resolve.js n=100000 path='down' href='javascript'                                                                -1.35 %       ±2.59%  ±3.45%  ±4.49%
url/url-resolve.js n=100000 path='down' href='long'                                                                      -0.21 %       ±2.38%  ±3.17%  ±4.12%
url/url-resolve.js n=100000 path='down' href='noscheme'                                                                  -0.78 %       ±3.43%  ±4.56%  ±5.95%
url/url-resolve.js n=100000 path='down' href='percent'                                                             *     -2.79 %       ±2.14%  ±2.85%  ±3.72%
url/url-resolve.js n=100000 path='down' href='short'                                                                     -1.25 %       ±3.38%  ±4.49%  ±5.85%
url/url-resolve.js n=100000 path='down' href='ws'                                                                        -1.95 %       ±2.61%  ±3.48%  ±4.53%
url/url-resolve.js n=100000 path='foo/bar' href='auth'                                                                   -0.80 %       ±3.58%  ±4.77%  ±6.23%
url/url-resolve.js n=100000 path='foo/bar' href='dot'                                                                    -0.88 %       ±2.93%  ±3.90%  ±5.07%
url/url-resolve.js n=100000 path='foo/bar' href='file'                                                                    0.62 %       ±2.84%  ±3.78%  ±4.92%
url/url-resolve.js n=100000 path='foo/bar' href='idn'                                                              *     -3.29 %       ±3.02%  ±4.02%  ±5.24%
url/url-resolve.js n=100000 path='foo/bar' href='javascript'                                                             -0.16 %       ±3.43%  ±4.57%  ±5.94%
url/url-resolve.js n=100000 path='foo/bar' href='long'                                                                   -0.20 %       ±2.37%  ±3.15%  ±4.11%
url/url-resolve.js n=100000 path='foo/bar' href='noscheme'                                                               -1.64 %       ±3.54%  ±4.71%  ±6.14%
url/url-resolve.js n=100000 path='foo/bar' href='percent'                                                         **     -3.89 %       ±2.29%  ±3.05%  ±3.97%
url/url-resolve.js n=100000 path='foo/bar' href='short'                                                                  -2.38 %       ±3.21%  ±4.27%  ±5.57%
url/url-resolve.js n=100000 path='foo/bar' href='ws'                                                                     -2.62 %       ±3.67%  ±4.89%  ±6.38%
url/url-resolve.js n=100000 path='sibling' href='auth'                                                                   -2.29 %       ±3.36%  ±4.48%  ±5.83%
url/url-resolve.js n=100000 path='sibling' href='dot'                                                                    -2.23 %       ±2.87%  ±3.82%  ±4.97%
url/url-resolve.js n=100000 path='sibling' href='file'                                                                   -0.84 %       ±2.67%  ±3.56%  ±4.67%
url/url-resolve.js n=100000 path='sibling' href='idn'                                                                    -3.42 %       ±3.58%  ±4.76%  ±6.20%
url/url-resolve.js n=100000 path='sibling' href='javascript'                                                              0.36 %       ±3.30%  ±4.39%  ±5.72%
url/url-resolve.js n=100000 path='sibling' href='long'                                                                   -0.33 %       ±3.06%  ±4.08%  ±5.31%
url/url-resolve.js n=100000 path='sibling' href='noscheme'                                                               -1.71 %       ±3.32%  ±4.42%  ±5.77%
url/url-resolve.js n=100000 path='sibling' href='percent'                                                                -0.63 %       ±2.78%  ±3.71%  ±4.83%
url/url-resolve.js n=100000 path='sibling' href='short'                                                                  -1.07 %       ±3.41%  ±4.56%  ±5.96%
url/url-resolve.js n=100000 path='sibling' href='ws'                                                                     -0.81 %       ±2.58%  ±3.43%  ±4.47%
url/url-resolve.js n=100000 path='up' href='auth'                                                                         0.76 %       ±2.75%  ±3.67%  ±4.78%
url/url-resolve.js n=100000 path='up' href='dot'                                                                         -0.76 %       ±1.90%  ±2.53%  ±3.30%
url/url-resolve.js n=100000 path='up' href='file'                                                                         0.85 %       ±2.78%  ±3.70%  ±4.82%
url/url-resolve.js n=100000 path='up' href='idn'                                                                  **     -3.77 %       ±2.81%  ±3.74%  ±4.87%
url/url-resolve.js n=100000 path='up' href='javascript'                                                                   0.43 %       ±3.16%  ±4.21%  ±5.48%
url/url-resolve.js n=100000 path='up' href='long'                                                                 **      2.40 %       ±1.73%  ±2.31%  ±3.00%
url/url-resolve.js n=100000 path='up' href='noscheme'                                                                     0.84 %       ±2.70%  ±3.59%  ±4.69%
url/url-resolve.js n=100000 path='up' href='percent'                                                                     -0.80 %       ±2.55%  ±3.39%  ±4.42%
url/url-resolve.js n=100000 path='up' href='short'                                                                       -1.18 %       ±3.71%  ±4.94%  ±6.43%
url/url-resolve.js n=100000 path='up' href='ws'                                                                          -1.44 %       ±2.70%  ±3.60%  ±4.68%
url/url-resolve.js n=100000 path='withscheme' href='auth'                                                                 0.75 %       ±2.51%  ±3.34%  ±4.35%
url/url-resolve.js n=100000 path='withscheme' href='dot'                                                                  2.05 %       ±2.93%  ±3.90%  ±5.10%
url/url-resolve.js n=100000 path='withscheme' href='file'                                                                -0.08 %       ±2.55%  ±3.40%  ±4.46%
url/url-resolve.js n=100000 path='withscheme' href='idn'                                                                 -0.14 %       ±2.66%  ±3.54%  ±4.61%
url/url-resolve.js n=100000 path='withscheme' href='javascript'                                                           0.78 %       ±3.93%  ±5.23%  ±6.81%
url/url-resolve.js n=100000 path='withscheme' href='long'                                                                 1.02 %       ±2.03%  ±2.70%  ±3.51%
url/url-resolve.js n=100000 path='withscheme' href='noscheme'                                                            -0.04 %       ±4.26%  ±5.66%  ±7.37%
url/url-resolve.js n=100000 path='withscheme' href='percent'                                                              2.59 %       ±2.81%  ±3.74%  ±4.86%
url/url-resolve.js n=100000 path='withscheme' href='short'                                                                0.99 %       ±3.14%  ±4.18%  ±5.45%
url/url-resolve.js n=100000 path='withscheme' href='ws'                                                                   1.59 %       ±2.77%  ±3.68%  ±4.79%
url/url-searchparams-iteration.js n=1000000 loopMethod='forEach'                                                         -8.10 %       ±8.41% ±11.21% ±14.63%
url/url-searchparams-iteration.js n=1000000 loopMethod='iterator'                                                         0.28 %       ±3.36%  ±4.48%  ±5.85%
url/url-searchparams-read.js n=20000000 param='nonexistent' accessMethod='get'                                            0.48 %       ±2.35%  ±3.14%  ±4.11%
url/url-searchparams-read.js n=20000000 param='nonexistent' accessMethod='getAll'                                  *     -3.12 %       ±3.00%  ±4.01%  ±5.25%
url/url-searchparams-read.js n=20000000 param='nonexistent' accessMethod='has'                                           -2.25 %       ±2.30%  ±3.07%  ±4.00%
url/url-searchparams-read.js n=20000000 param='one' accessMethod='get'                                                   -0.47 %       ±2.07%  ±2.76%  ±3.59%
url/url-searchparams-read.js n=20000000 param='one' accessMethod='getAll'                                                 1.29 %       ±1.90%  ±2.53%  ±3.30%
url/url-searchparams-read.js n=20000000 param='one' accessMethod='has'                                                   -0.57 %       ±3.05%  ±4.06%  ±5.29%
url/url-searchparams-read.js n=20000000 param='three' accessMethod='get'                                                 -0.36 %       ±2.13%  ±2.84%  ±3.71%
url/url-searchparams-read.js n=20000000 param='three' accessMethod='getAll'                                              -1.39 %       ±2.51%  ±3.34%  ±4.37%
url/url-searchparams-read.js n=20000000 param='three' accessMethod='has'                                                  0.45 %       ±2.60%  ±3.46%  ±4.51%
url/url-searchparams-read.js n=20000000 param='two' accessMethod='get'                                                   -0.20 %       ±2.75%  ±3.68%  ±4.83%
url/url-searchparams-read.js n=20000000 param='two' accessMethod='getAll'                                                -1.05 %       ±2.18%  ±2.91%  ±3.82%
url/url-searchparams-read.js n=20000000 param='two' accessMethod='has'                                                    0.58 %       ±3.14%  ±4.17%  ±5.44%
url/url-searchparams-sort.js n=1000000 type='almostsorted'                                                                1.42 %       ±2.36%  ±3.13%  ±4.08%
url/url-searchparams-sort.js n=1000000 type='empty'                                                                       0.69 %       ±4.69%  ±6.24%  ±8.13%
url/url-searchparams-sort.js n=1000000 type='long'                                                                **     -2.99 %       ±2.02%  ±2.70%  ±3.53%
url/url-searchparams-sort.js n=1000000 type='random'                                                                     -0.90 %       ±1.28%  ±1.71%  ±2.23%
url/url-searchparams-sort.js n=1000000 type='reversed'                                                                   -1.46 %       ±2.35%  ±3.16%  ±4.16%
url/url-searchparams-sort.js n=1000000 type='short'                                                                *      4.12 %       ±3.91%  ±5.23%  ±6.87%
url/url-searchparams-sort.js n=1000000 type='sorted'                                                                      1.39 %       ±3.12%  ±4.15%  ±5.41%
url/url-searchparams-sort.js n=1000000 type='wpt'                                                                         2.46 %       ±3.96%  ±5.33%  ±7.06%
url/usvstring.js n=50000000 input='allinvalid'                                                                    **     -3.93 %       ±2.59%  ±3.46%  ±4.51%
url/usvstring.js n=50000000 input='nonstring'                                                                      *      3.14 %       ±2.83%  ±3.78%  ±4.95%
url/usvstring.js n=50000000 input='someinvalid'                                                                           0.84 %       ±2.62%  ±3.49%  ±4.54%
url/usvstring.js n=50000000 input='valid'                                                                                -1.71 %       ±2.25%  ±3.02%  ±4.00%
url/usvstring.js n=50000000 input='validsurr'                                                                             0.11 %       ±2.16%  ±2.88%  ±3.76%
url/whatwg-url-idna.js n=5000000 to='ascii' domain='all'                                                         ***     37.77 %       ±2.99%  ±3.98%  ±5.18%
url/whatwg-url-idna.js n=5000000 to='ascii' domain='empty'                                                                2.62 %       ±2.92%  ±3.88%  ±5.06%
url/whatwg-url-idna.js n=5000000 to='ascii' domain='none'                                                        ***     75.96 %       ±7.20%  ±9.64% ±12.67%
url/whatwg-url-idna.js n=5000000 to='ascii' domain='nonstring'                                                            1.24 %       ±1.83%  ±2.44%  ±3.17%
url/whatwg-url-idna.js n=5000000 to='ascii' domain='some'                                                        ***     48.65 %       ±4.61%  ±6.14%  ±7.99%
url/whatwg-url-idna.js n=5000000 to='unicode' domain='all'                                                       ***     18.40 %       ±3.26%  ±4.38%  ±5.76%
url/whatwg-url-idna.js n=5000000 to='unicode' domain='empty'                                                             -1.45 %       ±3.80%  ±5.05%  ±6.58%
url/whatwg-url-idna.js n=5000000 to='unicode' domain='none'                                                      ***     58.41 %       ±7.02%  ±9.40% ±12.36%
url/whatwg-url-idna.js n=5000000 to='unicode' domain='nonstring'                                                 ***      3.56 %       ±1.67%  ±2.22%  ±2.89%
url/whatwg-url-idna.js n=5000000 to='unicode' domain='some'                                                      ***     24.97 %       ±3.96%  ±5.29%  ±6.92%
url/whatwg-url-properties.js prop='hash' e=1 type='wpt' withBase='false'                                                 -0.37 %       ±1.87%  ±2.49%  ±3.24%
url/whatwg-url-properties.js prop='hash' e=1 type='wpt' withBase='true'                                                  -0.26 %       ±2.57%  ±3.42%  ±4.47%
url/whatwg-url-properties.js prop='host' e=1 type='wpt' withBase='false'                                         ***     16.52 %       ±2.93%  ±3.91%  ±5.11%
url/whatwg-url-properties.js prop='host' e=1 type='wpt' withBase='true'                                          ***     12.42 %       ±2.88%  ±3.85%  ±5.05%
url/whatwg-url-properties.js prop='hostname' e=1 type='wpt' withBase='false'                                     ***     21.44 %       ±5.09%  ±6.79%  ±8.89%
url/whatwg-url-properties.js prop='hostname' e=1 type='wpt' withBase='true'                                      ***     13.59 %       ±2.50%  ±3.32%  ±4.32%
url/whatwg-url-properties.js prop='href' e=1 type='wpt' withBase='false'                                         ***      7.99 %       ±3.08%  ±4.10%  ±5.35%
url/whatwg-url-properties.js prop='href' e=1 type='wpt' withBase='true'                                          ***     10.43 %       ±2.44%  ±3.25%  ±4.25%
url/whatwg-url-properties.js prop='origin' e=1 type='wpt' withBase='false'                                                0.89 %       ±3.12%  ±4.17%  ±5.46%
url/whatwg-url-properties.js prop='origin' e=1 type='wpt' withBase='true'                                         **      3.30 %       ±2.39%  ±3.19%  ±4.15%
url/whatwg-url-properties.js prop='password' e=1 type='wpt' withBase='false'                                             -0.17 %       ±2.60%  ±3.46%  ±4.51%
url/whatwg-url-properties.js prop='password' e=1 type='wpt' withBase='true'                                               1.51 %       ±2.97%  ±3.96%  ±5.15%
url/whatwg-url-properties.js prop='pathname' e=1 type='wpt' withBase='false'                                             -0.73 %       ±3.15%  ±4.19%  ±5.46%
url/whatwg-url-properties.js prop='pathname' e=1 type='wpt' withBase='true'                                              -2.68 %       ±2.87%  ±3.82%  ±4.97%
url/whatwg-url-properties.js prop='port' e=1 type='wpt' withBase='false'                                                  0.11 %       ±1.94%  ±2.58%  ±3.36%
url/whatwg-url-properties.js prop='port' e=1 type='wpt' withBase='true'                                                  -0.73 %       ±1.94%  ±2.58%  ±3.36%
url/whatwg-url-properties.js prop='protocol' e=1 type='wpt' withBase='false'                                              1.12 %       ±3.32%  ±4.42%  ±5.76%
url/whatwg-url-properties.js prop='protocol' e=1 type='wpt' withBase='true'                                               0.99 %       ±2.47%  ±3.29%  ±4.29%
url/whatwg-url-properties.js prop='search' e=1 type='wpt' withBase='false'                                                0.54 %       ±3.74%  ±5.01%  ±6.58%
url/whatwg-url-properties.js prop='search' e=1 type='wpt' withBase='true'                                                 0.44 %       ±1.79%  ±2.38%  ±3.09%
url/whatwg-url-properties.js prop='searchParams' e=1 type='wpt' withBase='false'                                          1.77 %       ±3.52%  ±4.69%  ±6.12%
url/whatwg-url-properties.js prop='searchParams' e=1 type='wpt' withBase='true'                                           0.32 %       ±1.97%  ±2.63%  ±3.43%
url/whatwg-url-properties.js prop='username' e=1 type='wpt' withBase='false'                                             -0.28 %       ±2.11%  ±2.80%  ±3.65%
url/whatwg-url-properties.js prop='username' e=1 type='wpt' withBase='true'                                        *      2.68 %       ±2.40%  ±3.20%  ±4.17%

@anonrig anonrig added the request-ci Add this label to start a Jenkins CI on a PR. label Jan 17, 2023
@anonrig anonrig requested a review from jasnell January 17, 2023 14:15
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jan 17, 2023
@nodejs-github-bot
Copy link
Collaborator

@miguelteixeiraa
Copy link
Contributor Author

Okay, windows problems.. not sure what it is but I'm checking

src/node_url.cc Outdated
}

char delimiter = '.';
auto pointer_start = input.begin();
Copy link
Member

Choose a reason for hiding this comment

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

If you use std::string_view::iterator it might solve the issues related to std::string_view construct on windows.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Windows build is still failing : /

D:\a\node\node\src\node_url.cc(465,66): error C2440: '<function-style-cast>': cannot convert from 'initializer list' to 'std::string_view' [D:\a\node\node\libnode.vcxproj]
D:\a\node\node\src\node_url.cc(465,66): message : No constructor could take the source type, or constructor overload resolution was ambiguous [D:\a\node\node\libnode.vcxproj]
  node_util.cc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I would like to know if I can go with &(*it); again

Copy link
Member

Choose a reason for hiding this comment

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

@addaleax any recommendations?

Copy link
Contributor Author

@miguelteixeiraa miguelteixeiraa Jan 18, 2023

Choose a reason for hiding this comment

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

it'd look like this:
std::string_view(&(*pointer_start), pointer_end - pointer_start));
just to make the build pass on windows

Copy link
Contributor Author

@miguelteixeiraa miguelteixeiraa Jan 18, 2023

Choose a reason for hiding this comment

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

What i understand is that iterators don't need to be pointers although they could be implemented as one. And some implementations of the STL (MSVC++, Mingw) implement interators with special classes (with no pre-difined casts to pointer), so that we cannot use them directly in the string_view constructor that we are using, which needs a charT*.

then we could use * which is overloaded to do what logically mean: convert the iterator type to its pointed-to object, then pass the address of this &(*it).

https://en.cppreference.com/w/cpp/named_req/RandomAccessIterator
https://stackoverflow.com/questions/32654108/c-stdvectoriterator-is-not-a-pointer-why/64910815#64910815

src/node_url.cc Outdated

return false;
return IsIPv4NumberValid(
std::string_view(&*pointer_start, pointer_end - pointer_start));
Copy link
Member

Choose a reason for hiding this comment

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

This is too hacky (even if it's guaranteed safe).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

removed!

Copy link
Contributor Author

@miguelteixeiraa miguelteixeiraa Jan 18, 2023

Choose a reason for hiding this comment

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

I'll try a static_cast<const char*>

Copy link
Member

Choose a reason for hiding this comment

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

@nodejs/cpp-reviewers any recommendations?

Copy link
Member

Choose a reason for hiding this comment

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

Yeah: I would definitely recommeng to go back to the original "hacky" implementation. It works and looks correct, even if it is not visually pretty. (I'd also not call this pointer if it's an iterator.) const_cast<char*>(pointer_start) doesn't even really make sense since the string_view constructor takes a const char* argument.

Copy link
Contributor Author

@miguelteixeiraa miguelteixeiraa Jan 18, 2023

Choose a reason for hiding this comment

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

Yes, I think it only works on the other compilers because their implementations for the iterator are:
std::string_view::iterator' (aka 'const char *')
(I purposely caused an error to catch this 'aka' haha)

src/node_url.cc Outdated Show resolved Hide resolved
src/node_url.cc Outdated Show resolved Hide resolved
@miguelteixeiraa
Copy link
Contributor Author

microbench:

cpu: Apple M1 Pro
runtime: node v19.4.0 (arm64-darwin)
new URL("http://www.hello.bench") x 100. 938.18 ns/iter (min -> 927.48 ns … max -> 1.01 µs)

runtime: node v20.0.0-pre (arm64-darwin) -- with this PR --
new URL("http://www.hello.bench") x 100. 758.47 ns/iter (min -> 748.85 ns … max -> 795.28 ns)

@anonrig anonrig added review wanted PRs that need reviews. request-ci Add this label to start a Jenkins CI on a PR. labels Jan 20, 2023
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jan 20, 2023
@nodejs-github-bot
Copy link
Collaborator

@RafaelGSS
Copy link
Member

microbench:

cpu: Apple M1 Pro runtime: node v19.4.0 (arm64-darwin) new URL("http://www.hello.bench") x 100. 938.18 ns/iter (min -> 927.48 ns … max -> 1.01 µs)

runtime: node v20.0.0-pre (arm64-darwin) -- with this PR -- new URL("http://www.hello.bench") x 100. 758.47 ns/iter (min -> 748.85 ns … max -> 795.28 ns)

Are you measuring production build against development build?

@miguelteixeiraa
Copy link
Contributor Author

miguelteixeiraa commented Jan 20, 2023

Thinking a little more, the microbench doesnt seem a good idea anymore. Sorry for that. Please just ignore (but yes, I guess I am)

@nodejs-github-bot
Copy link
Collaborator

@anonrig anonrig added the commit-queue Add this label to land a pull request using GitHub Actions. label Jan 23, 2023
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jan 23, 2023
@nodejs-github-bot nodejs-github-bot merged commit 762a3a8 into nodejs:main Jan 23, 2023
@nodejs-github-bot
Copy link
Collaborator

Landed in 762a3a8

ruyadorno pushed a commit that referenced this pull request Feb 1, 2023
Removes the use of vector in EndsInANumber and uses
IsIPv4NumberValid instead of parsing the number to check
if it is valid.

Fixes: nodejs/performance#36
Refs: ada-url/ada#36
PR-URL: #46227
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@ruyadorno ruyadorno mentioned this pull request Feb 1, 2023
juanarbol pushed a commit that referenced this pull request Mar 3, 2023
Removes the use of vector in EndsInANumber and uses
IsIPv4NumberValid instead of parsing the number to check
if it is valid.

Fixes: nodejs/performance#36
Refs: ada-url/ada#36
PR-URL: #46227
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@juanarbol juanarbol mentioned this pull request Mar 3, 2023
juanarbol pushed a commit that referenced this pull request Mar 5, 2023
Removes the use of vector in EndsInANumber and uses
IsIPv4NumberValid instead of parsing the number to check
if it is valid.

Fixes: nodejs/performance#36
Refs: ada-url/ada#36
PR-URL: #46227
Reviewed-By: Yagiz Nizipli <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
Reviewed-By: James M Snell <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c++ Issues and PRs that require attention from people who are familiar with C++. commit-queue-squash Add this label to instruct the Commit Queue to squash all the PR commits into the first one. needs-ci PRs that need a full CI run. review wanted PRs that need reviews. whatwg-url Issues and PRs related to the WHATWG URL implementation.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Do not parse numbers on url parsers - ipv4
7 participants