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

Mitigate perf degradation cause by loading wallet-standard #16868

Merged
merged 5 commits into from
Jan 27, 2023

Conversation

darkdh
Copy link
Member

@darkdh darkdh commented Jan 26, 2023

Resolves brave/brave-browser#27997

We now load wallet-standard script separately in OnFinishLoad and only when Solana keyring is created.
follow-up issue created: brave/brave-browser#28082

iOS now needs to load new script IDR_BRAVE_WALLET_SCRIPT_WALLET_STANDARD_SCRIPT_BUNDLE_JS in order to get wallet-standard compatibility and also call IsSolanaKeyringCreated to decide whether to load wallet-standard

Release build comparison on example.com: (Reland: v1.49.56, No wallet-standard: v1.48.110)
Screen Shot 2023-01-25 at 14 52 18
Screen Shot 2023-01-25 at 17 03 32

task (compile time + function call) is delayed after first paint

Submitter Checklist:

  • I confirm that no security/privacy review is needed, or that I have requested one
  • There is a ticket for my issue
  • Used Github auto-closing keywords in the PR description above
  • Wrote a good PR/commit description
  • Squashed any review feedback or "fixup" commits before merge, so that history is a record of what happened in the repo, not your PR
  • Added appropriate labels (QA/Yes or QA/No; release-notes/include or release-notes/exclude; OS/...) to the associated issue
  • Checked the PR locally:
    • npm run test -- brave_browser_tests, npm run test -- brave_unit_tests wiki
    • npm run lint, npm run presubmit wiki, npm run gn_check, npm run tslint
  • Ran git rebase master (if needed)

Reviewer Checklist:

  • A security review is not needed, or a link to one is included in the PR description
  • New files have MPL-2.0 license header
  • Adequate test coverage exists to prevent regressions
  • Major classes, functions and non-trivial code blocks are well-commented
  • Changes in component dependencies are properly reflected in gn
  • Code follows the style guide
  • Test plan is specified in PR before merging

After-merge Checklist:

Test Plan:

Fresh profile

  1. Get the nightly version with this fix (ex. v1.49.56) and with this fix
  2. Open them with fresh profiles and navigate to https://example.com (--user-data-dir can be used so you can open them simultaneously)
  3. Open dev console and switch to performance page
  4. Click "Start profiling and reload page" and wait for it to stop on each of them
  5. There shouldn't be any Function call (Function(anonymous) @ wallet_standard.js:1:10) + Compile time appeared after FP and FCP

With Solana account created

  1. Get the nightly version with this fix (ex. v1.49.56) and with this fix
  2. Open them with fresh profiles and navigate to https://example.com (--user-data-dir can be used so you can open them simultaneously)
  3. Setup wallet on both profiles.
  4. Open dev console and switch to performance page
  5. Click "Start profiling and reload page" and wait for it to stop on each of them
  6. Function call (Function(anonymous) @ wallet_standard.js:1:10) + Compile time ahead of it should be similar to previous version of Function(anonymous) @ solana_provider.js:1:10
  7. Also fixed version's Function call should be after FP and FCP
  8. Make sure Implement Solana support for "The Wallet Standard" brave-browser#27340 (comment) still passed in new version.

@darkdh darkdh self-assigned this Jan 26, 2023
@darkdh darkdh requested review from a team as code owners January 26, 2023 00:24
@darkdh darkdh force-pushed the wallet-standard-perf branch from d9476cd to a173a77 Compare January 26, 2023 21:03
@darkdh darkdh changed the title Load wallet-standard script separately in OnFinishLoad Mitigate perf degradation cause by loading wallet-standard Jan 26, 2023
@StephenHeaps StephenHeaps requested a review from a team January 26, 2023 22:13
Copy link
Collaborator

@kylehickinson kylehickinson left a comment

Choose a reason for hiding this comment

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

iOS++

