ref-fvm
ref-fvm copied to clipboard
Optimize IPLD Operations
- [x] Remove redundant copies from CGO.
- [ ] Use a dedicated thread in Go for message passing instead of directly calling with CGO. Calling from Rust to Go is very slow as it effectively schedules a new goroutine per call.
- [x] Try an FVM-side read-cache. We should also play with just caching the state-tree itself (but not actor state).
- [x] Optimize Flush: https://github.com/filecoin-project/ref-fvm/issues/331
Dig may be able to take a look at the second check box starting next week. @Stebalien - if you have any details in your head please add!
Use a dedicated thread in Go for message passing instead of directly calling with CGO. Calling from Rust to Go is very slow as it effectively schedules a new goroutine per call.
Specifically, instead of loading blocks by calling into go:
- Have go call into rust, then wait on a channel for a block request.
- In rust, write block requests to this channel.
This should reduce the CGO overhead by ~10x by having all calls go from Go to Rust, instead of from Rust to Go. Of course, other scheduling issues could make this slower in practice, so :man_shrugging:?
We could also skip calling from go to rust entirely by blocking on some system-level mutex in Rust.... but that may be significantly harder.
Before implementing, make sure to test a crappy version first to validate this approach. It should be faster, but could also be significantly slower.
@Stebalien can you point me at the main code paths where this is happening today? Is there a test/benchmark that already exists that shows the current preformance of the system (ideally isolated)
- The go side is in https://github.com/filecoin-project/filecoin-ffi/blob/asr/fvm/cgo/blockstore.go.
- The rust side is https://github.com/filecoin-project/filecoin-ffi/blob/asr/fvm/rust/src/fvm/blockstore.rs.
For testing/benchmarks, I've been using https://github.com/filecoin-project/cgo-blockstore/blob/master/example/main_test.go.