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

Fix perf regressions #385

merged 1 commit into from
Sep 27, 2023

Conversation

GioSensation
Copy link
Member

Reviewer: @shakyShane
Asana: https://app.asana.com/0/0/1205589679117410/f

Description

Prevent certain regex checks to run on huge strings.

Steps to test

Signed-off-by: Emanuele Feliziani <[email protected]>
@GioSensation GioSensation self-assigned this Sep 27, 2023
!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 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.

@@ -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.

@@ -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.

@GioSensation GioSensation merged commit 55466f1 into main Sep 27, 2023
1 check passed
@GioSensation GioSensation deleted the ema/fix-perf-regressions branch September 27, 2023 14:17
brindy added a commit to duckduckgo/macos-browser that referenced this pull request Sep 28, 2023
Task/Issue URL:
https://app.asana.com/0/1205602928782192/1205602928782192
Autofill Release:
https://github.com/duckduckgo/duckduckgo-autofill/releases/tag/8.4.1
BSK PR: duckduckgo/BrowserServicesKit#517

## Description
Updates Autofill to version
[8.4.1](https://github.com/duckduckgo/duckduckgo-autofill/releases/tag/8.4.1).

### Autofill 8.4.1 release notes
## What's Changed
* Precompile regexes by @GioSensation in
duckduckgo/duckduckgo-autofill#382
* Add perf tests by @GioSensation in
duckduckgo/duckduckgo-autofill#383
* deps: remove deprecated content-scope-utils by @shakyShane in
duckduckgo/duckduckgo-autofill#384
* Update dependencies by @GioSensation in
duckduckgo/duckduckgo-autofill#368
* Fix perf regressions by @GioSensation in
duckduckgo/duckduckgo-autofill#385


**Full Changelog**:
duckduckgo/duckduckgo-autofill@8.4.0...8.4.1

## Steps to test
This release has been tested during autofill development. For smoke test
steps see [this
task](https://app.asana.com/0/1198964220583541/1200583647142330/f).

---------

Co-authored-by: GioSensation <[email protected]>
Co-authored-by: Chris Brind <[email protected]>
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