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

#6581: lazy load page script to reduce memory footprint #6772

Merged
merged 4 commits into from
Oct 31, 2023

Conversation

twschiller
Copy link
Contributor

@twschiller twschiller commented Oct 30, 2023

What does this PR do?

  • Part of Investigate delayed execution of bricks in resource-starved browsers #6581
  • The page script stat size is 868kb
  • The page script is only used by the Page Editor and a few rare bricks. However, lifecycle.ts was loading the Page Editor on every frame, and the injection was blocking mod startup
  • Refactors legacy messenger utils out of pageScript folder to @/utils/legacyMessengerUtils
  • Fixes a circular dependency between selector inference and selector hints
  • Extracts inference method that calls the page script into: src/contentScript/pageEditor/inferSingleElementSelector.ts

Remaining Work

  • Fix browser-polyfill check

Future Work

  • Drop the deprecated framework detection for the element (which requires the page script, so therefore needed to be split from the other inference code)

Checklist

  • Add tests: TODO: check to see if we have existing Rainforest QA tests
  • New files added to src/tsconfig.strictNullChecks.json (if possible): N/A
  • Designate a primary reviewer: @grahamlangford

@twschiller twschiller self-assigned this Oct 30, 2023
@@ -47,6 +51,16 @@ function assertCustomEvent(
}
}

const injectPageScriptOnce = once(async (): Promise<void> => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved from lifecycle.ts

@@ -89,15 +88,6 @@ const _navigationListeners = new Set<() => void>();

const WAIT_LOADED_INTERVAL_MS = 25;

const injectPageScriptOnce = once(async (): Promise<void> => {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Moved to pigeon.ts

Copy link
Collaborator

Choose a reason for hiding this comment

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

Looks like it's in src/pageScript/messenger/sender.ts

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Looks like it's in src/pageScript/messenger/sender.ts

Move to src/pageScript/messenger/sender.ts 😄

@codecov
Copy link

codecov bot commented Oct 30, 2023

Codecov Report

Attention: 69 lines in your changes are missing coverage. Please review.

Comparison is base (ed759a5) 70.05% compared to head (5793ae9) 70.03%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #6772      +/-   ##
==========================================
- Coverage   70.05%   70.03%   -0.02%     
==========================================
  Files        1188     1193       +5     
  Lines       36936    36949      +13     
  Branches     6937     6937              
==========================================
+ Hits        25875    25879       +4     
- Misses      11061    11070       +9     
Files Coverage Δ
src/background/contentScript.ts 96.72% <100.00%> (ø)
src/background/externalProtocol.ts 0.00% <ø> (ø)
src/background/messenger/external/api.ts 0.00% <ø> (ø)
src/contentScript/externalProtocol.ts 0.00% <ø> (ø)
src/contentScript/lifecycle.ts 67.14% <100.00%> (-0.78%) ⬇️
src/contentScript/pageEditor.ts 0.00% <ø> (ø)
src/contentScript/pageEditor/elementPicker.ts 67.07% <100.00%> (+0.13%) ⬆️
...geEditor/tabs/effect/useDocumentPreviewRunBlock.ts 55.07% <ø> (ø)
src/pageScript/frameworks.ts 0.00% <ø> (ø)
src/pageScript/messenger/api.ts 100.00% <100.00%> (ø)
... and 9 more

... and 1 file with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@fregante fregante left a comment

Choose a reason for hiding this comment

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

I don't immediately see what's importing the polyfill. expectContext does not use browser

https://github.com/pixiebrix/pixiebrix-extension/blob/main/src/utils/expectContext.ts


/** @file The first messenger before webext-messenger. Deprecated, see https://github.com/pixiebrix/webext-messenger/issues/5 */

export interface RemoteProcedureCallRequest<TMeta extends Meta = Meta>
Copy link
Contributor

Choose a reason for hiding this comment

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

Moving these utils to a separate files opens them to being mistakenly imported since they're not individually deprecated.

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'll deprecate the whole file

@twschiller twschiller changed the title #6581: lazy load page script #6581: lazy load page script to reduce memory footprint Oct 30, 2023
@github-actions
Copy link

No loom links were found in the first post. Please add one there if you'd like to it to appear on Slack.

Do not edit this comment manually.

@twschiller twschiller merged commit aefc3e5 into main Oct 31, 2023
13 checks passed
@twschiller twschiller deleted the feature/6581-lazy-load-page-script branch October 31, 2023 01:24
@grahamlangford grahamlangford added this to the 1.8.2 milestone Oct 31, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

3 participants