eth-native 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,46 @@
1
+ # 端到端基准与 EIP-712 决策(M4)
2
+
3
+ 对照 [PLAN.md](../PLAN.md) M4:真实负载(交易签名/编码/解码、合约调用编码、
4
+ 1k/10k 事件日志解码)的 p50/p95、分配与 EIP-712 决策输入。native 路径通过
5
+ `Eth::Rlp` 路由到 `Eth::Native::Rlp`,与 eth.rb `native-rlp-backend` 分支的
6
+ opt-in 适配器等价。
7
+
8
+ ## 环境
9
+
10
+ - 2026-12-06,macOS arm64,Ruby 4.0.6,eth 0.5.18,eth-native 0.1.0.pre
11
+ - 原始输出:[e2e-2026-12-06.txt](e2e-2026-12-06.txt)
12
+
13
+ ## 结果摘要(p50 / p95 毫秒,alloc/op)
14
+
15
+ | 场景 | Ruby | native | 分配 Ruby→native |
16
+ | --- | --- | --- | --- |
17
+ | tx sign(EIP-1559 全流程) | 0.228 / 0.513 | 0.200 / 0.509 | 111 → 106 |
18
+ | tx signed encode | 0.033 / 0.035 | 0.019 / 0.020 | 8.7 → 5.6 |
19
+ | tx decode(自 hex) | 0.183 / 0.426 | 0.144 / 0.212 | 64 → 56 |
20
+ | contract call encode | 0.006 / 0.007 | 0.002 / 0.002 | 3.3 → 0.5 |
21
+ | event log decode x1000 | 66.9 / 71.2 | 1.06 / 1.21 | 31900 → 250 |
22
+ | event log decode x10000 | 632 / 698 | 10.8 / 12.8 | 319000 → 2500 |
23
+ | eip712 hash(Mail) | 0.085 / 0.096 | — | 35.9 |
24
+
25
+ ## 结论
26
+
27
+ 1. **事件日志解码是最大收益点**:1k 63 倍、10k 59 倍,分配降低三个数量级。
28
+ 合约调用编码 3 倍;交易签名整体只快约 12%(secp 签名与 Keccak 占主导),
29
+ 但纯 RLP 编码/解码阶段仍快 40–50%。
30
+ 2. **eth.rb 侧 type/schema 缓存已验证**:`Contract::FunctionInput` 在初始化时
31
+ 一次性 `Type.parse`(`@type` 缓存),`encode_call` 复用缓存的 Type 对象,
32
+ 参考实现并不存在「每次调用重解析」;native 的增益来自 Rust 侧整包编码与
33
+ 编译 Schema 复用,而非消除类型解析。
34
+ 3. **EIP-712 决策:暂不 native 化。** profiling(Mail 样例):0.094 ms/call
35
+ (约 10.6k calls/s),Keccak 占 23.1%,Ruby 遍历占 76.9%。遍历确为瓶颈,
36
+ 但 EIP-712 的编码格式独立于 RLP/ABI,现有加速无法迁移;新增 EIP-712 native
37
+ 模块需独立 schema/遍历器,收益仅在「高吞吐签名型 EIP-712 工作负载」成立。
38
+ 按 PLAN「没有收益的路径不 native 化」,0.1.0 不包含 EIP-712 native 模块;
39
+ 若后续有真实消费者报告该路径为瓶颈,再按本文件的数据重新评估。
40
+
41
+ ## 复现
42
+
43
+ ```bash
44
+ RBENV_VERSION=4.0.6 bundle exec rake compile
45
+ RBENV_VERSION=4.0.6 bundle exec ruby benchmark/e2e_benchmark.rb
46
+ ```
@@ -0,0 +1,44 @@
1
+ # RLP 配对基准
2
+
3
+ 对照 [PLAN.md](../PLAN.md) M1/M2 的基准要求:同机同 Ruby、独立进程预热、交错采样、
4
+ 报告中位数与离散度。本文件记录测量环境与结果;数字是本机证据,不是发布宣传倍数。
5
+
6
+ ## 环境
7
+
8
+ - 2026-12-06,macOS arm64(darwin25),Ruby 4.0.6,rustc 1.99,release profile(opt-level 3, lto)
9
+ - 参考:eth 0.5.18(PLAN 固定参考版本);native:eth-native 0.1.0.pre
10
+ - 方法:`benchmark/rlp_benchmark.rb`,benchmark-ips 3s 计时 1s 预热,两后端同进程交错;
11
+ 分配数取 `GC.stat(:total_allocated_objects)` 50 次均值;sanity 检查要求两后端逐字节一致后才计时
12
+ - 原始输出:[rlp-2026-12-06.txt](rlp-2026-12-06.txt)
13
+
14
+ ## 结果摘要
15
+
16
+ | 场景 | 参考 ips | native ips | 速度 | native 分配/op(参考) |
17
+ | --- | --- | --- | --- | --- |
18
+ | encode 12 字段交易 | 30.2k | 513.5k | 17.0x | 1.4(123.5) |
19
+ | encode 1k 整数 | 424.5 | 10.8k | 25.4x | 1.4(11140.3) |
20
+ | encode 1k 嵌套 | 37.4 | 542.4 | 14.5x | 1.4(91094.3) |
21
+ | encode 1KiB bytes | 172.5k | 1121.4k | 6.5x | 1.4(35.3) |
22
+ | encode 64KiB bytes | 69.3k | 417.7k | 6.0x | 1.4(35.3) |
23
+ | encode 批量 100 笔交易 | 382.3 | 6301.8 | 16.5x | 1.4(12422.3) |
24
+ | decode 12 字段交易 | 141.4k | 756.4k | 5.3x | 13.4(72.3) |
25
+ | decode 1k 整数 | 2301.3 | 20.4k | 8.9x | 1001.4(5012.3) |
26
+ | decode 1k 嵌套 | 291.2 | 2550.9 | 8.8x | 8001.4(36247.3) |
27
+ | decode 64KiB bytes | 421.9k | 233.6k | 1.8x 慢 | 2.4(23.3) |
28
+ | decode 批量 100 笔交易 | 1655.5 | 13.1k | 7.9x | 1301.4(6912.3) |
29
+
30
+ ## 结论
31
+
32
+ - 编码全面快 6–25 倍;对象分配近乎归零(整棵树只产出 1 个结果字符串,参考实现每节点建 sedes 对象)。
33
+ - 解码快 5–9 倍;大字符串叶子用共享切片(`byteslice`),与参考 `String#[]` 语义一致。
34
+ - **已知代价**:decode 64KiB 慢约 1.8 倍——native 在边界处对输入做一次安全拷贝
35
+ (防 GC compaction 期间的借用失效),参考实现是零拷贝切片。其他场景该成本不可见。
36
+ - M0 记录的 C 原型 120–148 倍仅是可行性线索;Rust 实测倍数低于该数,符合
37
+ ARCHITECTURE「不拿原型数字做承诺」的约束。
38
+
39
+ ## 复现
40
+
41
+ ```bash
42
+ RBENV_VERSION=4.0.6 bundle exec rake compile
43
+ RBENV_VERSION=4.0.6 bundle exec ruby benchmark/rlp_benchmark.rb 3
44
+ ```
@@ -0,0 +1,281 @@
1
+ # This file is automatically @generated by Cargo.
2
+ # It is not intended for manual editing.
3
+ version = 4
4
+
5
+ [[package]]
6
+ name = "aho-corasick"
7
+ version = "1.1.5"
8
+ source = "registry+https://github.com/rust-lang/crates.io-index"
9
+ checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba"
10
+ dependencies = [
11
+ "memchr",
12
+ ]
13
+
14
+ [[package]]
15
+ name = "bindgen"
16
+ version = "0.72.1"
17
+ source = "registry+https://github.com/rust-lang/crates.io-index"
18
+ checksum = "993776b509cfb49c750f11b8f07a46fa23e0a1386ffc01fb1e7d343efc387895"
19
+ dependencies = [
20
+ "bitflags",
21
+ "cexpr",
22
+ "clang-sys",
23
+ "itertools",
24
+ "proc-macro2",
25
+ "quote",
26
+ "regex",
27
+ "rustc-hash",
28
+ "shlex",
29
+ "syn",
30
+ ]
31
+
32
+ [[package]]
33
+ name = "bitflags"
34
+ version = "2.13.2"
35
+ source = "registry+https://github.com/rust-lang/crates.io-index"
36
+ checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06"
37
+
38
+ [[package]]
39
+ name = "cexpr"
40
+ version = "0.6.0"
41
+ source = "registry+https://github.com/rust-lang/crates.io-index"
42
+ checksum = "6fac387a98bb7c37292057cffc56d62ecb629900026402633ae9160df93a8766"
43
+ dependencies = [
44
+ "nom",
45
+ ]
46
+
47
+ [[package]]
48
+ name = "cfg-if"
49
+ version = "1.0.5"
50
+ source = "registry+https://github.com/rust-lang/crates.io-index"
51
+ checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
52
+
53
+ [[package]]
54
+ name = "clang-sys"
55
+ version = "1.9.1"
56
+ source = "registry+https://github.com/rust-lang/crates.io-index"
57
+ checksum = "157a8ba7b480713b56f4c09fd13fc3e0a22a5dfab8097ba61cbc5feef950788a"
58
+ dependencies = [
59
+ "glob",
60
+ "libc",
61
+ "libloading",
62
+ ]
63
+
64
+ [[package]]
65
+ name = "either"
66
+ version = "1.19.0"
67
+ source = "registry+https://github.com/rust-lang/crates.io-index"
68
+ checksum = "0e9c71c2167ca323c882b99918929403426e2373ea17242ff5653e0d5e1058be"
69
+
70
+ [[package]]
71
+ name = "eth-native"
72
+ version = "0.1.0-pre"
73
+ dependencies = [
74
+ "magnus",
75
+ ]
76
+
77
+ [[package]]
78
+ name = "glob"
79
+ version = "0.3.4"
80
+ source = "registry+https://github.com/rust-lang/crates.io-index"
81
+ checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b"
82
+
83
+ [[package]]
84
+ name = "itertools"
85
+ version = "0.13.0"
86
+ source = "registry+https://github.com/rust-lang/crates.io-index"
87
+ checksum = "413ee7dfc52ee1a4949ceeb7dbc8a33f2d6c088194d9f922fb8318faf1f01186"
88
+ dependencies = [
89
+ "either",
90
+ ]
91
+
92
+ [[package]]
93
+ name = "lazy_static"
94
+ version = "1.5.1"
95
+ source = "registry+https://github.com/rust-lang/crates.io-index"
96
+ checksum = "20870f649af7073d53e38067b2a84312175d56ea15217e1b15bc83506ec50afb"
97
+
98
+ [[package]]
99
+ name = "libc"
100
+ version = "0.2.191"
101
+ source = "registry+https://github.com/rust-lang/crates.io-index"
102
+ checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"
103
+
104
+ [[package]]
105
+ name = "libloading"
106
+ version = "0.8.9"
107
+ source = "registry+https://github.com/rust-lang/crates.io-index"
108
+ checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55"
109
+ dependencies = [
110
+ "cfg-if",
111
+ "windows-link",
112
+ ]
113
+
114
+ [[package]]
115
+ name = "magnus"
116
+ version = "0.9.4"
117
+ source = "registry+https://github.com/rust-lang/crates.io-index"
118
+ checksum = "3c5f2dd2017d172e2fde9969a35f10f1374a4dd79b37a17f1847f83201883de7"
119
+ dependencies = [
120
+ "magnus-macros",
121
+ "rb-sys",
122
+ "rb-sys-env",
123
+ "seq-macro",
124
+ ]
125
+
126
+ [[package]]
127
+ name = "magnus-macros"
128
+ version = "0.9.1"
129
+ source = "registry+https://github.com/rust-lang/crates.io-index"
130
+ checksum = "9dafde2eeb66f090e0f326112323eb8324b12cb32b5d1210e541d3df6b0ce77e"
131
+ dependencies = [
132
+ "proc-macro2",
133
+ "quote",
134
+ "syn",
135
+ ]
136
+
137
+ [[package]]
138
+ name = "memchr"
139
+ version = "2.8.4"
140
+ source = "registry+https://github.com/rust-lang/crates.io-index"
141
+ checksum = "4566d79b1fa17cb1520b5ec00f8d8865b2121b8e2e27a6ebbac504f45d86eb36"
142
+
143
+ [[package]]
144
+ name = "minimal-lexical"
145
+ version = "0.2.1"
146
+ source = "registry+https://github.com/rust-lang/crates.io-index"
147
+ checksum = "68354c5c6bd36d73ff3feceb05efa59b6acb7626617f4962be322a825e61f79a"
148
+
149
+ [[package]]
150
+ name = "nom"
151
+ version = "7.1.3"
152
+ source = "registry+https://github.com/rust-lang/crates.io-index"
153
+ checksum = "d273983c5a657a70a3e8f2a01329822f3b8c8172b73826411a55751e404a0a4a"
154
+ dependencies = [
155
+ "memchr",
156
+ "minimal-lexical",
157
+ ]
158
+
159
+ [[package]]
160
+ name = "proc-macro2"
161
+ version = "1.0.107"
162
+ source = "registry+https://github.com/rust-lang/crates.io-index"
163
+ checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
164
+ dependencies = [
165
+ "unicode-ident",
166
+ ]
167
+
168
+ [[package]]
169
+ name = "quote"
170
+ version = "1.0.47"
171
+ source = "registry+https://github.com/rust-lang/crates.io-index"
172
+ checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
173
+ dependencies = [
174
+ "proc-macro2",
175
+ ]
176
+
177
+ [[package]]
178
+ name = "rb-sys"
179
+ version = "0.9.130"
180
+ source = "registry+https://github.com/rust-lang/crates.io-index"
181
+ checksum = "02faf625bb10ba893e3ae620f19c9fb1b5f8fcae0fe4eb86bb3f2230fad75edb"
182
+ dependencies = [
183
+ "rb-sys-build",
184
+ ]
185
+
186
+ [[package]]
187
+ name = "rb-sys-build"
188
+ version = "0.9.130"
189
+ source = "registry+https://github.com/rust-lang/crates.io-index"
190
+ checksum = "05be6f9c86fe5482808162826f6c047d093b3670582296c770de1d94f8066694"
191
+ dependencies = [
192
+ "bindgen",
193
+ "lazy_static",
194
+ "proc-macro2",
195
+ "quote",
196
+ "regex",
197
+ "shell-words",
198
+ "syn",
199
+ ]
200
+
201
+ [[package]]
202
+ name = "rb-sys-env"
203
+ version = "0.2.3"
204
+ source = "registry+https://github.com/rust-lang/crates.io-index"
205
+ checksum = "cca7ad6a7e21e72151d56fe2495a259b5670e204c3adac41ee7ef676ea08117a"
206
+
207
+ [[package]]
208
+ name = "regex"
209
+ version = "1.13.2"
210
+ source = "registry+https://github.com/rust-lang/crates.io-index"
211
+ checksum = "9807af0e638c12e753aa1b4e601791bf2a8f71274023c8bbeec12fc149950857"
212
+ dependencies = [
213
+ "aho-corasick",
214
+ "memchr",
215
+ "regex-automata",
216
+ "regex-syntax",
217
+ ]
218
+
219
+ [[package]]
220
+ name = "regex-automata"
221
+ version = "0.4.19"
222
+ source = "registry+https://github.com/rust-lang/crates.io-index"
223
+ checksum = "41d60ef07df457506a0a1a2073112eb4aae5733dbd2813c3da77d1b0fd441158"
224
+ dependencies = [
225
+ "aho-corasick",
226
+ "memchr",
227
+ "regex-syntax",
228
+ ]
229
+
230
+ [[package]]
231
+ name = "regex-syntax"
232
+ version = "0.8.12"
233
+ source = "registry+https://github.com/rust-lang/crates.io-index"
234
+ checksum = "d902046e6a28a1e4c3cab97258a0ce11e994903f01c2d97a9447a0b3df85f4f6"
235
+
236
+ [[package]]
237
+ name = "rustc-hash"
238
+ version = "2.1.4"
239
+ source = "registry+https://github.com/rust-lang/crates.io-index"
240
+ checksum = "ca420ddf5554e546a707e0ecb8bd311d505ee00b40982a7064b8bdc48aa59336"
241
+
242
+ [[package]]
243
+ name = "seq-macro"
244
+ version = "0.3.6"
245
+ source = "registry+https://github.com/rust-lang/crates.io-index"
246
+ checksum = "1bc711410fbe7399f390ca1c3b60ad0f53f80e95c5eb935e52268a0e2cd49acc"
247
+
248
+ [[package]]
249
+ name = "shell-words"
250
+ version = "1.1.1"
251
+ source = "registry+https://github.com/rust-lang/crates.io-index"
252
+ checksum = "dc6fe69c597f9c37bfeeeeeb33da3530379845f10be461a66d16d03eca2ded77"
253
+
254
+ [[package]]
255
+ name = "shlex"
256
+ version = "1.3.0"
257
+ source = "registry+https://github.com/rust-lang/crates.io-index"
258
+ checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
259
+
260
+ [[package]]
261
+ name = "syn"
262
+ version = "2.0.119"
263
+ source = "registry+https://github.com/rust-lang/crates.io-index"
264
+ checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297"
265
+ dependencies = [
266
+ "proc-macro2",
267
+ "quote",
268
+ "unicode-ident",
269
+ ]
270
+
271
+ [[package]]
272
+ name = "unicode-ident"
273
+ version = "1.0.27"
274
+ source = "registry+https://github.com/rust-lang/crates.io-index"
275
+ checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
276
+
277
+ [[package]]
278
+ name = "windows-link"
279
+ version = "0.2.1"
280
+ source = "registry+https://github.com/rust-lang/crates.io-index"
281
+ checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5"
@@ -0,0 +1,22 @@
1
+ [package]
2
+ name = "eth-native"
3
+ version = "0.1.0-pre"
4
+ edition = "2021"
5
+ rust-version = "1.85"
6
+ license = "Apache-2.0"
7
+ description = "Optional Rust native acceleration for eth.rb"
8
+ publish = false
9
+
10
+ [lib]
11
+ name = "eth_native"
12
+ crate-type = ["cdylib"]
13
+ path = "src/lib.rs"
14
+
15
+ [dependencies]
16
+ magnus = { version = "0.9", default-features = false, features = ["io"] }
17
+
18
+ [profile.release]
19
+ opt-level = 3
20
+ lto = true
21
+ codegen-units = 1
22
+ strip = "symbols"
@@ -0,0 +1,15 @@
1
+ # eth-native Rust crate
2
+
3
+ This crate is compiled into `lib/eth/native/eth_native.{so,bundle,dll}` by
4
+ `rb_sys` and `rake-compiler`.
5
+
6
+ M0 exports exactly one function:
7
+
8
+ ```rust
9
+ fn native_abi_version() -> u64 { 1 }
10
+ ```
11
+
12
+ The Ruby loader compares the reported value with
13
+ `Eth::Native::NATIVE_ABI_VERSION` before marking the extension available.
14
+
15
+ RLP and ABI modules are intentionally absent until M1 and M3.
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "mkmf"
4
+ require "rb_sys/mkmf"
5
+
6
+ create_rust_makefile("eth/native/eth_native")