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

More optimizations to package load #14762

Merged
merged 1 commit into from
Nov 10, 2023
Merged

Conversation

lxfind
Copy link
Contributor

@lxfind lxfind commented Nov 10, 2023

Description

I noticed that we still spend a non-trivial amount of time loading packages in execution. After digging in, I realized that this is mostly due to us trying to save all runtime loaded packages.
This PR minimizes that overhead by:

  1. Do not write unless it's not already in the runtime loaded package map.
  2. Avoid clone.

This fix is sufficient to make the package load disappear in a local benchmark, and we are seeing about 10% improvements in throughout in the baseline mode. So this is good enough for now.
However as a long term fix, I think a proper solution is that we should introduce a verbose flag to execution. Normally the verbose flag is off. When we detect a fork, we rerun the execution with the verbose flag on so that we could collect more information for the debug state dump.

Also fixed the execution-only mode in the local benchmark to use the package cache, otherwise we would see a ton of unnecessary clones there.

Test Plan

CI


If your changes are not user-facing and not a breaking change, you can skip the following section. Otherwise, please indicate what changed, and then add to the Release Notes section as highlighted during the release process.

Type of Change (Check all that apply)

  • protocol change
  • user-visible impact
  • breaking change for a client SDKs
  • breaking change for FNs (FN binary must upgrade)
  • breaking change for validators or node operators (must upgrade binaries)
  • breaking change for on-chain data layout
  • necessitate either a data wipe or data migration

Release notes

@lxfind lxfind requested review from oxade and amnn November 10, 2023 01:02
Copy link

vercel bot commented Nov 10, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
mysten-ui ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 10, 2023 4:34am
sui-core ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 10, 2023 4:34am
sui-typescript-docs ✅ Ready (Inspect) Visit Preview 💬 Add feedback Nov 10, 2023 4:34am
3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
explorer ⬜️ Ignored (Inspect) Visit Preview Nov 10, 2023 4:34am
multisig-toolkit ⬜️ Ignored (Inspect) Visit Preview Nov 10, 2023 4:34am
sui-kiosk ⬜️ Ignored (Inspect) Visit Preview Nov 10, 2023 4:34am

{
// TODO: Can this lock ever block execution?
// TODO: Why do we need a RwLock anyway???
self.runtime_packages_loaded_from_db
Copy link
Contributor

Choose a reason for hiding this comment

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

This lock is for interior mutability since we only take self as read ref

Copy link
Contributor

@oxade oxade left a comment

Choose a reason for hiding this comment

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

Great catch! Honestly I'm in favor of rethinking/replacing this logic altogether.
We put it together as a quick response for fork analysis, so I'm in support better solutions sooner than later if possible

@lxfind lxfind force-pushed the performance-opt-package-more branch from 0fbf864 to 1c039d3 Compare November 10, 2023 04:33
@vercel vercel bot temporarily deployed to Preview – mysten-ui November 10, 2023 04:34 Inactive
@lxfind lxfind merged commit 3871468 into main Nov 10, 2023
34 checks passed
@lxfind lxfind deleted the performance-opt-package-more branch November 10, 2023 17:31
@@ -54,7 +54,7 @@ pub struct TemporaryStore<'backing> {

/// Every package that was loaded from DB store during execution.
/// These packages were not previously loaded into the temporary store.
runtime_packages_loaded_from_db: RwLock<BTreeMap<ObjectID, Object>>,
runtime_packages_loaded_from_db: RwLock<BTreeMap<ObjectID, PackageObjectArc>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

we should consider just switching to DashMap

@@ -63,7 +63,7 @@ pub struct TemporaryStore<'backing> {

/// Every package that was loaded from DB store during execution.
/// These packages were not previously loaded into the temporary store.
runtime_packages_loaded_from_db: RwLock<BTreeMap<ObjectID, Object>>,
runtime_packages_loaded_from_db: RwLock<BTreeMap<ObjectID, PackageObjectArc>>,
Copy link
Contributor

Choose a reason for hiding this comment

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

ditto DashMap

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.

3 participants