You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Composer's autoloader need to [require all Safe files](https://github.com/thecodingmachine/safe/blob/05925e1d2abe0c0fee2095c1d569a1302a1a209e/composer.json#L13-L97)
5
+
on each request (since there is no autoloader for functions in PHP).
6
+
7
+
"Requiring" those ~84 files in PHP has a performance impact. We used [Blackfire](http://blackfire.io/) to time precisely the impact of loading the PHP files.
|[Composer autoload without Safe](https://blackfire.io/profiles/cb9122ac-69a7-4e90-9ea7-bf7561058815/graph)| 264µs |
15
+
|[Composer autoload with Safe](https://blackfire.io/profiles/35eb02eb-60f8-480a-bad0-0cfc43179c18/graph)| 1.03ms |
16
+
17
+
Safe load time: **~700µs**
18
+
19
+
Only 700µs for loading 84 files containing 1000+ functions. Damn, PHP is fast! Opcache does a very good job.
20
+
21
+
The tests have been performed on a DELL XPS 9550 laptop running Ubuntu 18.04 and Docker. CPU: [Intel(R) Core(TM) i7-6700HQ](https://ark.intel.com/products/88967/Intel-Core-i7-6700HQ-Processor-6M-Cache-up-to-3-50-GHz-)
22
+
23
+
Reproducing the test
24
+
--------------------
25
+
26
+
There are 2 test files:
27
+
28
+
-`test_with_safe/index.php`: loads Composer autoloader with Safe
29
+
-`test_without_safe/index.php`: loads Composer autoloader without Safe
30
+
31
+
Both test files are only loading Composer autoloader (with and without Safe), then echoing "foo".
32
+
33
+
For each file, you need to install the Composer dependencies:
34
+
35
+
```bash
36
+
cd test_with_safe
37
+
composer install
38
+
cd ..
39
+
cd test_without_safe
40
+
composer install
41
+
cd ..
42
+
```
43
+
44
+
A `docker-compose.yml` file is provided to start a PHP 7.2 environment with Blackfire enabled.
45
+
46
+
To start the environment, simply type:
47
+
48
+
```bash
49
+
BLACKFIRE_SERVER_ID=[xyz] BLACKFIRE_SERVER_TOKEN=[abc] docker-compose up
50
+
```
51
+
52
+
You can now browse to `http://localhost:8888/test_with_safe` and `http://localhost:8888/test_without_safe` and profile it using the [Blackfire companion](https://blackfire.io/docs/integrations/firefox)
0 commit comments