ext-php-rs icon indicating copy to clipboard operation
ext-php-rs copied to clipboard

Slower Than C

Open arshidkv12 opened this issue 1 year ago • 4 comments

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

arshidkv12 avatar Jan 24 '24 08:01 arshidkv12

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

ryangjchandler avatar Feb 14 '24 21:02 ryangjchandler

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.

joehoyle avatar Jun 23 '24 13:06 joehoyle

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

ryangjchandler avatar Jun 23 '24 14:06 ryangjchandler

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

joehoyle avatar Jun 23 '24 14:06 joehoyle