davidcole1340 / ext-php-rs

Bindings for the Zend API to build PHP extensions natively in Rust.
Apache License 2.0
598 stars 64 forks source link

Slower Than C #310

Open arshidkv12 opened 9 months ago

arshidkv12 commented 9 months ago

Hi I tested with xdebug profile option with grind cache. Functions are slower than c. How to speed up?

ryangjchandler commented 8 months ago

The difference in speed is likely due to converting between PHP types (Zval) and Rust types such as String, Vec, etc.

joehoyle commented 4 months ago

I think to test this assumption it could be a good idea to benchmark:

#[php_function]
fn should_be_fast(&Zval zval ) -> Zval {
    zval.shallow_clone()
}

I suspect we might actually have several inefficiencies in the calling bridging, unnecessarily allocating etc.

ryangjchandler commented 4 months ago

That would just be benchmarking a direct clone of a Zval though right? Not the Vec<T> allocations, etc?

joehoyle commented 4 months ago

I'm not sure, I think the #[php_function] may generate code that has additional allocations etc in.