-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
Autoloading WordPress classes #3470
base: trunk
Are you sure you want to change the base?
Conversation
6f5d207
to
aa17c97
Compare
Ohhh, love this PR! |
Not quite... 😄 Worth noting: |
I'm also thinking that at very least, it's a DX improvement and future unlocker. If it lands with no performance regressions, that's cherry on top. |
Hey @aristath are you daily driving this by any chance, or is anybody else? Wondering if I could become real hands-on for testing this in my semi-production / staging env 🤔 or will everything blow up instantly. |
Hey @lkraav! The implementation here is complete, and the autoloader works as expected. I haven't seen anything "blow up"... I plan to create a new trac ticket when the time comes and publish a formal proposal, so any testing and additional data we have will be greatly appreciated! 👍 |
Ah, this brings up a compatibility question - I'd like to stay in at least release candidate stability, but I guess this branch is constantly moving with trunk? Maybe you have tags available so I could merge only up to some "latest compatible with 6.1, or 6.2" state? |
Yeah, I'm keeping it up to date with trunk constantly... |
I'm running into trouble trying to apply it to release WP at https://github.com/WordPress/WordPress.git didn't think of that before.
EDIT This hunk gets rejected on top of 6.2 RC2 $ [-] cat index.php.rej
diff a/index.php b/index.php (rejected hunks)
@@ -19,9 +19,8 @@
/*
* Load the actual index.php file if the assets were already built.
- * Note: WPINC is not defined yet, it is defined later in wp-settings.php.
*/
-if ( file_exists( ABSPATH . 'wp-includes/js/dist/edit-post.js' ) ) {
+if ( file_exists( ABSPATH . WPINC . '/js/dist/edit-post.js' ) ) {
require_once ABSPATH . '_index.php';
return;
} Aha but I see this Skimmed through our sites, and everything seems to be working 💪 no crashes! |
3a6050e
to
daac22d
Compare
@spacedmonkey The front-end performance test suite for this pull request appears to show a performance improvement for both classic and block themes: That's with 20 runs against the |
24d7ccd
to
81aabba
Compare
This file will need to be broken up into multiple files. |
Since I lack the ability to test memory consumption reliably, I think a good measure would be the test-suite results posted in this PR. https://github.com/WordPress/wordpress-develop/actions/runs/8264293168
|
Have you considered having multiple smaller autoload.php files instead of just one big |
I'm curious if you have explored bundling Composer\Autoload\ClassLoader instead of building a new autoloader? It's more or less the standard nowadays, it's battle-tested, and it already supports working with classmaps $composer = new \Composer\Autoload\ClassLoader();
$composer->addClassMap([
'wp_hook' => 'wp-includes/class-wp-hook.php',
'wp_locale' => 'wp-includes/class-wp-locale.php',
]);
$composer->register(); It seems to me there will be an additional benefit as there are a lot of plugins and themes that are already using composer, although in a local capacity. |
@@ -21,8 +21,7 @@ | |||
* @since 1.5.0 | |||
*/ | |||
|
|||
// Initialize the filter globals. | |||
require __DIR__ . '/class-wp-hook.php'; | |||
require_once ABSPATH . 'wp-includes/class-wp-autoload.php'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is curious -- is src/wp-includes/plugin.php
included/required before the wp-autoload is set? And that's why it is necessary to include it here as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't remember exactly the scenario that required this... But in all cases where I added this line in various files, it was because without it I was getting errors either when using WP, or when running PHPUnit tests 🤔
I don't remember exactly the case, but this is one of the files that plugins/themes frequently include manually in order to load various functions, so maybe that's why I was getting errors 🤷
@kktsvetkov acutely aware, discussion of it completely derailed the last attempt to include composer setting things back years. Having said that there was discussion of using composer to generate the file mappings, but you're best referring to the Make WP post for specifics, this isn't the place for it |
I'm not suggesting using composer as it is used in general, instead only utilizing the ClassLoader as available solution. I did manage to read the previous thread, and you are right - the composer discussion did seem to get out of hand. |
Trac ticket: https://core.trac.wordpress.org/ticket/60414
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.