ref-fvm icon indicating copy to clipboard operation
ref-fvm copied to clipboard

Optimize IPLD Operations

Open Stebalien opened this issue 3 years ago • 5 comments

  • [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

Stebalien avatar Feb 16 '22 03:02 Stebalien

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!

jennijuju avatar Mar 07 '22 17:03 jennijuju

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:

  1. Have go call into rust, then wait on a channel for a block request.
  2. 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.

Stebalien avatar Mar 07 '22 17:03 Stebalien

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 avatar Mar 07 '22 18:03 Stebalien

@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)

dignifiedquire avatar Mar 08 '22 09:03 dignifiedquire

  • 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.

Stebalien avatar Mar 08 '22 13:03 Stebalien