nextcloud / nextcloud/server

Performance: autoloader is executed too many times and is slow

Open
#40,236 2 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

0. Needs triage 25-feedback bug feature: files performance 🚀
Dominant language
PHP
Stars
36.9k
Forks
5.2k
Avg merge
2d 3h
Merged PRs (30d)
713

Description

⚠️ This issue respects the following points: ⚠️
Bug description

When benchmarking the login page of NextCloud, I found out it was extremely slow, about 12 requests / second on my laptop, compared to around 380 requests / second on the login page of another PHP app I'm developing.

The login page is making 29 SQL requests, and is loading 768 files of PHP code (!).

When watching what's going on with Xdebug profiler I can see that classLoader::loadClass from Composer is executed more than 14.000 times and is taking 13% of the execution time. That's a lot. Most of the time it doesn't do much as the required file is not part of this composer instance (as all projects have their own composer loader). It seems that there are dozens of composer loaders registered, and every one is called until the correct project loader is found. For each of the 700 included files.

I tried writing a short autoloader that will just store a cache of all files and have only one instance (see attached patch). It's just a proof of concept, not a ready-to-implement patch (hence why the bug report and not a PR).

0001-Alternative-autoloader.patch.gz

This is a very simple and nave approach, just to see the impact it has.

With it I get only 752 calls, and it is now only using 3.5% of the execution time.

It's likely that there are better options out there, but this was just a quick test and a pointer on a place where NextCloud performance could be made better. Even though it should be questioned why a simple login page is doing so many requests and loading so many unrelated classes.

Steps to reproduce

--

Expected behavior

--

Installation method

None

Nextcloud Server version

25

Operating system

None

PHP engine version

None

Web server

None

Database engine version

None

Is this bug present after an update or on a fresh install?

None

Are you using the Nextcloud Server Encryption module?

None

What user-backends are you using?
  • Default user-backend (database)
  • LDAP/ Active Directory
  • SSO - SAML
  • Other
Configuration report

No response

List of activated Apps

No response

Nextcloud Signing status

No response

Nextcloud Logs

No response

Additional info

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by profiling the login page and examining Composer's classLoader::loadClass calls, using the attached alternative-autoloader patch as a performance reference. Compare the loader-call count and execution time with the current behavior, then define a solution that reduces redundant autoloader work without changing class loading behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
php
Domain
backend, performance
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.