Repository navigation
Performance: Autoload Plugin Classes - #1240
Merged
Merged
Conversation
WordPress Playground🚀 Your PR has been built and is ready for testing in WordPress Playground! |
n7studios
marked this pull request as ready for review
October 9, 2026 10:30
n7studios
requested review from
a team,
ciccio-kit and
noelherrick
and removed request for
a team
October 9, 2026 10:30
noelherrick
approved these changes
Oct 13, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Reduces the memory the Plugin uses on each request by loading class files only when they're used, instead of loading every file when the Plugin starts.
convertkit_autoloader()inwp-convertkit.php. The first time aConvertKit_,CK_orWP_ConvertKitclass is used, it loads the class's file from a list of Plugin folders, with the folders used most on the frontend checked first. Files with code outside the class (integrations that hook in directly, plusfunctions.phpandcron-functions.php) are still loaded withrequire_once.ConvertKit_Admin_Settings::register_sections(), instead of each section file hooking intoconvertkit_admin_settings_register_sectionswhen loaded. Section files are no longer loaded on every request, so they couldn't register themselves. Tab order and the conditions for MCP, Contact Form 7, Forminator and WishList Member are unchanged. The filter still runs, so third-party sections still work.set-screen-optionfilter into theConvertKit_Admin_Settingsconstructor, as it must be registered beforeadmin_init.Frontend peak memory, OPcache off
mainFrontend peak memory, OPcache on
mainWith OPcache on, compiled code lives in shared memory, so the saving per request is small (~9KB). The main gains are on hosts without OPcache, cold caches, WP-CLI and cron. Frontend requests now include 60 plugin files instead of 155.
This won't fix the specific creator's issue in WP-95, given the memory usage is already low, their environment has a strangely low memory limit of 128M, and their other plugins contribute to the issue - but will hopefully prevent it for other creators in the future.
Testing
AutoloadTest::testAllClassesCanBeAutoloaded: every class in/includesand/adminis autoloaded from its own file. A class in a folder that isn't in the autoloader's list fails this test.AutoloadTest::testNonPluginClassesAreIgnored: the autoloader does nothing for classes that don't belong to the Plugin.Checklist