Hi Internals,
I did a somewhat rough test to compare Composer's autoloader and the
function proposed in the RFC.

## TL;DR:

Composer autoloader + Opcache:
autoload_set_classmap + Opcache:


## Long version:

Using symfony/framework-bundle , symfony/console, and phpunit/phpunit,
in a new composer project, I created a classmap (`composer
dump-autoload -ao`) in `vendor/composer/autoload_classmap.php`, file.
To keep the test fair, I removed the Composer autoload.files (always
include those files), and platform-check to keep the test fair. I had
to comment out the "Error during autoloading from classmap. Entry
\"%s\" failed to load the class from \"%s\" (Class undefined after
file included)" exception because it errored for valid classes. Using
Composer 2.

Benchmark called `class_exists()` on the Composer-generated classmap,
with autoloading enabled. On the same tests, it called 10K
`class_exists('test\\test_' . $i)` where $i = 1...10K. Results are
averaged from 3 runs.

**Composer autoloader**
With OPCache: 20.337 sec.
Without OPCache: 20.042 sec.

**autoload_set_classmap**
With OPCache: 18.684 sec
Without OPCache: 18.451 sec

**Performance gain**
autoload_set_classmap over Composer with OPCache: 8.12%
autoload_set_classmap over Composer without OPCache: 7.93%

I think 7-8% difference is more of a best-case scenario for
autoload_set_classmap, because the default unauthoritative classmap
has PSR-4/0/files/classmap features, and some sanity checks to avoid
collisions. That, I don't think a reasonable PHP application will have
2K autoload hits and 10K misses. This is indeed an improvement, and
something I would use myself if approved. However, I doubt real-life
applications would see any noticeable difference in other measures
such as response time or req/sec count.

Smile,
Ayesh.

On Fri, Mar 19, 2021 at 8:16 PM Nikita Popov <nikita....@gmail.com> wrote:
>
> On Mon, Mar 15, 2021 at 6:41 PM Mark Randall <marand...@php.net> wrote:
>
> > Hi Internals,
> >
> > I would like to propose the addition of a new mechanism of autoloading
> > classes - a classmap that will be consulted prior to checking the
> > spl_autoload_register'd callbacks.
> >
> > https://wiki.php.net/rfc/autoload_classmap
>
>
> Could you please update the RFC with some performance numbers, including
> the used methodology? The number of 5% has been floating around, but it's
> not clear what it refers to. I'm primarily interested in end-to-end effect,
> e.g. on the symfony demo project.
>
> Regards,
> Nikita

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to