Skip to content

Fix PFA caching with file_cache_only after priming from SHM - #25709

Open
arnaud-lb wants to merge 2 commits into
php:PHP-8.6from
arnaud-lb:pfa-caching
Open

arnaud-lb wants to merge 2 commits into
php:PHP-8.6from
arnaud-lb:pfa-caching

Conversation

@arnaud-lb

@arnaud-lb arnaud-lb commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Follow up GH-25374.

PFAs that will not be cached in SHM are cached in EG(partial_function_application_cache) instead. The cache key is concat(PFA name addr, called fun addr) with the assumption that the name is not interned, therefore has a unique address.

A file cache primed from SHM breaks this assumption: In that case the name is interned before being persisted to the file cache. On a subsequent file_cache_only request the PFA will not be SHM-cacheable, but its name will not be unique either.

Fix by using &ast->lineno as key, which is unique as long as the AST is live. Invalidate related cache entries when destroying the AST.

Fixes https://github.com/php/php-src/actions/runs/45303330074/job/138141503801#step:13:151

cc @jorgsowa

PFA that can not be cached in SHM are cached in EG(partial_function_application_cache).
The cache key is concat(PFA name addr, called fun addr) with the assumption that
PFA names are not interned, therefore have a unique address.

File cache breaks this assumption.

Fix by using &ast->lineno as key prefix, which is unique as long as the
AST is live. Invalidate related cache entries when destroying the AST.

@jorgsowa jorgsowa left a comment

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.

Looks good to me.

zend_hash_add_new_ptr(&EG(partial_function_application_cache), key, op_array);
zend_string_release(key);

if (!declaring_op_array) {

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.

Suggested change
if (!declaring_op_array) {
if (!declaring_op_array && !zend_accel_in_shm((void*)declaring_lineno_ptr)) {

It's dead entry when declaring_lineno_ptr is in SHM

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