RFC: Persistent Cache MakeOccasion #8636
jerrykingxyz
started this conversation in
RFC
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Feature Name: Design the MakeOccasion at persistent cache
Start Date: 2024/12/05
Summary
Design MakeOccasion to support the use of persistent cache during the make stage.
Glossary
MakeArtifact
: The output of the Make stage, including all the data of the Make stage, also needs to be passed as a parameter in the Make incremental build.User Guide
The API of MakeOccasion on the user side is very simple, providing only
save
: SaveMakeArtifact
to persistent cache storage.recovery
: RestoreMakeArtifact
from persistent cache storage.Additional
before_make
andafter_make
are required for CacheTrait to access MakeOccasion.Detailed design
Impl MakeOccasion
MakeOccassion needs to implement persistent cache features for MakeArtifact, so it needs to pay attention to the purpose and function of each field inside MakeArtifact. In MakeArtifact, fields can be divided into
When implementing persistent cache, we need to split the large amount of data in the core data of MakeArtifact into three parts:
Dependencies
&ModuleGraph
&Meta
.Dependencies
The processing of
Dependencies
mainly includes* _dependencies
in MakeArtifact, that is, the incremental processing ofFileCounter
, which requires us to collect the dependencies information that has been changed in this build, which can be collected by adding additional fields inIncrementalInfo
.When saving MakeArtifact, we can use
FileCouter.incremental_info
to get the deps affected in this build, and then updateStorage
by whether they currently exist inFileCounter
.ModuleGraph
ModuleGraph is a very large graph structure, and its storage requires tiling data at the module granularity.
The tiled node contains the information about the current module, such as
module
,mgm
,block
, and downstreamdependencies
andconnection
data of the current module (PS. Remove all upstream data). Its data structure is as follows:The ModuleGraph can incremental updates by
built_module
andrevoked_module
in MakeArtifact.When restore module_graph, in addition to setting the information in the node back, we also need to traverse all dependencies to regenerate the incoming information. If some modules fail to restore, record it in the make_failed_dependencies.
Meta
Meta is for core data other than ModuleGraph and * _dependencies, which has a small amount of data and can be saved in full for each build.
API
MakeOccasion provides
save
andrecovery
, which are relatively simple to implement and only need to integrate the above functions.CacheTrait
CacheTrait needs to add two additional functions
before_make
andafter_make
, which need to be called at the begin and end of the make stage.For PersistentCache, it is necessary to
before_make
according to theMakeArtifact.initialized
to determine whether to use the cache, and save the MakeArtifact whenafter_make
.For DisableCache, MakeArtifact needs to be erased when
before_make
.For MemoryCache, no operation is required.
Exception handling
Since some node in ModuleGraph currently does not support serialization due to some data structures. the ModuleGraph has a certain tolerance for those errors.
save
ModuleGraph will skip nodes that fail serialization.recovery
ModuleGraph will record missing modules to themake_failed_dependencies
, and make stage will regenerate them.After serialization is supported for all data structures used by Occasion in the future, the fault-tolerant logic at ModuleGraph can be considered for removal.
Unresolved Questions & TODOs
DependenyId
is achieved through digital auto-increment. In the case of persistent caching, it may exceed the upper limit and requires subsequent modifications similar to ModuleId.Beta Was this translation helpful? Give feedback.
All reactions