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

Adapt Storage and SnapshotSource to use Rc only. #700

Merged
merged 4 commits into from
Feb 25, 2023

Conversation

jayz22
Copy link
Contributor

@jayz22 jayz22 commented Feb 22, 2023

What

Resolves #603.

This PR explores the 2nd solution described in the issue above. By adapting the Storage and SnapshotSource to using Rc, it eliminates the unnecessary cloning of LedgerKey and LedgerEntry.

Why

The LedgerKey and LedgerEntry are deep structures (contains ScVal). Cloning them can be very expensive. Also in order to properly charge the cloning to the budget. MeteredClone needs to be implemented for them and all their substructures, which adds bloating to the code.

Known limitations

[TODO or N/A]

@jayz22 jayz22 requested a review from dmkozh February 22, 2023 19:28
Copy link
Contributor

@dmkozh dmkozh left a comment

Choose a reason for hiding this comment

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

Looks fine to me, though not sure what are the expected additional changes to move this from the 'draft' state to review.

@jayz22
Copy link
Contributor Author

jayz22 commented Feb 22, 2023

Looks fine to me, though not sure what are the expected additional changes to move this from the 'draft' state to review.

Thanks @dmkozh. I just want to go through the whole stack: core, sdk, rpc to make sure there are no major disruptions there if this lands. Once that's done, I'll mark this ready for review.

@jayz22
Copy link
Contributor Author

jayz22 commented Feb 23, 2023

The churn on the downstream (core, sdk, rpc) seems pretty minimal (see the three draft PRs mentioned above), so I'm marking this ready for review.

Copy link
Contributor

@graydon graydon left a comment

Choose a reason for hiding this comment

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

Solid step in the right direction, but a few things to clean up.

soroban-env-host/src/storage.rs Outdated Show resolved Hide resolved
soroban-env-host/src/storage.rs Outdated Show resolved Hide resolved
soroban-env-host/src/storage.rs Outdated Show resolved Hide resolved
soroban-env-host/src/storage.rs Outdated Show resolved Hide resolved
soroban-env-host/src/storage.rs Outdated Show resolved Hide resolved
soroban-env-host/src/storage.rs Outdated Show resolved Hide resolved
soroban-env-host/src/host.rs Outdated Show resolved Hide resolved
soroban-env-host/src/host.rs Outdated Show resolved Hide resolved
soroban-env-host/src/host/data_helper.rs Show resolved Hide resolved
soroban-env-host/src/host/data_helper.rs Outdated Show resolved Hide resolved
@jayz22
Copy link
Contributor Author

jayz22 commented Feb 24, 2023

@graydon I've addressed all your feedback around changing Rc->&Rc at the interface level. It makes a lot more sense:

  1. Reduces cloning. Rc::clone is only called at the lowest level when it has to, avoiding cloning it everywhere upfront (where most of the lower code paths don't actually need it).
  2. Makes the interface more uniform and much easier to use.

@graydon graydon merged commit dc7f135 into stellar:main Feb 25, 2023
dmkozh pushed a commit to stellar/rs-soroban-sdk that referenced this pull request Feb 27, 2023
### What

Adapt to env changes in
stellar/rs-soroban-env#700

### Why

[TODO: Why this change is being made. Include any context required to
understand the why.]

### Known limitations

[TODO or N/A]
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.

decide how to meter cloning of LedgerKey / LedgerVal
3 participants