[php-src] PR #20429: Make user space streams faster
| From: | ndossche | Date: | Sat, 08 Nov 2025 22:00:30 +0000 |
| Subject: | [php-src] PR #20429: Make user space streams faster | ||
| Groups: | php.git-pulls | ||
| Request: | Send a blank email to git-pulls+get-33980@lists.php.net to get a copy of this message | ||
Pull Request: https://github.com/php/php-src/pull/20429
Author: ndossche
Needs more testing, but shows the general idea.
Small PoC bench:
```php
<?php
class MyStream {
public $context;
public function stream_open(
string $path,
string $mode,
int $options,
?string &$opened_path
): bool {
// debug_print_backtrace();
return true;
}
public function stream_read(int $count): string|false {
return 'abc';
}
public function stream_eof(): bool {
return false;
}
}
stream_wrapper_register('my', MyStream::class);
$f = fopen('my://', 'r');
for ($i = 0; $i < 1000000; $i++)
fread($f, 4096);
```
On my i7-4790:
```
Time (mean ± σ): 135.6 ms ± 3.9 ms [User: 132.8 ms, System: 2.3 ms]
Range (min … max): 132.8 ms … 151.6 ms 22 runs
Warning: Statistical outliers were detected. Consider re-running this benchmark on a quiet system
without any interferences from other programs. It might help to use the '--warmup' or
'--prepare' options.
Benchmark 2: ./sapi/cli/php_old x.php
Time (mean ± σ): 234.3 ms ± 5.7 ms [User: 231.4 ms, System: 2.2 ms]
Range (min … max): 229.4 ms … 249.6 ms 12 runs
Summary
./sapi/cli/php x.php ran
1.73 ± 0.07 times faster than ./sapi/cli/php_old x.php
```