Slim 4 - Why so heavy

I just loaded slim 4 on a dev site according to the installation instructions on the home page.

$ php composer.phar create-project slim/slim-skeleton [my-app-name]

Surprisingly, it proceeded to load 18 M of dependency code, without me writing a single line of code.

Package operations: 47 installs, 0 updates, 0 removals
  - Installing ralouphie/getallheaders (3.0.3): Loading from cache
  - Installing psr/http-message (1.0.1): Loading from cache
  - Installing psr/http-factory (1.0.1): Loading from cache
  - Installing fig/http-message-util (1.1.3): Loading from cache
  - Installing slim/psr7 (0.5.0): Loading from cache
  - Installing psr/log (1.1.0): Downloading (100%)         
  - Installing monolog/monolog (1.25.1): Downloading (100%)         
  - Installing nikic/php-parser (v4.2.4): Downloading (100%)         
  - Installing symfony/polyfill-util (v1.12.0): Downloading (100%)         
  - Installing symfony/polyfill-php56 (v1.12.0): Downloading (100%)         
  - Installing jeremeamia/superclosure (2.4.0): Downloading (100%)         
  - Installing php-di/phpdoc-reader (2.1.1): Downloading (100%)         
  - Installing psr/container (1.0.0): Loading from cache
  - Installing php-di/invoker (2.0.0): Downloading (100%)         
  - Installing php-di/php-di (6.0.10): Downloading (100%)         
  - Installing psr/http-server-handler (1.0.1): Loading from cache
  - Installing psr/http-server-middleware (1.0.1): Loading from cache
  - Installing nikic/fast-route (v1.3.0): Loading from cache
  - Installing slim/slim (4.3.0): Downloading (100%)         
  - Installing sebastian/version (2.0.1): Downloading (100%)         
  - Installing sebastian/resource-operations (2.0.1): Loading from cache
  - Installing sebastian/recursion-context (3.0.0): Downloading (100%)         
  - Installing sebastian/object-reflector (1.1.1): Downloading (100%)         
  - Installing sebastian/object-enumerator (3.0.3): Downloading (100%)         
  - Installing sebastian/global-state (2.0.0): Downloading (100%)         
  - Installing sebastian/exporter (3.1.2): Downloading (100%)         
  - Installing sebastian/environment (4.2.2): Loading from cache
  - Installing sebastian/diff (3.0.2): Loading from cache
  - Installing sebastian/comparator (3.0.2): Downloading (100%)         
  - Installing phpunit/php-timer (2.1.2): Loading from cache
  - Installing phpunit/php-text-template (1.2.1): Downloading (100%)         
  - Installing phpunit/php-file-iterator (2.0.2): Loading from cache
  - Installing theseer/tokenizer (1.1.3): Loading from cache
  - Installing sebastian/code-unit-reverse-lookup (1.0.1): Downloading (100%)         
  - Installing phpunit/php-token-stream (3.1.1): Downloading (100%)         
  - Installing phpunit/php-code-coverage (6.1.4): Loading from cache
  - Installing doctrine/instantiator (1.2.0): Downloading (100%)         
  - Installing symfony/polyfill-ctype (v1.12.0): Loading from cache
  - Installing webmozart/assert (1.5.0): Loading from cache
  - Installing phpdocumentor/reflection-common (2.0.0): Downloading (100%)         
  - Installing phpdocumentor/type-resolver (1.0.1): Downloading (100%)         
  - Installing phpdocumentor/reflection-docblock (4.3.2): Downloading (100%)         
  - Installing phpspec/prophecy (1.9.0): Downloading (100%)         
  - Installing phar-io/version (2.0.1): Loading from cache
  - Installing phar-io/manifest (1.0.3): Loading from cache
  - Installing myclabs/deep-copy (1.9.3): Loading from cache
  - Installing phpunit/phpunit (7.5.16): Downloading (100%)

Here is my end result.

Why so heavy?

It’s not clear what you are comparing this application to.

If you want to see how much space each dependency is occupying you can enter vendor/ and run ‘ls | xargs du -sh’, then you can remove some of them from composer.json if you consider them unnecessary for your project.

In practice, this is luckily not relevant, because an optimized version will be deployed on the production system without all these dependencies.

Run composer install --no-dev --optimize-autoloader and the size will be reduced from 7.3 MB to 2.8 MB.

2 Likes

Well, I never really compared, but 18 M for a micro framework seems to me to be a tad too much. Perhaps somewhere the concept of “slim” gets blurred.

Great tip @odan. Thank you.

The file size of the application doesn’t matter much, what matters is the application performance. A dependency package might have a large file size, but Slim might only use a tiny portion of its code. Likewise a package might be large simply because it has extensive documentation with images, or it could be large because it has language translations for dozens of languages.

3 Likes