Skip to content

[storage] Add batch_push operations to StorageVec for improved perfor… #2502

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

peiqing6888
Copy link

[storage] Add batch_push operations to StorageVec

Summary

  • n | Does it introduce breaking changes?
  • n | Is it dependent on a specific version of cargo-contract or pallet-revive?

Introduces batch operations to StorageVec to optimize gas costs when adding multiple elements. The new methods reduce storage operations by updating length only once for multiple insertions.

Description

Added batch_push and try_batch_push methods to StorageVec for efficient bulk insertions. These methods optimize storage operations by performing a single length update after inserting all elements, rather than updating length after each insertion. This approach significantly reduces gas costs for bulk operations while maintaining the same functionality and safety guarantees.

The implementation includes comprehensive tests verifying both functionality and performance improvements, along with proper error handling for buffer size limitations.

Checklist before requesting a review

  • I have added an entry to CHANGELOG.md
  • I have commented on my code, particularly in hard-to-understand areas
  • I have added tests that prove my fix is effective or that my feature works
  • Any dependent changes have been merged and published in downstream modules

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.

1 participant