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

perf: avoid domainToAscii on pure lowercase ascii cases #67

Merged
merged 2 commits into from
Aug 18, 2023

Conversation

Uzlopak
Copy link
Contributor

@Uzlopak Uzlopak commented Jul 30, 2023

before:

fast-uri: parse domain x 691,379 ops/sec ±0.47% (94 runs sampled)
urijs: parse domain x 316,209 ops/sec ±0.41% (95 runs sampled)
WHATWG URL: parse domain x 2,326,414 ops/sec ±0.33% (90 runs sampled)
fast-uri: parse IPv4 x 1,658,275 ops/sec ±0.25% (96 runs sampled)
urijs: parse IPv4 x 277,154 ops/sec ±0.95% (93 runs sampled)
fast-uri: parse IPv6 x 707,699 ops/sec ±0.29% (95 runs sampled)
urijs: parse IPv6 x 210,365 ops/sec ±1.34% (91 runs sampled)
fast-uri: parse URN x 1,682,084 ops/sec ±0.25% (96 runs sampled)
urijs: parse URN x 813,089 ops/sec ±0.24% (94 runs sampled)
WHATWG URL: parse URN x 3,321,670 ops/sec ±0.30% (91 runs sampled)
fast-uri: parse URN uuid x 1,175,383 ops/sec ±0.26% (94 runs sampled)
urijs: parse URN uuid x 604,137 ops/sec ±0.24% (92 runs sampled)
fast-uri: serialize uri x 945,225 ops/sec ±0.80% (95 runs sampled)
urijs: serialize uri x 284,622 ops/sec ±0.30% (92 runs sampled)
fast-uri: serialize IPv6 x 337,427 ops/sec ±0.66% (94 runs sampled)
urijs: serialize IPv6 x 183,875 ops/sec ±0.61% (96 runs sampled)
fast-uri: serialize ws x 902,500 ops/sec ±0.23% (96 runs sampled)
urijs: serialize ws x 253,735 ops/sec ±0.21% (94 runs sampled)
fast-uri: resolve x 249,328 ops/sec ±0.66% (95 runs sampled)
urijs: resolve x 164,304 ops/sec ±0.20% (97 runs sampled)

after:

fast-uri: parse domain x 1,180,480 ops/sec ±0.34% (90 runs sampled)
urijs: parse domain x 322,980 ops/sec ±0.17% (97 runs sampled)
WHATWG URL: parse domain x 2,340,656 ops/sec ±0.34% (94 runs sampled)
fast-uri: parse IPv4 x 1,594,761 ops/sec ±0.67% (93 runs sampled)
urijs: parse IPv4 x 273,783 ops/sec ±0.96% (95 runs sampled)
fast-uri: parse IPv6 x 691,538 ops/sec ±0.25% (88 runs sampled)
urijs: parse IPv6 x 214,914 ops/sec ±1.48% (93 runs sampled)
fast-uri: parse URN x 1,815,279 ops/sec ±0.25% (96 runs sampled)
urijs: parse URN x 863,531 ops/sec ±0.20% (95 runs sampled)
WHATWG URL: parse URN x 3,293,837 ops/sec ±0.30% (93 runs sampled)
fast-uri: parse URN uuid x 1,216,795 ops/sec ±0.21% (95 runs sampled)
urijs: parse URN uuid x 628,702 ops/sec ±0.18% (95 runs sampled)
fast-uri: serialize uri x 952,087 ops/sec ±0.61% (94 runs sampled)
urijs: serialize uri x 283,889 ops/sec ±0.35% (94 runs sampled)
fast-uri: serialize IPv6 x 338,960 ops/sec ±0.80% (96 runs sampled)
urijs: serialize IPv6 x 180,274 ops/sec ±0.58% (96 runs sampled)
fast-uri: serialize ws x 938,850 ops/sec ±0.29% (94 runs sampled)
urijs: serialize ws x 255,779 ops/sec ±0.21% (96 runs sampled)
fast-uri: resolve x 241,644 ops/sec ±1.24% (93 runs sampled)
urijs: resolve x 159,649 ops/sec ±1.25% (89 runs sampled)

Only thing i want to note:
nodes own: URL.domainToAscii('1') returns '0.0.0.1', the same for URL.domainToAscii('11') returns '0.0.0.11',
So basically transforms the decimal notation to the dot notation. Is this neglectable?

Checklist

@Uzlopak Uzlopak requested a review from zekth July 30, 2023 16:39
@zekth
Copy link
Member

zekth commented Jul 30, 2023

Are we testing this branch in the tests? I'm not sure 🤔

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.

lgtm

@zekth
Copy link
Member

zekth commented Aug 14, 2023

nodes own: URL.domainToAscii('1') returns '0.0.0.1', the same for URL.domainToAscii('11') returns '0.0.0.11',
So basically transforms the decimal notation to the dot notation. Is this neglectable?

I'd say yes.

Can regex be replaced by just a cursor on the string? We tried to remove the maximum of regex from the original codebase

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Aug 14, 2023

Can regex be replaced by just a cursor on the string? We tried to remove the maximum of regex from the original codebase

I have no clue what you mean with "just a cursor on the string".

Do you want to iterate over the string?

@zekth
Copy link
Member

zekth commented Aug 15, 2023

Yes, sometimes it's faster. Really depends on the case.

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Aug 15, 2023

Something like

const hexLookUp = Array.from({ length: 256 }, (v, k) => /[^!"$&'()*+,.;=_`a-z{}~-]/.test(String.fromCharCode(k)))

function nonSimpleDomain (value) {
  let code = 0
  for (var i = 0, len = value.length; i < len; ++i) {
    code = value.charCodeAt(i)
    if (code > 255 || hexLookUp[code]) {
      return true
    }
  }
  return false
}

@zekth
Copy link
Member

zekth commented Aug 15, 2023

Yup!

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Aug 15, 2023

@zekth
PTAL

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.

lgtm

Copy link
Member

@zekth zekth left a comment

Choose a reason for hiding this comment

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

LGTM

(sorry for the late review)

@zekth zekth merged commit 51e27a0 into main Aug 18, 2023
25 checks passed
@zekth zekth deleted the perf-domain-host branch August 18, 2023 08:46
@Uzlopak
Copy link
Contributor Author

Uzlopak commented Aug 18, 2023

@zekth if Numbers are neglectable, we could add numbers to the lookup

@zekth
Copy link
Member

zekth commented Aug 18, 2023

we might also add capital letters A-Z don't you think?

@Uzlopak
Copy link
Contributor Author

Uzlopak commented Aug 18, 2023

Let me investigate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants