Skip to content

Performance: Autoload Plugin Classes - #1240

Merged
n7studios merged 4 commits into
mainfrom
improve-memory-performance
Oct 14, 2026
Merged

n7studios merged 4 commits into
mainfrom
improve-memory-performance

Conversation

@n7studios

@n7studios n7studios commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

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.

  • Registers convertkit_autoloader() in wp-convertkit.php. The first time a ConvertKit_, CK_ or WP_ConvertKit class 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, plus functions.php and cron-functions.php) are still loaded with require_once.
  • Registers Kit's own settings sections in ConvertKit_Admin_Settings::register_sections(), instead of each section file hooking into convertkit_admin_settings_register_sections when 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.
  • Moves the Form Entries set-screen-option filter into the ConvertKit_Admin_Settings constructor, as it must be registered before admin_init.

Frontend peak memory, OPcache off

Peak Plugin overhead
No Plugin 34.51MB –
main 40.40MB +5.89MB
This PR 37.06MB +2.54MB (−57%)

Frontend peak memory, OPcache on

Peak Plugin overhead
No Plugin 4.48MB –
main 4.91MB +0.42MB
This PR 4.90MB +0.42MB (−2%)

With 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 /includes and /admin is 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.
  • Existing settings, Form Entries, integration and Integration tests pass unchanged.

Checklist

@n7studios n7studios self-assigned this Oct 8, 2026
@github-actions

github-actions Bot commented Oct 9, 2026

Copy link
Copy Markdown

WordPress Playground

🚀 Your PR has been built and is ready for testing in WordPress Playground!

Click here to test your changes in WordPress Playground

@n7studios
n7studios marked this pull request as ready for review October 9, 2026 10:30
@n7studios
n7studios requested review from a team, ciccio-kit and noelherrick and removed request for a team October 9, 2026 10:30
@n7studios n7studios added this to the 3.4.7 milestone Oct 9, 2026
@n7studios
n7studios merged commit 471f377 into main Oct 14, 2026
617 of 628 checks passed
@n7studios
n7studios deleted the improve-memory-performance branch October 15, 2026 04:41
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