Skip to content

Clear wide storage places with a loop - #1874

Open
sbillig wants to merge 1 commit into
argotorg:masterfrom
sbillig:perf-clear-loop
Open

sbillig wants to merge 1 commit into
argotorg:masterfrom
sbillig:perf-clear-loop

Conversation

@sbillig

@sbillig sbillig commented Oct 25, 2026 •

Copy link
Copy Markdown
Collaborator

core::intrinsic::clear zeroed a storage or transient place with one store per word, unrolled, so SolArray<[u256; 64]>::pop or removing a 100-word StorageMap entry emitted hundreds of stores.

A clear of more than 16 words now lowers to a ZeroState runtime builtin, which Sonatina lowering expands to a loop over the place's slots. The loop stops on !=, so a place that wraps past the top of the slot space clears the same slots the unrolled stores did. The loop costs 23-32 gas per word more than the stores at -O1 and -O2, so narrower clears stay unrolled. Memory places are unchanged.

A contract that does both of the above shrinks from 1296 to 217 bytes of runtime code; removing a 17-word map entry, from 176 to 89.

`core::intrinsic::clear` lowered to one zero store per storage word, so
clearing a large place, such as `SolArray<[u256; 64]>::pop` or removing a
100-word map entry, emitted hundreds of stores. A clear of more than 16
words now lowers to `RuntimeBuiltin::ZeroState { space, slot, len }`,
which Sonatina lowering expands to a loop from `slot` to `slot + len`.
The loop compares with `!=`, so it wraps around the slot space exactly as
the unrolled stores do.

The loop costs about 30 gas per word more than the stores, so narrower
clears stay unrolled.
@sbillig

sbillig commented Nov 6, 2026

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 6, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-06T02:37:00.537382Z 0f5f2d7 Manual request
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: 0f5f2d7224

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

This branch has not been deployed

No deployments
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