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

Minimize calls to storage for bytes/string #217

Merged
merged 4 commits into from
Feb 4, 2025
Merged

Conversation

gligneul
Copy link
Contributor

@gligneul gligneul commented Feb 4, 2025

Description

This PR improves the Storage bytes and strings by reducing the number of calls to set_word and get_word. Now, when extending a storage bytes, the SDK will make a HostIO call for each chunk instead of each byte.

Close STY-207

Co-authored-by: Rory Neithinger <rneithinger@offchainlabs.com>
if len < 32 {
while len < 32 {
if let Some(byte) = iter.next() {
root.word[len] = byte;
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need a bounds check here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is not necessary because the while condition already ensures that len is smaller than the word size.

stylus-sdk/src/storage/bytes.rs Outdated Show resolved Hide resolved
@gligneul gligneul merged commit 8c2493a into main Feb 4, 2025
10 checks passed
@gligneul gligneul deleted the gligneul/efficient-bytes branch February 4, 2025 21:25
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