-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feat(#56) blog about caching #58
Changes from 12 commits
b46d9c1
805d79c
ca11fee
b8789f7
198cb96
96e9f05
4d30d65
3cdae01
ed510bc
5c2fa3e
ad6e8eb
9e6a736
daab2ce
25396af
5c065a5
8f27368
f25314b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,285 @@ | ||
--- | ||
layout: post | ||
date: 2024-02-06 | ||
title: "Build cache in EO and other build systems" | ||
author: Alekseeva Yana | ||
--- | ||
|
||
|
||
## Introduction | ||
In [EO](https://github.com/objectionary/eo), caching is used to speed up program compilation. | ||
Recently we found a caching | ||
[bug](https://github.com/objectionary/eo/issues/2790) in `eo-maven-plugin` | ||
for EO version `0.34.0`. The bug occurred because the old verification method | ||
used compilation time and caching time to search for a cached file. | ||
This is not the most reliable verification method, | ||
because caching time does not have to be equal to compilation time. | ||
We came to the conclusion that we need caching with a reliable verification method. | ||
Furthermore, this verification method should refrain from reading the file content. | ||
|
||
The goal is to implement effective caching in EO. | ||
To achieve the goal, we will briefly look at how frequently used build systems (such as ccache, Maven, Gradle) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 "frequently used", maybe it's better to use "well-known"? wdyt? |
||
in order to gain a deeper understanding of the caching concepts employed within them and to development caching in EO. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 "and to development caching in EO" is redundant. |
||
|
||
<!--more--> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 "More"? |
||
|
||
## Build caching of existing build systems | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 What about "Caching in Build Systems" ? or " Caching in Other Build Systems". There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @volodya-lombrozo I will choose " Caching in Other Build Systems" |
||
|
||
### ccache/sccache | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 Is it a build system or what? Where is the link? Short description? |
||
In compiled programming languages, building a project with many source code files takes a long time. | ||
This time is spent on loading of libraries, preparing, optimizing, checking the code, and so on. | ||
Let's look at the assembly scheme using C++ as an example: | ||
|
||
<p align="center"> | ||
<img src="/images/defaultCPhase.svg"> | ||
</p> | ||
|
||
1) First, preprocessor retrieves the source code files, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 You only say that "preprocessor" only retrieves the source code files. And then... magic...:
Moreover, you don't need "compiler will get" |
||
which consist of both source files `.cpp` and header files `.h`. | ||
The result is a single file `.cpp` with human-readable code that the compiler will get. | ||
2) The compiler receives the file `.cpp` from the preprocessor and converts it into object file - `.obj`. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 "converts it" -> "compiles it" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 "object file" -> "an object file" ? |
||
At the compilation stage, parsing checks whether the code matches rules of a specific programming language. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 Did you mean "parser" instead of "parsing"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @volodya-lombrozo yes, thanks |
||
At the end, the compiler optimizes the resulting machine code and produces an object file. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 You already mentioned it:
|
||
To speed up compilation, different files of the same project might be compiled in parallel. | ||
3) Then, the [Linker](https://en.wikipedia.org/wiki/Linker_(computing)) gets object files. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 Again. Linker gets something... magic... we have an executable file. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 You might use a different verb instead of "gets". It actually does something with this files. Combines? Resolves? |
||
The result of the linker is an executable `.exe` file. | ||
|
||
|
||
To speed up the build of compiled languages, [ccache](https://ccache.dev) | ||
and [sccache](https://github.com/mozilla/sccache) are used. | ||
`ccache` uses the hash algorithm for the hashing of code at certain stages of the build. | ||
`ccache` uses the hash to save a code in the cache. | ||
The [`ccache` hash](https://ccache.dev/manual/4.8.2.html#_common_hashed_information) is | ||
based on: | ||
* the file contents | ||
* the current directory of the file | ||
* the name of the compiler | ||
* the compiler’s size and modification time | ||
* extensions used by the compiler. | ||
|
||
Moreover, `ccache` has two types of the hashing: | ||
1) `Direct mode` - the hash is generated based on the source code only. | ||
This mode allows to build the program faster, since the preprocessor step is skipped. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 Do we really skep "preprocessor step" here? Ot it's just the mode that doesn't require "preprocessor"? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @volodya-lombrozo I have fixed the text so: "
Moreover,
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @volodya-lombrozo I added an explanation of what There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 I like it. Except the last sentence "but the project is built without compile errors.." - It might be removed. |
||
When using this mode, the user must be sure that the external libraries, using in a project, have not changed. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 "When using this mode, the user must ensure that the external libraries used in a project have not changed." |
||
Otherwise, the project will build with errors. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 "Otherwise, the project will fail to build, resulting in errors." |
||
2) `Preprocessor mode` - hash is generated based on the `.cpp` file received after the preprocessor step. | ||
`Preprocessor mode` is slower than `direct mode`, but the project is built without errors. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 This is strange statement. What if we have an error in the code? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @volodya-lombrozo It is ok: " There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 Why do you need to say here about compile errors? Which errors do you mean? If you mention the errors related to libraries, it's better to specify it. Otherwise, it's better just to remove these sentence. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @volodya-lombrozo I will delete these sentence. |
||
|
||
`Sccache`, unlike `ccache`, allows you to store cached files not only locally, but also in a cloud data storage. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 Maybe it worth mentioning, that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @volodya-lombrozo " There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 ok |
||
And `sccache` supports a wider range of languages, while `ccache` focuses on caching C and C++ compiler. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 Maybe we need to write a short summary 1-2 sentences about this type of caching? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @volodya-lombrozo The principle of caching in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 I mean ccache and sccache altogether. What is the difference with other types of caching? Why did you choose these tools? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @volodya-lombrozo I wrote above that I looked at well-known used build systems. Isn't this enough? |
||
|
||
### Gradle | ||
[Gradle](https://gradle.org) builds projects using a | ||
[task graph](https://docs.gradle.org/current/userguide/build_lifecycle.html) that allows for synchronous execution | ||
of certain tasks. | ||
`Gradle` employs | ||
[Incremental build](https://docs.gradle.org/current/userguide/incremental_build.html#sec:how_does_it_work), | ||
to speed up project builds. | ||
For an incremental build to work, the tasks used to build the project must have specified | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 Could you please simplify this sentence and use simple active voice? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @volodya-lombrozo "The tasks that build the project must have input and output files for an incremental build to work." - is it ok? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 The second sentence clearly explains the idea which you are trying to explain here. I would suggest to combine this two sentences into a single one. Or jut to remove this sentence. What do you think? |
||
source and output files. | ||
The provided code snippet demonstrates the implementation of a custom task in Gradle, | ||
showcasing how inputs and outputs are specified to enable `Incremental build`: | ||
``` | ||
task myTask { | ||
inputs.dir 'src/main/java/MyTask.somebody' // Specify the input directory | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @volodya-lombrozo I have fixed this example:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 good |
||
outputs.dir 'build/classes/java/main/MyTask.somebody' // Specify the output directory | ||
|
||
doLast { | ||
// Task actions go here | ||
// This code will only be executed if the inputs or outputs have changed | ||
} | ||
} | ||
``` | ||
`Gradle` uses this information to determine if a task is up-to-date and needs to perform any work. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 Who "needs to perform any work" ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @volodya-lombrozo I think that I will delete this sentence |
||
|
||
To understand how `Incremental build` works, consider the following steps: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 Something strange is happening here with punctuation. Did you put this sentences in this order intentionally? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @volodya-lombrozo If I replace "To understand how There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 Is it possible to remove this sentence? |
||
1) Before executing a task for the first time, `Gradle` takes a | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 "Before executing a task for the first time" -> "Before executing a task" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 takes? Maybe it's better to say "calculates"? wdyt? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @volodya-lombrozo I used "take" because this verb is used the Gradle documentation |
||
[fingerprint](https://en.wikipedia.org/wiki/Fingerprint_(computing)) | ||
of the path and contents of the source files and saves it. | ||
2) Then `Gradle` executes the task and saves a fingerprint of the path and contents of the output files. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "Where does it save the fingerprint?" - I don't know. the Gradle documentation has the sentence: "Gradle persists both fingerprints for the next time the task is executed." Nothing is said about the save location. |
||
3) Before each rebuilding of the task, `Gradle` generates a new fingerprint of the source files | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 "Then, when There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @volodya-lombrozo "Then, when Gradle starts a project build again, it generates a new fingerprint for the same files. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 You don't need this: "can reuse outputs. |
||
and compares it with the current fingerprint. | ||
The fingerprint is considered current if the last modification time | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 This sentence makes no sense to me. If you have an intention to describe "fingerprint". It's better to do above where you left the link to the fingerprint definition. You might say that "fingerprint is based on last modification time and size of the source files" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @volodya-lombrozo I did this:
I believe that the sentence "fingerprint is based on last modification time and size of the source files" is not good idea because fingerprint is based on the path and the contents of a file. |
||
and the size of the source files have not changed. | ||
If none of the inputs or outputs have changed, Gradle can skip that task. | ||
|
||
|
||
In addition to `Incremental build`, `Gradle` also stores fingerprints of previous builds, enabling quick project builds, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 What is the difference with the cache that you described above? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @volodya-lombrozo this cache is for various branches, above - for project of one branch There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 Ok, let's leave it, but I have some doubts about the description. For me, it's not clear from the first glance. |
||
for example when switching from one branch to another. This feature is known as | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 Please, specify which branch do you mean. Is it a "git" branch? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @volodya-lombrozo yes, "git" branch |
||
the [Build Cache](https://docs.gradle.org/current/userguide/build_cache.html). | ||
|
||
|
||
### Maven | ||
[Maven](https://maven.apache.org) automates and manages Java-project builds. | ||
`Maven` is based on the concept of | ||
[Maven LifeCycles](https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html), | ||
which include default, clean, and site lifecycles. | ||
Each lifecycle consists of `phases` and these `phases` consist of sets of `goals`. | ||
|
||
In Maven, there are default phases and goals for building any projects: | ||
|
||
<p align="center"> | ||
<img src="/images/defaultPhaseMaven.svg"> | ||
</p> | ||
|
||
By default, the `phases` in Maven are inherently connected within the build lifecycle. | ||
Each `phase` represents a specific task, and the execution order of `goals` within `phases` is determined | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 I thought that:
|
||
by the default Maven lifecycle bindings. This means that while each `phase` operates as a series of individual tasks, | ||
they are part of a cohesive build lifecycle, and their execution order is predefined by Maven. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 Please, remove it "they are part of a cohesive build lifecycle," |
||
|
||
|
||
`Maven` supports `Incremental build` through plugins the `takari-lifecycle-plugin` and | ||
`maven-build-cache-extension`. | ||
The [takari-lifecycle-plugin](http://takari.io/book/40-lifecycle.html) is an alternative to the default Maven lifecycle | ||
(building JAR files). Its distinctive feature is the use of a single universal plugin with the same functionality | ||
as five separate plugins for the standard lifecycle, but with significantly fewer dependencies. As a result, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 Why do we need to know that there are exactly "five" separate plugins? |
||
it provides a much faster startup, more optimal operation, and lower resource consumption. | ||
This leads to a significant increase in performance when compiling complex projects with a large number of modules. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 Where is a "cache" here? You mentioned that it's a build tool only. |
||
|
||
The [maven-build-cache-extension](https://maven.apache.org/extensions/maven-build-cache-extension/) | ||
is used for large Maven projects that have a significant number of small modules. | ||
This plugin takes a key for a project module, it encapsulates the essential aspects of the module, | ||
including the source code and the configuration of the plugins used within it. | ||
Projects with the same key are considered current (unchanged) and can be efficiently restored from the cache. | ||
Conversely, projects that generate different keys are deemed outdated (changed), | ||
prompting the cache to initiate a complete rebuild for them. In the event of a cache miss, | ||
where an outdated project requires a complete rebuild, | ||
the cache seamlessly delegates the build work to the standard Maven core, | ||
without interfering with the build execution logic. | ||
This ensures that only the changed modules within the project are rebuilt, | ||
minimizing unnecessary overhead and optimizing the build process. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 What is the conclusion? Why did you mention Maven? Does this caching similar to Grade? to ccache? What is the difference? |
||
|
||
### EO build cache | ||
|
||
The EO code uses the `Maven` for building projects. | ||
For this purpose, there is the `eo-maven-plugin` containing the essential goals for working with EO code. | ||
As previously mentioned, the build of projects in Maven follows a specific order of phases. | ||
Below is a diagram illustrating the main phases and their corresponding goals for the EO: | ||
|
||
<p align="center"> | ||
<img src="/images/EO.svg"> | ||
</p> | ||
|
||
In [Picture 3](/images/EO.svg) the goals of the `eo-maven-plugin` are highlighted in green. | ||
|
||
|
||
However, the actual work with EO code takes place in `AssembleMojo`. | ||
`AssembleMojo` is the goal consisting of other goals that work with the EO file, as shown in | ||
[Picture 4](/images/AssembleMojo.svg). | ||
|
||
|
||
<p align="center"> | ||
<img src="/images/AssembleMojo.svg"> | ||
</p> | ||
|
||
Each goal within `AssembleMojo` is a distinct compilation step for EO code. | ||
These tasks happen one after the other, and each task relies on the output of the one before it. | ||
To speed up the EO program rebuild process, it is helpful to save the results of each goal. | ||
This avoids repeating actions and makes the compilation more efficient. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 Why do you constantly say this: "This avoids repeating actions and makes the compilation more efficient. Using caching methods significantly speeds up the build process."? We know why we use caching. It's totally redundant say it over and over again. |
||
Using caching methods significantly speeds up the build process. | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 Why do you need two consecutive empty lines here? If you need some logical division, use headings and clear sections. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 Same question. |
||
|
||
In this chapter, we introduce the keywords: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 It's not a book. We don't usually have "chapters" in a blog post. |
||
* `the source file`: This file serves as the input for goal operations. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 Why do you use "the" ? Is it some particular source file which we know, or which you introduced previously? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @volodya-lombrozo I will remove these text. |
||
* `the cached file`: This file contains the results of goal's execution. | ||
|
||
|
||
The previous caching mechanism in EO made use of distinct interfaces, specifically `Footprint` and `Optimization`, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 It's untrue. They just interfaces. Why do they "derive" from the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 Please, provide links to this files in the repository. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @volodya-lombrozo It's my mistake. There was |
||
both of which derive from the `SafeMojo` class. | ||
These caching interfaces shared similar logic, but with minor differences. | ||
For instance, `Footprint` verifies the EO version of the compiler, whereas the remaining checks are identical. | ||
Additionally, the conditions for searching data in the cache had errors. | ||
The cached file is considered valid if the end time of goal's execution | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 You don't need to explain it again. I've already mentioned this bug above. Could you please remove this sentence? |
||
and the time of saving goal's result to the cache are equal. | ||
Due to this issue, the program behaved incorrectly, because saving the goal's result to the cache is not instantaneous. | ||
After conducting an in-depth analysis of the project's incorrect operation, | ||
several disadvantages of the previous caching mechanism in EO were brought to light: | ||
* Incorrect search conditions for data in the cache. | ||
* The verification method requires reading the file content, which results in inefficiencies. | ||
* The presence of multiple caching mechanisms creates challenges in identifying and rectifying caching errors. | ||
* Employing multiple caching mechanisms for similar entities is a suboptimal practice, | ||
leading to redundancy and complicating the caching infrastructure. | ||
|
||
|
||
To address these disadvantages, the following solutions are proposed: | ||
1) Creating a unified caching mechanism for all goals associated in EO code compilation. | ||
This mechanism, represented by the `Cache` class, will assume responsibility for data validation, | ||
cache storage, and retrieval. | ||
To improve the flexibility for different data verification conditions, | ||
the constructor of the `Cache` class will accept a list of validations. | ||
Here's the corresponding code: | ||
|
||
``` | ||
public class Cache { | ||
|
||
private List<CacheValidation> validations; | ||
|
||
public Cache(final List<CacheValidation> cv) { | ||
this.validations = cv; | ||
} | ||
|
||
public Optional<XML> load(final Path source, final Path cache) {...}; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 Maybe it's better to make |
||
|
||
public void save(final Path cache, final Scalar<String> program, final Path relative) {...}; | ||
} | ||
``` | ||
|
||
The `List<CacheValidation>` represents a list of validations implemented from the `CacheValidation` interface. | ||
This interface defines the structure for validations within the `Cache` class. | ||
The `CacheValidation` interface has the only method ensuring that each validation contains a specific test condition. | ||
|
||
``` | ||
public interface CacheValidation { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 I didn't grasp the idea why we might need this class and why it has exactly this implementation. |
||
boolean validate(final Path source, final Path cache) throws IOException; | ||
} | ||
``` | ||
|
||
2) In order to minimize disk access, we will utilize file paths represented by the `Path` class. | ||
By leveraging methods provided by the `Path` and `Files` classes, | ||
we can obtain essential information such as the file name and the time of the last modification. | ||
The file name plays a crucial role in locating the cached file within the directory, | ||
while the time of the last modification enables us to determine whether | ||
the source file is older or equal in age to the cached file. | ||
Given that the project build process in Maven is linear, | ||
these conditions are deemed sufficient for our caching mechanism. | ||
|
||
|
||
3) Searching for a cached data will use the following conditions: | ||
* `The source file` and `the cached file` should have same file name; | ||
* Each goal involved caching should have both a cache directory and a directory of result files. | ||
The directory of result files corresponds to the directory of source files for the subsequent goal. | ||
* The time of the last modification of the source file should be earlier or equal than cached file. | ||
|
||
|
||
Example: Let's consider an EO program named `program.eo`, which is executed for the first time. | ||
The cache of each goal will save the execution results in the cache directory and the result directory. | ||
When this program is run again without changes, these goal will receive data from the cache, | ||
without executing of task and rewriting of result. | ||
However, if we make changes to the `program.eo` file or `the source files` of the goals and execute again, | ||
the execution result of goals was overwritten in the directory of result files and the cache directory. | ||
This approach effectively protects the program from artificial changes during the build process. | ||
|
||
|
||
### Conclusion | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 I don't think we need such a conclusion in a blog post. It isn't a scientific article. Moreover it doesn't provide any useful information. Kinda "water". |
||
In this article, we explored various build systems and their caching methods. | ||
We were motivated to find an efficient caching approach for EO due to issues discovered during bug investigation. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Yanich96 To be honest, I don't understand why you "explored various build systems". This analysis is completely disconnected from the solution you propose. You observe high-level concepts in other build systems but didn't do any conclusions from them. You merely mention their existence. Why? Why should we read about them? Where is the connection with the second part of the text? Later, you just mentioned that we have some goals and some Mojos in Maven. Why? Why do we need to read about them? What is the purpose of this? Please, pause for a moment and consider these questions: What is the purpose of this blog post? Why are you writing it, and why should people read it? |
||
The previous caching mechanism was flawed logically and architecturally, making it ineffective. | ||
As a result, we discussed the problems, suggest solutions, and outline the criteria | ||
for implementing a new caching system in EO. | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Yanich96 It's better to say: "The bug occurred because the old verification method used compilation time and caching time to search for a cached file"