8000 perf: improve `tldts.getDomain` speed by SukkaW · Pull Request #1936 · violentmonkey/violentmonkey · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

SukkaW
Copy link
Contributor
@SukkaW SukkaW commented Oct 16, 2023

Address suggestions from @remusao (#1883 (comment)).

Update getDomainSharedOpts for getDomain as inputs are known to be valid hostnames.

The getPublicSuffix still uses the old options, as getPublicSuffix is only used in unit test cases and inputs can be invalid.

};

export const getDomain = url => getDomain_(url, getDomainSharedOpts);
export const getPublicSuffix = url => getPublicSuffix_(url, getPublicSuffixSharedOpts);
Copy link
Member

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.

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 am worrying about the getPublicSuffix case here:

image image

The input of getPublicSuffix can be invalid IMHO.

Copy link
Member

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]+)+)

Copy link
Contributor Author

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

image

Copy link
Member
@tophf tophf Oct 16, 2023

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.

Copy link
Member

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.

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.

2 participants
0