Chia-Network / clvm_rs

Rust implementation of clvm
Apache License 2.0
67 stars 54 forks source link

run_program for `op_point_add` is slow. Even slower than Python's clvm #104

Closed ChiaMineJP closed 2 years ago

ChiaMineJP commented 2 years ago

It is really strange, but I got the same results even I tried benchmark multiple times.

I am releasing production-ready version of clvm_tools-js and I am currently benchmarking to compare performance with:

In summary, clvm in Rust implementation works great in run_program. It is around 30-100 times faster than other implementation in most cases. (But be aware, to_sexp_f benchmark is 5-10 times slower than other implementation. This is another story.)

When I got the benchmark result, I found that op_point_add is slower than Python implementation of clvm. This is really strange. I haven't started investigation yet, but I'd like to share the current data with you.

The benchmark was done using benchmark files generated by costs/generate-benchmark.py in clvm_tools. The benchmark parameters are:

I modified generate-benchmrk.py a bit to produce benchmark files with such parameters. I thought value_size = 4bytes and operations count = 200 seems to be typical among most of chialisp programs.

run_program

benchmark-result-32bit-value-200-ops_run_program

to_sexp_f

If you are interested, here is the result of to_sexp_f benchmark.

benchmark-result-32bit-value-200-ops_to_sexp_f

richardkiss commented 2 years ago

The reason for the difference in pubkey_for_exp is because clvm uses bls-signatures (aka blspy), and clvm_rs uses https://github.com/zkcrypto/bls12_381.

richardkiss commented 2 years ago

Note that clvm_rs is now an npm package https://www.npmjs.com/package/clvm_rs containing wasm32. The api is not good yet, but PRs are most welcome. See also https://github.com/Chia-Network/clvm_rs/tree/main/src/wasm. With this code, you may be able to speed up clvm(js) and clvm_tools(js)

richardkiss commented 2 years ago

In clvm_rs, op_point_add does from_compressed instead of from_compressed_unchecked, which is probably a lot slower. However, making this change would probably be a hard fork.

ChiaMineJP commented 2 years ago

@richardkiss I'll try to import clvm_rs into clvm_tools-js soon. I already have an idea on how to integrate clvm_rs into clvm_tools-js.