Our Experience Building a Hybrid Rust - C++ Project

For the past four months, I’ve been actively contributing to a new Rust-C++ project. Through this process, I’ve gained valuable insights and lessons. While I can’t disclose many project details, there are numerous technical challenges worth elaborating.

The linking problem

Thread or coroutine?

Benefits of using coroutine:

  • Smaller memory cost, so we can create more coroutines.
  • Context switch is faster because there is no syscall.

Pitfalls of using tokio:

  • Runtime can only be created outside the “async context” of tokio. So if we need to use tuned Runtimes, we have to create them in advance. This involves lots of refactors.

Shared Memory or Actor?

Online config change

There are some ways:

  • For every actor, introduce a new UpdateConfig event, and handle it in the message loop.
  • Using arc_swap