Avoid duplicate loading of component files #11195
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
As discovered in #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
, thecompile_all.py
creates an instance ofssg.builld_yaml.BuildLoader
class. Moreover, many other instances ofssg.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 thessg.build_yaml.BuildLoader
by thessg.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 parentssg.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 ofssg.builld_yaml.BuildLoader
. The ctor is called before the initialization of therule_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 in this method says.This should bring a speed up about 5 seconds.