@@ -211,6 +211,9 @@ interface SolanaProvider {
=> (SolanaProviderError error, string error_message,
mojo_base.mojom.DictionaryValue result);

// DO NOT USE: This is supposed to be a temoprary solution for us to decide
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit:

Suggested change
// DO NOT USE: This is supposed to be a temoprary solution for us to decide
// DO NOT USE: This is supposed to be a temporary solution for us to decide

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@@ -600,6 +600,12 @@ void SolanaProviderImpl::Request(base::Value::Dict arg,
}
}

void SolanaProviderImpl::IsSolanaKeyringCreated(
IsSolanaKeyringCreatedCallback callback) {
std::move(callback).Run(
Copy link
Collaborator

Choose a reason for hiding this comment

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

nit: add DCHECK(keyring_service_);

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@@ -68,6 +70,10 @@ JSSolanaProvider::JSSolanaProvider(content::RenderFrame* render_frame)
*g_provider_solana_web3_script =
LoadDataResource(IDR_BRAVE_WALLET_SOLANA_WEB3_JS);
}
if (g_wallet_standard_script->empty()) {
*g_wallet_standard_script = LoadDataResource(
Copy link
Collaborator

Choose a reason for hiding this comment

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

Do we really need to cache LoadDataResource() returned values?
If we need, then it should be shared memory for all the renderer. Otherwise it takes 1.8MB(the string size) per renderer process because it's private process memory.

Copy link
Collaborator

Choose a reason for hiding this comment

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

For large resources:

  1. If the resource isn't gzipped use GetRawDataResource() each time, don't cache;
  2. If unzip time is affordable don't cache, use LoadDataResourceString() each time (except large resources on UI thread in browser process);
  3. Store cached unzipped resources in browser process. Pass them via IPC each time you need it. Or store it in shared memory and pass a handle.

Bad practice:

  • Using private process memory to cache LoadDataResourceString() (i.e. static std::string) for large resources. It increases total footprint by RESOURCE_SIZE * N where N is renderer process number. Also each new tab usually uses a new process => old cache doesn't help to save time.
  • Loading large zipped resources on UI thread. It will result in freezes/frame drops: crbug.com/973417

Copy link
Collaborator

@atuchin-m atuchin-m Jan 27, 2023

Choose a reason for hiding this comment

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

In this particular case all 3 cached resources are unzipped => please use GetRawDataResource() each time, don't cache.

P.S. I wonder could we support gzip in transpile_web_ui.

Copy link
Member Author

Choose a reason for hiding this comment

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

Those cached scripts resources are removed and they are only be used once, I don't think they need to be cached.

Copy link
Collaborator

@atuchin-m atuchin-m left a comment

Choose a reason for hiding this comment

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

LGTM after removing the resource cache.

@darkdh darkdh force-pushed the wallet-standard-perf branch 2 times, most recently from 2613037 to 31fd637 Compare January 27, 2023 18:09
@darkdh darkdh force-pushed the wallet-standard-perf branch from 31fd637 to 2c655a2 Compare January 27, 2023 18:58
@darkdh darkdh merged commit dd90cc3 into master Jan 27, 2023
@darkdh darkdh deleted the wallet-standard-perf branch January 27, 2023 22:53
@github-actions github-actions bot added this to the 1.49.x - Nightly milestone Jan 27, 2023
darkdh added a commit that referenced this pull request Jan 28, 2023
Mitigate perf degradation cause by loading wallet-standard
kjozwiak pushed a commit that referenced this pull request Jan 30, 2023
Mitigate perf degradation cause by loading wallet-standard
kjozwiak pushed a commit that referenced this pull request Jan 30, 2023
* Add wallet-standard-brave to register Solana wallet-standard (Reland) (Uplift of #16724)

* Mitigate perf degradation cause by loading wallet-standard (Uplift of #16868)
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.

First paint performance degradation for v1.49.41..v1.49.45
6 participants