Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid duplicate loading of component files
As discovered in ComplianceAsCode#11190, the `components.load()` function is called many times during a build of product content. However, the component files need to be loaded only once. When the build systems resolves the content using `compile_all.py`, the `compile_all.py` creates an instance of `ssg.builld_yaml.BuildLoader` class. Moreover, many other instances of `ssg.builld_yaml.BuildLoader` class are created recursively as the loader recurses into sub-directories of the given benchmark root directory. When we iterate over the directories, for each child directory the script creates a new instance of the `ssg.build_yaml.BuildLoader` by the `ssg.builld_yaml.BuildLoader._get_new_loader()` method. This method should ensure that the component data and other data won't be unnecessarily loaded again but will be just referenced from the parent `ssg.builld_yaml.BuildLoader` that handles the parent directory. The problem is the way how the `ssg.builld_yaml.BuildLoader._load_components()` method is called in the ctor of `ssg.builld_yaml.BuildLoader`. The ctor is called before the initialization of the `rule_to_components` attribute. Also, there is no code in this ctor or elsewhere assuring that it won't load the components data if they were already loaded. In this commit, we won't call `_load_components` in the ctor, which will leave the opportunity to `_get_new_loader` to swap the data as the comment said. This should bring a speed up about 5 seconds.
- Loading branch information