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

core/types: add handcrafted and generated rlp encoders #31386

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

MariusVanDerWijden
Copy link
Member

@MariusVanDerWijden MariusVanDerWijden commented Mar 13, 2025

Opened as a draft for discussion. This PR contains a handwritten decoder for headers and autogenerated decoders for all transaction types.
The gains for a header is around 25%
The gains for a dynamic fee transaction is around 23%
The gains for a full block is around 21%
The gains for a StateAccount is around 28%

Master:

BenchmarkDecodeRLP/legacy-header-14         	 1880151	       634.9 ns/op	 855.31 MB/s	      88 B/op	       3 allocs/op
BenchmarkDecodeRLP/london-header-14         	 1882408	       642.5 ns/op	 854.43 MB/s	      88 B/op	       3 allocs/op
BenchmarkDecodeRLP/receipt-for-storage-14   	 3687753	       323.5 ns/op	  27.82 MB/s	     120 B/op	       5 allocs/op
BenchmarkDecodeRLP/receipt-full-14          	 2793394	       417.8 ns/op	 646.26 MB/s	     369 B/op	       4 allocs/op
BenchmarkDecodeRLP/legacy-transaction-14    	 1438696	       813.1 ns/op	 125.45 MB/s	     456 B/op	      13 allocs/op
BenchmarkDecodeRLP/access-transaction-14    	 1000000	      1079 ns/op	  98.27 MB/s	     576 B/op	      17 allocs/op
BenchmarkDecodeRLP/1559-transaction-14      	  917408	      1129 ns/op	  97.45 MB/s	     608 B/op	      18 allocs/op
BenchmarkDecodeRLP/blob-transaction-14      	  768469	      1587 ns/op	 198.50 MB/s	    1201 B/op	      18 allocs/op
BenchmarkDecodeRLP/blob-sidecar-14          	   56906	     19323 ns/op	40730.71 MB/s	      24 B/op	       1 allocs/op
BenchmarkDecodeRLP/full-block-14            	    4388	    233879 ns/op	 195.76 MB/s	  165786 B/op	    3553 allocs/op
PASS

BenchmarkEncodeRLP/legacy-header-14         	 7392064	       152.4 ns/op	3562.75 MB/s	       0 B/op	       0 allocs/op
BenchmarkEncodeRLP/london-header-14         	 7404615	       159.1 ns/op	3450.14 MB/s	       0 B/op	       0 allocs/op
BenchmarkEncodeRLP/receipt-for-storage-14   	17004567	        70.42 ns/op	 127.81 MB/s	       0 B/op	       0 allocs/op
BenchmarkEncodeRLP/receipt-full-14          	 5051928	       234.9 ns/op	1149.29 MB/s	     320 B/op	       1 allocs/op
BenchmarkEncodeRLP/legacy-transaction-14    	 5467675	       215.3 ns/op	 473.83 MB/s	       0 B/op	       0 allocs/op
BenchmarkEncodeRLP/access-transaction-14    	 3551023	       350.7 ns/op	 302.24 MB/s	      24 B/op	       1 allocs/op
BenchmarkEncodeRLP/1559-transaction-14      	 3272458	       361.4 ns/op	 304.36 MB/s	      24 B/op	       1 allocs/op
BenchmarkEncodeRLP/blob-transaction-14      	 2961487	       404.3 ns/op	 779.19 MB/s	      24 B/op	       1 allocs/op
BenchmarkEncodeRLP/blob-sidecar-14          	   82690	     14498 ns/op	54286.10 MB/s	       0 B/op	       0 allocs/op
BenchmarkEncodeRLP/full-block-14            	   16887	     71406 ns/op	 641.23 MB/s	    5038 B/op	     201 allocs/op

This PR:


BenchmarkDecodeRLP/legacy-header-14         	 2376819	       506.6 ns/op	1071.87 MB/s	     136 B/op	       6 allocs/op
BenchmarkDecodeRLP/london-header-14         	 2044398	       590.8 ns/op	 929.23 MB/s	     176 B/op	       8 allocs/op
BenchmarkDecodeRLP/receipt-for-storage-14   	 3651877	       324.0 ns/op	  27.78 MB/s	     120 B/op	       5 allocs/op
BenchmarkDecodeRLP/receipt-full-14          	 2918422	       433.5 ns/op	 622.80 MB/s	     369 B/op	       4 allocs/op
BenchmarkDecodeRLP/legacy-transaction-14    	 1727917	       695.5 ns/op	 146.66 MB/s	     456 B/op	      13 allocs/op
BenchmarkDecodeRLP/access-transaction-14    	 1377159	       864.5 ns/op	 122.62 MB/s	     552 B/op	      16 allocs/op
BenchmarkDecodeRLP/1559-transaction-14      	 1310846	       921.9 ns/op	 119.31 MB/s	     584 B/op	      17 allocs/op
BenchmarkDecodeRLP/blob-transaction-14      	  835886	      1251 ns/op	 251.87 MB/s	    1193 B/op	      22 allocs/op
BenchmarkDecodeRLP/blob-sidecar-14          	   62143	     19272 ns/op	40839.43 MB/s	      24 B/op	       1 allocs/op
BenchmarkDecodeRLP/full-block-14            	    5211	    192595 ns/op	 237.74 MB/s	  160738 B/op	    3335 allocs/op

BenchmarkEncodeRLP/legacy-header-14         	 7262065	       152.5 ns/op	3561.67 MB/s	       0 B/op	       0 allocs/op
BenchmarkEncodeRLP/london-header-14         	 7208215	       160.0 ns/op	3431.72 MB/s	       0 B/op	       0 allocs/op
BenchmarkEncodeRLP/receipt-for-storage-14   	17004182	        68.93 ns/op	 130.57 MB/s	       0 B/op	       0 allocs/op
BenchmarkEncodeRLP/receipt-full-14          	 5005762	       236.8 ns/op	1140.30 MB/s	     320 B/op	       1 allocs/op
BenchmarkEncodeRLP/legacy-transaction-14    	 6188692	       190.6 ns/op	 535.24 MB/s	       0 B/op	       0 allocs/op
BenchmarkEncodeRLP/access-transaction-14    	 3856098	       313.3 ns/op	 338.34 MB/s	      24 B/op	       1 allocs/op
BenchmarkEncodeRLP/1559-transaction-14      	 3700237	       327.5 ns/op	 335.89 MB/s	      24 B/op	       1 allocs/op
BenchmarkEncodeRLP/blob-transaction-14      	 3438661	       346.2 ns/op	 909.81 MB/s	      24 B/op	       1 allocs/op
BenchmarkEncodeRLP/blob-sidecar-14          	   83097	     14647 ns/op	53735.84 MB/s	      36 B/op	       0 allocs/op
BenchmarkEncodeRLP/full-block-14            	   18370	     63885 ns/op	 716.72 MB/s	    5025 B/op	     201 allocs/op

State account:

BenchmarkDecodeRLP/state-account-14         	 5723620	       224.2 ns/op	 312.16 MB/s	     120 B/op	       4 allocs/op
BenchmarkEncodeRLP/state-account-14         	16749090	        74.82 ns/op	 935.56 MB/s	       0 B/op	       0 allocs/op
PR:
BenchmarkDecodeRLP/state-account-14         	 6984242	       174.1 ns/op	 401.95 MB/s	      56 B/op	       2 allocs/op

@fjl
Copy link
Contributor

fjl commented Mar 14, 2025

One thing I don't like about this, is that we are losing the error messages with this change.

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.

None yet

2 participants