perf: direct syscall fastpath for absolute paths in zend_virtual_cwd#22722
perf: direct syscall fastpath for absolute paths in zend_virtual_cwd#22722henderkes wants to merge 2 commits into
Conversation
|
|
||
| #ifndef ZEND_WIN32 | ||
| if (virtual_path_is_direct(path)) { | ||
| return fopen(path, mode); |
There was a problem hiding this comment.
should this use php_win32_ioutil_fopen on windows?
There was a problem hiding this comment.
ohh its ifNdef ZEND_WIN32 .. nevermind
There was a problem hiding this comment.
yeah, I will revisit all these small findings later on Windows
|
Just realised that this doesn't apply to dirty composer autoloader paths with |
henderkes
left a comment
There was a problem hiding this comment.
The only thing I'm not entirely sure is whether we couldn't switch to using fstatat and siblings instead of doing the manual string operations for every path operation that doesn't need the resolved string.
Most importantly, ZTS (/a/c) differs from what NTS is doing (/x/c) when it could be using direct syscalls, get NTS' performance and also resolve (correctly) even for relative paths.
| #endif | ||
|
|
||
| CWD_STATE_COPY(&new_state, &CWDG(cwd)); | ||
| if (virtual_file_ex(&new_state, path, NULL, CWD_EXPAND)) { |
There was a problem hiding this comment.
just realized github doesn't display these lines by default in the diff - the use_realpath parameter to virtual_file_ex is passed through to tsrm_realpath_r which does:
save = (use_realpath != CWD_EXPAND); // line 573which disables per-component lstat/readlink. So it strips .. segments lexically and may get a different path.
Example:
/a/b/../c
/a/b is a symlink to /x
lstat/readlink resolve to /x/c
virtual_lstat resolves to /a/c
Absolute paths don't need to go through the per-thread cwd emulation, add a fast-path to directly hand them to libc.
since relative paths won't start with a leading slash, this adds negligible cost for them
Benchmark for Symfony demo:
cc @dunglas because this will be a nice improvement for frankenphp (though fpm alike) in 8.6 :)