From f851c6ce90e1f6266aa53c6a4befba4d9ac34e74 Mon Sep 17 00:00:00 2001 From: Christoph Wurst Date: Fri, 20 Jan 2023 16:56:25 +0100 Subject: [PATCH] feat(dev-manual): Document performance optimizations with class loaders Signed-off-by: Christoph Wurst --- .../digging_deeper/classloader.rst | 25 ++++++++++++++++++- .../digging_deeper/performance.rst | 5 ++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/developer_manual/digging_deeper/classloader.rst b/developer_manual/digging_deeper/classloader.rst index 463e17bc3..540e0a47a 100644 --- a/developer_manual/digging_deeper/classloader.rst +++ b/developer_manual/digging_deeper/classloader.rst @@ -10,7 +10,7 @@ The classloader is provided by Nextcloud and loads all your classes automaticall PSR-4 autoloading ----------------- -Nextcloud uses a PSR-4 autoloader. The namespace **\\OCA\\MyApp** +Nextcloud uses a :ref:`PSR-0 autoloader`. The namespace **\\OCA\\MyApp** is mapped to :file:`/apps/myapp/lib/`. Afterwards normal PSR-4 rules apply, so a folder is a namespace section in the same casing and the class name matches the file name. @@ -32,3 +32,26 @@ info.xml in the following way: A second PSR-4 root is available when running tests. **\\OCA\\MyApp\\Tests** is thereby mapped to :file:`/apps/myapp/tests/`. + +.. _app-custom-classloader: + +Replacing Nextcloud's autoloader +-------------------------------- + +Nextcloud's autoloader for apps is flexible and robust but not always the fastest. You can improve the loading speed of your app by shipping and optimizing a Composer class loader with the app. + +First of all, familiarize yourself with the `Composer autoloader optimization options `_ and how they work. (Authoritative) class maps are a good fit for Nextcloud apps. + +Once Composer is set up and class maps have been dumped, you can replace the generic Nextcloud class loader with the Composer class loader. This is done by placing a file at `composer/autoload.php`. If Nextcloud finds this file for an app, no generic class loader will be registered. The following contents will wire the file to Composer's generated ``autoloader.php`` file: + +.. code-block:: php + :caption: composer/autoload.php + + `. The application code does not have to change for this optimization. + Database performance --------------------