-
Notifications
You must be signed in to change notification settings - Fork 566
perf: improve tldts.getDomain
speed
#1936
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
base: master
Are you sure you want to change the base?
Conversation
}; | ||
|
||
export const getDomain = url => getDomain_(url, getDomainSharedOpts); | ||
export const getPublicSuffix = url => getPublicSuffix_(url, getPublicSuffixSharedOpts); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICT the same options can be used for both functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICT it can't be invalid because it's extracted as dot-separated valid sequence via ((?:\.[-\w]+)+)/
or (|(?:\.[-\w]+)+)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tophf Exactly! Using regex can not ensure whether the input is a valid domain or not, thus extra check from tldts
is required!
Also, the option will affect how tldts
handles the invalid TLD:
https://runkit.com/sukkaw/652d2ea9557abc00083e0209
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, my point is that our regex is guaranteed to extract a valid sequence because it's applied to an actual URL, not to an arbitrary input.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also note that optimizing getDomain is pointless performance-wise as we use it only when showing the popup and when the user creates a new script for the tab.
Address suggestions from @remusao (#1883 (comment)).
Update
getDomainSharedOpts
forgetDomain
as inputs are known to be valid hostnames.The
getPublicSuffix
still uses the old options, asgetPublicSuffix
is only used in unit test cases and inputs can be invalid.