Skip to content

perf: direct syscall fastpath for absolute paths in zend_virtual_cwd#22722

Open
henderkes wants to merge 1 commit into
php:masterfrom
henderkes:perf/vcwd-direct
Open

perf: direct syscall fastpath for absolute paths in zend_virtual_cwd#22722
henderkes wants to merge 1 commit into
php:masterfrom
henderkes:perf/vcwd-direct

Conversation

@henderkes

Copy link
Copy Markdown
Contributor

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

<?php
chdir(__DIR__);

$s = microtime(true);
for ($i = 0; $i < 1000000; $i++) {
    file_exists("data.txt");
}
$rel = microtime(true) - $s;

$abs = __DIR__ . "/data.txt";
$s = microtime(true);
for ($i = 0; $i < 1000000; $i++) {
    file_exists($abs);
}
$abs_t = microtime(true) - $s;
workload master patch delta
relative path 0.3521s 0.3524s +0.09%
absolute path 0.3162s 0.2623s −17.05%

Comment thread Zend/zend_virtual_cwd.c

#ifndef ZEND_WIN32
if (virtual_path_is_direct(path)) {
return fopen(path, mode);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this use php_win32_ioutil_fopen on windows?

@staabm staabm Jul 14, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohh its ifNdef ZEND_WIN32 .. nevermind

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I will revisit all these small findings later on Windows

@henderkes

Copy link
Copy Markdown
Contributor Author

Just realised that this doesn't apply to dirty composer autoloader paths with ../vendor/*. Is there any site resolving a path lexically instead of physically? If not I could drop the dot checks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants