Does using PyO3 make it slower than natively using Rust?

I am curious to know if I used PyO3 in Rust, is it slower than natively using just Rust?

As with any such question, this can only be answered by measuring the concrete timings. In general case, yes, it will be slower, because Python objects are essentially Rc<RefCell<dyn Any>>, so you'll usually pay runtime cost for both shared mutability and dynamic dispatch, whether you really need it or not.

Isn't it possible to disable reference counting?

I'm not entirely sure what you're asking here. PyO3 offers rust bindings for the C Python interpreter. If you're comparing the same thing implemented in Rust against the same thing implemented in Python then called from Rust, Rust will be faster (basically) because it's a compiled language and Python is an interpreted language.

Of course, they can co-exist very well, normally one'd use Python only for high level scripting and Rust for the computation heavy inner loops.

But I'm not sure if that's what you're asking.

I see, that makes sense now, thanks man.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.