Skip to content

test: Avoid copying RLP-encoded strings - #1816

Merged
chfast merged 1 commit into
masterfrom
test/rlp-encode-copy
Nov 17, 2026
Merged

chfast merged 1 commit into
masterfrom
test/rlp-encode-copy

Conversation

@chfast

@chfast chfast commented Nov 16, 2026

Copy link
Copy Markdown
Member

rlp::encode(bytes_view) returned the reference that bytes::operator+= gives, so the encoded string was copied into the return value. Append to a local variable instead and return it.

This removes an allocation and a copy from most RLP string encodings (transactions, logs, trie nodes) and makes the state tests execute about 0.1% fewer instructions. The copy was found with LLVM's CopyProf (-fcopyprof).

rlp::encode(bytes_view) returned the reference that bytes::operator+=
gives, so the encoded string was copied into the return value. Append
to a local variable instead and return it.

This removes an allocation and a copy from most RLP string encodings
(transactions, logs, trie nodes) and makes the state tests execute
about 0.1% fewer instructions. The copy was found with LLVM's CopyProf
(-fcopyprof).
@codspeed

codspeed Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will regress 14 benchmarks

2 warnings

⚠️ 154 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚠️ 30 benchmarks with a significant change ran in a different software environment

Their base and head results were measured with a different OS or toolchain, such as compiler, runtime or library versions, so the changes might come from this difference rather than from the code. Open an affected benchmark to see what changed.

See affected benchmarks

⚡ 143 improved benchmarks
❌ 14 regressed benchmarks
✅ 742 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
❌ test_push[fork_Osaka-blockchain_test-opcode_PUSH24-benchmark-gas-value_1M] 48.6 ms 54.7 ms -11.16%
❌ test_push[fork_Osaka-blockchain_test-opcode_PUSH26-benchmark-gas-value_1M] 52.7 ms 59.2 ms -11.11%
❌ test_push[fork_Osaka-blockchain_test-opcode_PUSH25-benchmark-gas-value_1M] 51.1 ms 57.4 ms -11.03%
❌ test_push[fork_Osaka-blockchain_test-opcode_PUSH23-benchmark-gas-value_1M] 47.4 ms 53.3 ms -11.02%
❌ test_gas_op[fork_Osaka-blockchain_test-benchmark-gas-value_1M] 12 ms 12.3 ms -2.14%
❌ test_dup[fork_Osaka-blockchain_test-opcode_DUP14-benchmark-gas-value_1M] 9.4 ms 9.6 ms -2.05%
❌ baseline/analyse/main/structarray_alloc 5.2 µs 5.3 µs -2.04%
❌ test_dup[fork_Osaka-blockchain_test-opcode_DUP13-benchmark-gas-value_1M] 9.3 ms 9.5 ms -1.87%
❌ test_dup[fork_Osaka-blockchain_test-opcode_DUP4-benchmark-gas-value_1M] 9.4 ms 9.5 ms -1.85%
❌ test_dup[fork_Osaka-blockchain_test-opcode_DUP15-benchmark-gas-value_1M] 9.4 ms 9.5 ms -1.75%
❌ test_calldatasize[fork_Osaka-blockchain_test-zero_data_True-calldata_size_0-benchmark-gas-value_1M] 14 ms 14.3 ms -1.69%
❌ test_msize[fork_Osaka-blockchain_test-mem_size_1000-benchmark-gas-value_1M] 12.9 ms 13.1 ms -1.62%
❌ test_dup[fork_Osaka-blockchain_test-opcode_DUP2-benchmark-gas-value_1M] 9.4 ms 9.6 ms -1.4%
❌ test_calldatasize[fork_Osaka-blockchain_test-zero_data_False-calldata_size_256-benchmark-gas-value_1M] 14.1 ms 14.3 ms -1.39%
⚡ test_block_full_data[fork_Osaka-blockchain_test-zero_byte_True-benchmark-gas-value_1M] 14.3 ms 12.7 ms +12.8%
⚡ test_block_full_data[fork_Osaka-blockchain_test-zero_byte_False-benchmark-gas-value_1M] 4.6 ms 4.1 ms +11.36%
⚡ test_bls12_g1_msm[fork_Osaka-blockchain_test-k_128-benchmark-gas-value_1M] 5 ms 4.7 ms +7.9%
⚡ test_bls12_381[fork_Osaka-blockchain_test-bls12_g2msm-benchmark-gas-value_1M] 4.7 ms 4.4 ms +7.81%
⚡ test_bls12_381[fork_Osaka-blockchain_test-bls12_g1msm-benchmark-gas-value_1M] 5.1 ms 4.7 ms +7.58%
⚡ test_bls12_g2_msm[fork_Osaka-blockchain_test-k_64-benchmark-gas-value_1M] 4.7 ms 4.4 ms +7.51%
... ... ... ... ...

ℹ️ Only the first 20 benchmarks are displayed. Go to the app to view all benchmarks.

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing test/rlp-encode-copy (2abe848) with master (ba92871)

Open in CodSpeed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues are reported for the RLP string encoder optimization.

No open issues 🎉

What changed in this PR

This PR removes an avoidable copy from the RLP string encoder used by test utilities, reducing encoding overhead without changing the encoded output.

Changes:

  • Append input bytes to a local encoded buffer and return it, enabling return-value optimization or move semantics.
File Description
test/​utils/​rlp.hpp Return a local RLP buffer instead of copying the reference returned by operator+=.

Review effort: Balanced

@codecov

codecov Bot commented Nov 16, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.23%. Comparing base (ba92871) to head (2abe848).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #1816   +/-   ##
=======================================
  Coverage   98.23%   98.23%           
=======================================
  Files         186      186           
  Lines       17192    17194    +2     
  Branches     3963     3963           
=======================================
+ Hits        16888    16890    +2     
  Misses        235      235           
  Partials       69       69           
Flag Coverage Δ
eest-develop-gmp 26.76% <100.00%> (+<0.01%) ⬆️
eest-legacy 17.22% <100.00%> (+<0.01%) ⬆️
eest-libsecp256k1 28.73% <100.00%> (+<0.01%) ⬆️
eest-stable 83.75% <100.00%> (+<0.01%) ⬆️
evmone-unittests 93.94% <100.00%> (+<0.01%) ⬆️
riscv64 94.81% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
core 96.60% <ø> (ø)
tooling 94.87% <100.00%> (+<0.01%) ⬆️
tests 99.80% <ø> (ø)
Files with missing lines Coverage Δ
test/utils/rlp.hpp 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

No active review issues remain for the RLP string encoder change that removes an unnecessary buffer copy.

No open issues 🎉

Review effort: Balanced

@chfast
chfast merged commit 0a50c91 into master Nov 17, 2026
33 of 34 checks passed
@chfast
chfast deleted the test/rlp-encode-copy branch November 17, 2026 09:43
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