You could try having it rewrite parts of the hot path into Rust with PyO3.