Skip to content

Preload unlinked classes, remove preload autoload #7311

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 28, 2021

Conversation

nikic
Copy link
Member

@nikic nikic commented Jul 27, 2021

Currently, classes that can't be linked get moved back into the original script and are not preloaded. As such classes may be references from functions that did get preloaded, there is a preload autoload mechanism to load them at runtime.

Since PHP 8.1, we can safely preload unlinked classes, which will then go through usual lazy loading. This means that we no longer need the preload autoload mechanism. However, we need to be careful not to modify any hash table buckets in-place, and should create new buckets for lazy loaded classes.

@nikic
Copy link
Member Author

nikic commented Jul 27, 2021

@dstogov What do you think about this?

@nikic nikic force-pushed the preload-no-autoload branch from 7c89f95 to a274234 Compare July 27, 2021 14:59
Copy link
Member

@dstogov dstogov left a comment

Choose a reason for hiding this comment

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

This looks awesome!

success = zend_hash_set_bucket_key(EG(class_table), (Bucket*) class_table_slot, Z_STR_P(lcname)) != NULL;
} else {
/* If preloading is used, don't replace the existing bucket, add a new one. */
success = zend_hash_add_ptr(EG(class_table), Z_STR_P(lcname), ce) != NULL;
Copy link
Member

Choose a reason for hiding this comment

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

why this is necessary?

Copy link
Member Author

Choose a reason for hiding this comment

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

If the original bucket (< persistent_classes_count) is replaced, it won't get cleaned up on shutdown, and we'll leak a class from the previous request into the next one.

@@ -3021,18 +3021,24 @@ zend_class_entry *zend_try_early_bind(zend_class_entry *ce, zend_class_entry *pa
zend_class_entry *proto = NULL;
zend_class_entry *orig_linking_class;
uint32_t is_cacheable = ce->ce_flags & ZEND_ACC_IMMUTABLE;
bool is_preloaded = ce->ce_flags & ZEND_ACC_PRELOADED;
Copy link
Member

Choose a reason for hiding this comment

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

I think, it may be more efficient to check the flag each time. Checking it once, but than checking another local variable doesn't make a lot of sense.

nikic added a commit that referenced this pull request Jul 28, 2021
This is the same for the cached and uncached cases and will make
GH-7311 a bit simpler.
@nikic nikic force-pushed the preload-no-autoload branch from a274234 to 8b85a9c Compare July 28, 2021 09:25
@nikic nikic merged commit e011952 into php:master Jul 28, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants