4

We can disable Compilation in Magento 1 in the admin. But there is no settings in Magento 2 in the admin. Also compile is something different compare with m1. Its depending on the mode (default,developer,production) we are running app. Anyone have in-depth knowledge on compile?

devdocs contains limited info.

8

First you need to know that even though we call both features compilers they are very different:

Magento 1 compiler :

It makes a copy of every class in a Magento system and places them in a single folder. The class’s full name is used for the filename to ensure uniqueness. Then, when Magento is configured to use the compiler classes, its autoload will look in the compiler folder instead of running its normal autoload routine. This spares PHP the overhead of transversing the file system for all the different include paths.

You can find further details about the M1 compiler here: http://alanstorm.com/magento_compiler_path/

Also I suggest you read this StackExchange Q&A regarding why you should never use the M1 compiler: When should I use the Magento Compiler

Magento 2 compiler:

On the other here's what the M2 compiler does:

Code compilation consists of all of the following in no particular order:

  • Application code generation (factories, proxies, and so on)
  • Area configuration aggregation (that is, optimized dependency injection configurations per area)
  • Interceptor generation (that is, optimized code generation of interceptors)
  • Interception cache generation
  • Repositories code generation (that is, generated code for APIs)
  • Service data attributes generation (that is, generated extension classes for data objects)

You can find further details about the M2 compiler on the official documentation page: http://devdocs.magento.com/guides/v2.0/config-guide/cli/config-cli-subcommands-compiler.html

Final answer

Out of the box, you cannot (and you shouldn't) disable the Magento 2 compilation because it is required for Magento 2 to work properly.

However, in production mode, the compiler is automatically disabled because you should manually run the DI compile before shipping to production. In developer mode, the compilation automatically starts when new/updated files are added.

| improve this answer | |
  • 1
    To clarify: you don't have to run compilation in develper mode (only for testing purposes). Also, compilation does not happen in dev mode, only code is generated on demand when you launch magento. – Anton Kril Apr 12 '17 at 20:49
5

Compilation in Magento 2 is mandatory, in production mode at least. It is something completely different to the compilation in Magento 1:

The Magento 1 compiler was built to reduce I/O operations by merging the source files. With current technology this does not make sense anymore, see: When should I use the Magento Compiler

The Magento 2 compiler creates definitions, which classes should be used where and is used to generate code. Magento 2 heavily uses code generation for:

  • plugins
  • factory classes
  • proxy classes
  • extension interfaces

More info: http://devdocs.magento.com/guides/v2.0/extension-dev-guide/code-generation.html

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.