Skip to content

perf: improve tldts.getDomain speed#1936

Open
SukkaW wants to merge 1 commit intoviolentmonkey:masterfrom
SukkaW:tldts-perf
Open

perf: improve tldts.getDomain speed#1936
SukkaW wants to merge 1 commit intoviolentmonkey:masterfrom
SukkaW:tldts-perf

Conversation

@SukkaW
Copy link
Copy Markdown
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.

Comment thread src/common/tld.js
};

export const getDomain = url => getDomain_(url, getDomainSharedOpts);
export const getPublicSuffix = url => getPublicSuffix_(url, getPublicSuffixSharedOpts);
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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