Skip to content

Perf/reorganize autoloading - #62231

Draft
come-nc wants to merge 15 commits into
masterfrom
perf/reorganize-autoloading
Draft

Perf/reorganize autoloading#62231
come-nc wants to merge 15 commits into
masterfrom
perf/reorganize-autoloading

Conversation

@come-nc

@come-nc come-nc commented Jul 16, 2026

Copy link
Copy Markdown
Contributor
  • Resolves: #

Summary

The idea here is to have only one autoloader instead of one by application, with a cached classmap in a PHP file.
On a test instance (debug mode on) I get 500ms instead of 600ms to run occ status.
The cached array in PHP file mechanism could be leveraged for other optimizations.

TODO

  • Fix tests if needed
  • Remove debug output
  • Remove TODO comments
  • Clean up git history
  • Rework tooling related to autoloader (build/autoloadchecker.sh notably)
  • Document
  • Rename/move new classes to a namespace
  • Add tests for new classes
  • Move core and lib to PSR4 scanning
  • Remove parts of Autoloader we do not use (leftover from nette)
  • Test updates, app installs, app upgrades…
  • Figure out how to manage temp directory (default location, opcache config, deletion of old files, permissions, and so on)
  • Improve installation usecase (currently results in 26 disk scans because each app installation triggers one, and 26 files in cache afterwards)
  • Avoid having to compute namespaces from enabled apps, directly cache autoloading and namespaces. Maybe appinfo as well?

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

@come-nc come-nc self-assigned this Jul 16, 2026
Comment thread lib/private/Autoloader.php Fixed
Comment thread lib/private/Autoloader.php Fixed
@icewind1991

Copy link
Copy Markdown
Member

(I'm very hesitant about this approach but don't really know how to formulate my reasoning, but leaving a note for a soft-disagreement until I can better word things or change my mind)

@come-nc

come-nc commented Aug 7, 2026

Copy link
Copy Markdown
Contributor Author

(I'm very hesitant about this approach but don't really know how to formulate my reasoning, but leaving a note for a soft-disagreement until I can better word things or change my mind)

Is your disagreement with the PhpDumpCache API or the autoloader change?
I’m willing to work on both aspects but I think we cannot avoid rethinking the autoloader to use a maintained classmap at some point, it’s too much of a performance boost.

I did the PhpDumpCache part that way because I would like to re-use it for other things, notably caching commands as in this draft: #61865
And PHP on-disk is the fastest cache you can get, it ends up in the opcache.

come-nc added 11 commits August 13, 2026 14:39
This leverages opcache to be as fast as possible. Can be used for
 autoloading class maps, but also for other kind of pre-computed cached
 arrays (routes, occ commands, …).

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
The idea is to cache to disk a static classmap with all classes from
 core and applications.

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
cachedirectory still needs to be added to config.sample.php

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
There was a weird inconsistent mix of Test\, Tests\lib, Test\Core,
 Tests\Core and Core\.
Now there is only Test\ for tests/lib/ and Tests\Core for tests/Core.

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
@come-nc
come-nc force-pushed the perf/reorganize-autoloading branch from cdca333 to b688559 Compare August 13, 2026 12:39
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
Avoids parsing info.xml from each app and recomputing namespaces. For
 now Autoloader still has its own calls to PhpDumpCache which is a bit
 dirty, we might want to clean that up later.

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
…mmmands

This saves 100ms on occ runs by avoiding to load all commands to only
 run one of them. The list of commands is cached and loading is skipped
 when command is known.

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
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