Skip to content

platform: copy 64 bytes per memcpy iteration on OpenVM - #10

Merged
maximmenshikov merged 1 commit into
NethermindEth:mainfrom
LukaszRozmej:perf/memcpy-64-byte-blocks
Nov 21, 2026
Merged

maximmenshikov merged 1 commit into
NethermindEth:mainfrom
LukaszRozmej:perf/memcpy-64-byte-blocks

Conversation

@LukaszRozmej

Copy link
Copy Markdown
Member

Changes

  • __wrap_memcpy in platform/entry.S copies 64 bytes per loop iteration while 64 or more bytes are left, then at most one 32-byte block, then 8-byte words, as before.
  • The loop's count, pointer and branch instructions cost as much as its loads and stores, so doubling the block cuts the loop overhead per byte in half. The last-word tail and the byte path for copies below 8 bytes do not change.
  • __wrap_memmove still tail-calls __wrap_memcpy for forward copies. The 64-byte loop reads each 32-byte half before it stores it, as the 32-byte loop did, so a destination below the source still reads every source byte before it overwrites it.

Measurement

OpenVM metered cost (execute_metered_cost, trace cells) and instret of the Nethermind stateless guest on 5 mainnet blocks (4.5 to 60 Mgas). Both arms link the same libopenvm.a; only openvm_entry.o differs. The zkVM is deterministic, so one run per arm is exact. Both arms commit the same public values on every block.

Block Instret before Instret after Change Cost before Cost after Change
26279606 13,356,326 13,082,460 -2.05% 1,504,277,094 1,497,644,983 -0.44%
26279555 47,077,353 46,449,080 -1.33% 5,287,110,093 5,271,860,631 -0.29%
26279462 60,129,865 59,379,016 -1.25% 6,355,836,572 6,337,756,970 -0.28%
26279483 107,251,067 106,260,636 -0.92% 10,190,945,863 10,166,901,057 -0.24%
26279621 189,943,274 188,241,695 -0.90% 17,387,083,326 17,345,947,893 -0.24%
Total 417,757,885 413,412,887 -1.04% 40,725,252,948 40,620,111,534 -0.26%

Small blocks gain the most, because copies are a larger share of their work.

Tests

tests/platform/run.sh passes under qemu-user: memcpy at every source and destination offset 0-15 and length 0-600, memmove forward, reverse and overlapping at -40 to +40 bytes, memset.

@maximmenshikov
maximmenshikov merged commit adaf385 into NethermindEth:main Nov 21, 2026
10 checks passed
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