What is the effect of eager_load = true?

I need to know why eager_load preferable to false in non-working environments? One of the arguments I've heard about says that eager_load eager loads most of Rails and applications into memory. Therefore, using eager_load for a single test makes it run slower. However, some questions arise, for example, how is a test run performed without loading Rails and the code associated with the application? What is Rails and its associated code that loads? config.eager_load_namespaces provides the following classes:

ActiveSupport ActionDispatch ActiveModel ActionView ActionController ActiveRecord ActionMailer Jquery::Rails::Engine MyApp::Application

Are all these classes and their subclasses loaded?

What are the obvious disadvantages of using eager_load = false in a development or testing environment?

+6
source share
2 answers

However, a number of questions arise, for example, how does the test go without loading Rails and the code associated with the application?

The test loads the necessary code on demand when it tries to use it. So, for example, on some line of code, the test wants to use the Active::Record class. If the eager_load parameter eager_load set to false , this class is not yet required, which will lead to the exclusion of vanilla ruby ​​in the program. However, as part of the rails project, testing will require Active::Record as it is used. Thus, in the end, one test is faster because only the parts of the code that it needs are needed.

This method is the opposite of eager_loading and is called autoload.

What is the loaded Rails code and the application that is loading?

Check out https://github.com/rails/rails . This is a bunch of staff.

Are all these classes and their subclasses loaded?

Yes

What are the obvious disadvantages of using eager_load = false in a development or testing environment?

In a development environment, this runs counter to the benefits and best practice, since you get faster load times (ignored when using a preloader such as spring). This probably also makes it easier to reload changes using the cache_classes=false option, since you have less reload (just a guess).

In a test environment, sometimes you simply cannot use eager_loading=false if you want to evaluate some code metrics, for example, code coverage or style checking. For instance. simple_cov requires you to run all the code before starting the tests.

In general, it may happen that some libarary cannot be used with eager_loading because it does some initialization when loading a class that should already be available, even before calling the methods. However, this is the back case, saying that this happened to us with the stone neo4j.rb

+3
source

The expected load makes the rails load your entire application at startup, which increases startup time.

For example, if you just want to load the rail console to check the behavior of one model, you will have to wait until all the models, controllers, etc. boot even if you want to use only one of them.

0
source

Source: https://habr.com/ru/post/980686/


All Articles