tlopex commented on PR #806: URL: https://github.com/apache/tvm-ffi/pull/806#issuecomment-5756108882
Benchmark comparison on AMD Threadripper 3970X, pinned to one core. Rust 1.97.1 (release, thin LTO) and Clang 18.1.3 (`-O3`) use the same native runtime. Times are medians of seven measurements per traversal; input construction and validation are excluded. Lower is better. **4,096 integers, uniquely owned array — µs/traversal:** | Operation | C++ | Rust | | --- | ---: | ---: | | Visit | 12.50 | 9.29 | | Walk, pre-order | 41.18 | 8.84 | | Walk, post-order | 42.13 | 8.89 | | Map, pre-order | 95.73 | 13.42 | | Map, post-order | 134.94 | 13.46 | | Mutate | 27.77 | 9.87 | | Mutate, `Unchanged` | 11.55 | 9.41 | | Walk, pre-order + policy | 42.07 | 31.07 | | Mutate + policy | 27.78 | 9.92 | Visit and walk collect statistics. Map and mutate increment each integer; `Unchanged` callbacks leave values unchanged. Pre-order callbacks run before children, post-order callbacks afterward. The policy tracks nesting depth around default recursion. **Other structures, without policy — µs/traversal:** | Workload | C++ | Rust | | --- | ---: | ---: | | Shared array, mutate | 61.19 | 66.60 | | Reflected binary tree, mutate | 105.90 | 111.49 | | Reflected binary tree, closure callbacks returning `Unchanged` | 72.23 | 80.07 | | Shared-node DAG, mutate | 180.52 | 206.23 | - Shared array: 4,096 integers with another owner retained, requiring copying when changed. - Binary tree: 1,023 reflected objects and 1,024 integer leaves. - DAG: 4,096 references to 512 distinct objects, exercising identity remapping. **128 index expressions with four nested div/mod expansion levels — ms/traversal:** | Operation | C++ | Rust | | --- | ---: | ---: | | Map simplification | 3.167 | 2.309 | | Map simplification + policy | 3.165 | 4.022 | | Mutate simplification | 2.944 | 3.123 | | Mutate simplification + policy | 3.067 | 4.086 | Both apply the same rules, including `(x // 8) * 8 + x % 8 → x`, constant folding, and removing `+ 0` / `* 1`. Map uses post-order; mutate explicitly processes children before rewriting. The policy tracks expression depth. All 186 configurations passed output and callback/state checks. Rust is faster on the uniquely owned arrays; shared/reflected mutation and expression mutation with policies remain slower in these local measurements. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
