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

Fix perf regressions #385

Merged
merged 1 commit into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 16 additions & 17 deletions dist/autofill-debug.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 16 additions & 17 deletions dist/autofill.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 11 additions & 7 deletions src/Form/FormAnalyzer.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,12 @@ class FormAnalyzer {
shouldCheckUnifiedForm = false,
shouldBeConservative = false
}) {
// If the string is empty or too long (noisy) do nothing
if (
!string ||
string.length > constants.TEXT_LENGTH_CUTOFF
) return this

Copy link
Member Author

Choose a reason for hiding this comment

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

This is the meat of the fix. We want to avoid running several regex checks on potentially huge chunks of text. This is what was causing the issues.

const matchesLogin = /current.?password/i.test(string) || this.matching.getDDGMatcherRegex('loginRegex')?.test(string) || this.matching.getDDGMatcherRegex('resetPasswordLink')?.test(string)

// Check explicitly for unified login/signup forms
Expand Down Expand Up @@ -177,9 +183,10 @@ class FormAnalyzer {
}

evaluatePageHeadings () {
const headings = document.querySelectorAll('h1, h2, h3, [class*="title"], [id*="title"]')
headings.forEach(({textContent}) => {
textContent = removeExcessWhitespace(textContent || '')
const headings = document.querySelectorAll('h1, h2, h3')
Copy link
Member Author

Choose a reason for hiding this comment

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

Removed [class*="title"], [id*="title"] to avoid catching a bunch of useless stuff.

headings.forEach((heading) => {
const textContent = removeExcessWhitespace(heading.textContent || '')

this.updateSignal({
string: textContent,
strength: 0.5,
Expand Down Expand Up @@ -256,10 +263,7 @@ class FormAnalyzer {
this.updateSignal({string, strength, signalType: `external link: ${string}`, shouldFlip})
} else {
// any other case
// only consider the el if it's a small text to avoid noisy disclaimers
if (removeExcessWhitespace(el.textContent)?.length < constants.TEXT_LENGTH_CUTOFF) {
Copy link
Member Author

Choose a reason for hiding this comment

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

The length check has been moved to updateSignal so we're sure all these regexes are safeguarded against extra long text.

this.updateSignal({string, strength: 1, signalType: `generic: ${string}`, shouldCheckUnifiedForm: true})
}
this.updateSignal({string, strength: 1, signalType: `generic: ${string}`, shouldCheckUnifiedForm: true})
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/Scanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ class DefaultScanner {
return
}

// Do not add explicitly search forms
if (parentForm.role === 'search') return
Copy link
Member Author

Choose a reason for hiding this comment

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

Just occurred to me we shouldn't even add these obvious search forms, whenever web authors are kind enough to mark them as such. Now there's a new search html element, but not worth bothering about it now.


// Check if the forms we've seen are either disconnected,
// or are parent/child of the currently-found form
let previouslyFoundParent, childForm
Expand Down
33 changes: 16 additions & 17 deletions swift-package/Resources/assets/autofill-debug.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 16 additions & 17 deletions swift-package/Resources/assets/autofill.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading