Compilation cache implementation method, device and equipment
By performing hash addressing and native compilation based on source code compilation elements in CI/CD scenarios, the problem of low cache hit rate is solved, compilation efficiency and cache reliability are improved, and it is suitable for compilation cache implementation in CI/CD scenarios.
Patent Information
- Application Number
- CN202410780828.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-14
- Publication Date
- 2024-10-01
AI Technical Summary
In a continuous integration/continuous delivery (CI/CD) scenario, due to changes in source file metadata information or project CI directories, the compilation cache hit rate is very low or even unavailable, affecting development efficiency.
By obtaining the compilation elements of the source code, hash addressing is performed in the cache based on these elements. If there is a hit, the cache product is extracted. If there is a miss, the native compilation command is executed and the cache is updated. It is independent of the build system and cache mechanism of the integrated development environment. .
It improves the cache hit rate and cache reliability, shortens the average compilation time of a thousand lines of code, from more than 1000ms to less than 100ms, adapts to CI/CD construction scenarios, and reduces dependence on the integrated development environment.
Smart Images

Figure CN118733049A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of computer technology, and in particular to a method, device and apparatus for implementing a compilation cache. Background Art
[0002] With the development of computer and Internet technologies, more and more software products (hereinafter referred to as products) have entered people's lives.
[0003] For a product, its development process may go through multiple processes such as design, coding, compilation, testing, and deployment. Among them, the speed of product compilation and construction directly affects the iteration cycle and productivity of developers, and is a core indicator of R&D efficiency.
[0004] In the traditional compilation process, developers rely on the caching capabilities of the development language and framework itself to achieve incremental compilation in local development scenarios to ensure the efficiency of daily development.
[0005] In the continuous integration / continuous delivery (also known as CI / CD) scenario, for the saved historical build cache, due to changes in source file metadata information (also known as metadata information) or the project CI directory, the cache life rate is very low or even unavailable. It is difficult to perceive the historical build cache when the product project is cold started, and a full build is often required at this time.
[0006] Based on this, a compilation cache implementation solution that can improve the cache hit rate is needed. Summary of the invention
[0007] One or more embodiments of the present specification provide a compile cache implementation method, apparatus, device, and storage medium to solve the following technical problem: a compile cache implementation solution that can improve cache hit rate is needed.
[0008] To solve the above technical problems, one or more embodiments of this specification are implemented as follows:
[0009] One or more embodiments of this specification provide a compile cache implementation method, including:
[0010] Obtaining source code and determining compilation elements of the source code;
[0011] Addressing in a cache based on the compilation element to determine whether the source code hits the cache;
[0012] If there is a hit, the corresponding cache product is extracted;
[0013] If there is no hit, a native compilation command is executed on the source code to obtain a compilation product, and the cache is updated according to the compilation product.
[0014] One or more embodiments of this specification provide a compile cache implementation device, including:
[0015] An element determination module obtains source code and determines compilation elements of the source code;
[0016] A cache addressing module, which addresses the cache based on the compilation element to determine whether the source code hits the cache;
[0017] an extraction module, which extracts a corresponding cache product if the determination result of the cache addressing module is a hit;
[0018] The compile update module executes a native compile command for the source code to obtain a compile product if the determination result of the cache addressing module is a miss, and updates the cache according to the compile product.
[0019] One or more embodiments of this specification provide a compile cache implementation device, including:
[0020] at least one processor; and,
[0021] a memory communicatively connected to the at least one processor; wherein,
[0022] The memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to:
[0023] Obtaining source code and determining compilation elements of the source code;
[0024] Addressing in a cache based on the compilation element to determine whether the source code hits the cache;
[0025] If there is a hit, the corresponding cache product is extracted;
[0026] If there is no hit, a native compilation command is executed on the source code to obtain a compilation product, and the cache is updated according to the compilation product.
[0027] One or more embodiments of this specification provide a non-volatile computer storage medium storing computer executable instructions, wherein the computer executable instructions are configured to:
[0028] Obtaining source code and determining compilation elements of the source code;
[0029] Addressing in a cache based on the compilation element to determine whether the source code hits the cache;
[0030] If there is a hit, the corresponding cache product is extracted;
[0031] If there is no hit, a native compilation command is executed on the source code to obtain a compilation product, and the cache is updated according to the compilation product.
[0032] At least one of the above technical solutions adopted in one or more embodiments of this specification can achieve the following beneficial effects:
[0033] The cache product obtained through the native compilation command and cache update do not rely on the capabilities of the integrated development environment itself (including the build system and cache mechanism integrated in each IDE). Instead, the compilation cache is calculated based on the actual compilation instructions and the current compilation environment context information, which improves the cache hit rate while ensuring cache reliability. BRIEF DESCRIPTION OF THE DRAWINGS
[0034] In order to more clearly illustrate the embodiments of this specification or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this specification. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying creative labor.
[0035] Figure 1 A flowchart of a compile cache implementation method provided in one or more embodiments of this specification;
[0036] Figure 2 A schematic diagram of a compilation cache implementation process in an application scenario provided for one or more embodiments of this specification;
[0037] Figure 3 A hash addressing flow chart in an application scenario provided for one or more embodiments of this specification;
[0038] Figure 4 A schematic diagram of a distributed caching process in an application scenario provided for one or more embodiments of this specification;
[0039] Figure 5 A schematic diagram of a cache framework in an application scenario provided for one or more embodiments of this specification;
[0040] Figure 6 A schematic diagram of the structure of a compile cache implementation device provided in one or more embodiments of this specification;
[0041] Figure 7 A schematic diagram of the structure of a compile cache implementation device provided in one or more embodiments of this specification. DETAILED DESCRIPTION
[0042] The embodiments of this specification provide a compile cache implementation method, apparatus, device, and storage medium.
[0043] In order to enable those skilled in the art to better understand the technical solutions in this specification, the technical solutions in the embodiments of this specification will be clearly and completely described below in conjunction with the drawings in the embodiments of this specification. Obviously, the described embodiments are only part of the embodiments of this application, not all of them. Based on the embodiments of this specification, all other embodiments obtained by ordinary technicians in this field without creative work should fall within the scope of protection of this application.
[0044] Figure 1 A flowchart of a compilation cache implementation method provided by one or more embodiments of this specification. The method can be applied to different business fields, such as software development, Internet financial business, e-commerce business, instant messaging business, game business, official business, etc. The process can be executed by a computing device in the corresponding field (such as a server or smart mobile terminal corresponding to software development), and some input parameters or intermediate results in the process allow manual intervention and adjustment to help improve accuracy.
[0045] Figure 1 The process in may include the following steps:
[0046] S102: Acquire source code and determine compilation elements of the source code.
[0047] In the CI / CD scenario, after R&D personnel finish writing the source code, they need to submit it to the version control system to facilitate integration and testing of the source code. At this time, the source code is obtained.
[0048] Of course, in non-CI / CD scenarios, the source code can also be obtained by interacting with source code writing software, source code testing software, or a corresponding source code management system.
[0049] In the execution of code compilation tasks, the compilation environment needs to be configured, and the compilation action is performed on the source code after the parameters executed in the compilation process are set. The compilation elements refer to the various types of data and information that are relied on in order to complete the compilation task of the source code (for the convenience of description, this part of the content is called compilation dependency factors). The compilation elements can be used to represent the compilation environment, the source code itself, the compilation parameters that need to be set during the compilation process, etc. As long as the data or information is used in the compilation task and can be obtained, it can be considered as part or all of the components of the compilation elements.
[0050] Of course, the compilation elements may also include compilation entity factors such as the upload time of the source code, the department to which it belongs, the R&D personnel, the project to which it belongs, etc., which may all be used as part of the information in the compilation elements.
[0051] S104: performing addressing in a cache based on the compilation element to determine whether the source code hits the cache.
[0052] Figure 2 A schematic diagram of a compilation cache implementation process in an application scenario provided for one or more embodiments of this specification, in a CI / CD scenario, in a cache-optimized scenario of a traditional solution, after obtaining the source code, it is necessary to go through preprocessing, assembly, compilation (obtaining a file in .o format) and other processes in sequence, and finally generate a link to determine the compilation product (obtaining a file in .a, .so, exe, etc. format). In the embodiments of this specification, whenever a source code is compiled, its compilation product (also referred to as the compilation result) can be stored in the cache, so that the source code can be incrementally compiled next time. At this point, the preprocessing, assembly, and compilation processes are no longer directly executed, but first addressing is performed in the cache to determine whether the cache hits.
[0053] When storing the compiled product, a corresponding data identifier can be generated based on the compiled elements of the source code, and a corresponding mapping table can be set to record the mapping relationship between the data identifier and the storage address of the compiled product in the mapping table, so as to facilitate addressing in the cache through the compiled elements.
[0054] The data identifier of the compilation element can include a string, a barcode, a QR code, etc. In actual settings, the corresponding data identifier can be set based on the compilation entity factors in the compilation element and the preset data identifier generation algorithm. For example, the data identifier generation algorithm can be: department identifier-R&D personnel identifier-source code project identifier-upload time. Of course, the process can also be combined with compilation dependency factors, for example, adding the compilation environment, source code corresponding summary information, etc. to the data identifier generation algorithm.
[0055] The data identifier may also be generated by selecting data of several dimensions that best reflect the current compilation task from the compilation elements, and obtaining the data identifier after processing using a corresponding algorithm (e.g., a hash algorithm, an encryption algorithm, a data fusion algorithm, etc.). The process of obtaining the data storage identifier may be reversible or irreversible.
[0056] Of course, in non-CI / CD scenarios, the cache method and location may change, and a similar method can be used to set up a mapping table and generate data identifiers for addressing.
[0057] Specifically, Figure 3A hash addressing flowchart for an application scenario is provided for one or more embodiments of the present specification. Taking the generation of data identifiers through a hash algorithm as an example, after receiving a compilation command for a source code, a cache hit judgment logic is inserted through a hook mechanism to determine that the compilation elements include multiple component dimensions on which the code compilation implementation process depends. Each component dimension is data, information, operations, etc. that the code compilation implementation process depends on. Code compilation can only be achieved based on the cooperation between multiple component dimensions.
[0058] The composition dimensions may be as shown above, including the compilation environment, the source code itself, the compilation parameters required to be set during the compilation process, etc. Furthermore, the compilation environment may be represented by compiler information, and some compilation parameters that affect the final compilation result may be selected from the compilation parameters, and some information may be selected from the source file information to represent the source code itself.
[0059] At this time, for the component dimension, a hash result corresponding to the component dimension is obtained based on a hash algorithm (for the convenience of description, it is referred to as the first hash result). The hash algorithm may include MD5 (Message Digest Algorithm 5), MurmurHash, CityHash, FNV Hash and other algorithms. After performing hash calculation on each component dimension based on the hash algorithm, the first hash result corresponding to each component dimension is obtained.
[0060] At this time, hash addressing is performed based on the first hash result to determine whether the source code hits the cache. In the process of hash addressing, a hash table is pre-built, and each key value and its corresponding data storage address are stored in the hash table. In the embodiment of the present application, after obtaining the corresponding compilation element, a hash calculation is performed to obtain the first hash result, and then the data storage address corresponding to the first hash result is determined according to the hash table, thereby completing the addressing process.
[0061] Among them, since there are multiple first hash results corresponding to multiple component dimensions, the multiple first hash results can be processed accordingly and then used for hash addressing. For example, the multiple first hash results are combined in a preset order to obtain a larger hash result, and then the hash result is used for addressing. Alternatively, some hash results are selected from the multiple first hash results for combination to obtain a larger hash result.
[0062] The final first hash result generated in this way is not only related to each compilation element in the compilation task, but also more representative than the first hash result of a single dimension, thereby improving the performance of the hash table and reducing the possibility of conflict.
[0063] Further, hash addressing is performed according to the first hash result, and path information corresponding to a file address can be located. At this time, it is determined whether there is a dependency information file in the path information. The dependency information file records the relevant information of the header file required for the compilation task, and this information can ensure that the required header file is correctly included and used in the compilation task, so that the compiler can correctly parse the code and generate an executable file.
[0064] If there is no dependency information file in the path information, it means that the source code did not hit the cache during the addressing process, and the corresponding compilation command can continue to be executed. If there is a dependency information file, the header file information contained in the dependency information file is read, and a second hash result corresponding to the header file information is obtained based on the hash algorithm.
[0065] In a similar manner as above, the first hash result and the second hash result are combined to obtain a larger hash result, and hash addressing is performed according to the larger hash result. Combining the hash results of multiple component dimensions and header files, the path information of the final required cache product can be located. If the corresponding file exists in the path information, then the file is the cache product corresponding to the source code this time. If not, it means that the cache is not hit this time.
[0066] In addition, when calculating the first hash result corresponding to each component dimension, a corresponding method for generating the first hash result may be set based on the difference in the component dimensions.
[0067] Specifically, the composition dimensions include: compiler information, compilation parameters, and source file content. For compiler information, it may include compiler version information, supported programming languages, supported standards and specifications, compiler features, target code formats and target file formats generated by the code generator, etc. In the hashing process, you can select all or part of the content, calculate the hash values separately, and then combine and splice these hash values to obtain the first hash result corresponding to the compiler information; or, select all or part of the content, combine and splice these contents, and then hash them, and use the obtained hash value as the first hash result.
[0068] For the source file content, the header file information contained therein (for example, all or part of the content in the header file information such as function declaration, variable declaration, macro definition, etc.) can be used to perform a hash value as the first hash result of the source file content. Of course, other content corresponding to the source file content (for example, document information, test code, code logic, etc.) can also be hashed to obtain the first hash result corresponding to the source file content. The hashing process is similar to that of the compiler information, and will not be repeated here.
[0069] As for compilation parameters, since they are relatively more complex and contain more content, they need to be paid more attention to than the other two component dimensions.
[0070] Specifically, in actual work, each compilation parameter can be customized in advance based on demand, and the customization includes: whether the compilation parameter needs to be adopted for hashing, how to hash, etc.
[0071] As for compilation parameters, there are some compilation parameters that do not affect the compilation results. It is difficult to use these compilation parameters as a basis to describe the current compilation task, so these compilation parameters are filtered out and not used as the basis for hashing. For example, when the compiler executes the compilation action, it may carry some parameters corresponding to the timestamp, which will not affect the compilation results, so they can be filtered out.
[0072] There is also a part of compilation parameters, which is used as path information to indicate access to a specified file. At this time, this part of the compilation parameters can affect the final compilation result, but the way it affects the specified file it points to is to affect it, rather than through the value of the parameter itself. Therefore, for this part of the compilation parameters, it is no longer used to calculate the hash value, but the hash result corresponding to the file content it accesses is used as a replacement, thereby serving as part of the content in the first hash result corresponding to the compilation parameter. The selection of the file content can be the header file information or the pre-defined corresponding information therein, and the hash algorithm can be implemented through precompiled header files (Precompiled Headers, PCH) processing, and the frequently used header files are precompiled into binary form. When actually compiling the source code, these precompiled header files are directly used as the first hash result or when hashing the header file.
[0073] Of course, for the path information used to represent some compilation parameters for accessing the specified file, it may be represented in various forms such as relative path, absolute path, etc. At this time, the absolute path information can be relativized and converted into a relative path to avoid substituting project-irrelevant information into the hash calculation.
[0074] S106: If there is a hit, the corresponding cache product is extracted.
[0075] S108: If there is no hit, executing the native compilation command for the source code to obtain a compilation product, and updating the cache according to the compilation product.
[0076] If a corresponding file exists in the path information determined by hash addressing, then the file is the cache product required this time. At this time, extract the cache product and copy it to the compilation path. R&D personnel can perform incremental compilation based on the cache product to improve R&D efficiency.
[0077] If there is no hit, it means that the source code of this compilation has not been compiled before, and you need to execute the native compilation command for it, and then update the cache according to the compiled product obtained, and use it as the cache product, so that you can get the cache product for the source code next time to achieve incremental compilation.
[0078] The native compilation command refers to the process of using the compiler to directly compile the source code without relying on the build tool. The cached product can be saved in the system directory instead of the compiler directory.
[0079] The cache product obtained through native compilation commands is updated without relying on the capabilities of the Integrated Development Environment (IDE) itself (including the build system and cache mechanism integrated in each IDE). Instead, the compilation cache is calculated based on the actual compilation instructions and the current compilation environment context information, which improves the cache hit rate while ensuring cache reliability.
[0080] The cached products are saved in the system directory, which is globally accessible under the current system and can be shared between different projects. By adding various compilation elements to the hash algorithm, the interference of source file information and CI directory can be eliminated during cache calculation, adapting to CI / CD build scenarios. By controlling the technical selection of hash algorithms and compression algorithms, the efficiency of cache hash calculation and cache access is guaranteed. After experimental verification, the average compilation time of one thousand lines of code can be reduced by an order of magnitude, from more than 1000ms in traditional solutions to less than 100ms.
[0081] based on Figure 1 This specification also provides some specific implementation plans and extension plans of the method, which will be described below.
[0082] In traditional solutions, a single-machine cache solution is usually used, which makes the traditional cache solution highly heterogeneous, lacks customized configuration and integration capabilities, and is difficult to keep up with the needs of enterprise business development. For example, in CI / CD scenarios, a single-machine cache solution will make the cache extremely unevenly distributed among different packagers, resulting in a lower cache hit rate for the overall solution, affecting the R&D efficiency of the enterprise.
[0083] Based on this, Figure 4A schematic diagram of a distributed caching process in an application scenario is provided for one or more embodiments of the present specification, wherein a first packager represents a local program for packaging, and a second packager and a third packager represent non-local programs for packaging. In the actual processing process, the number of non-local packagers may change, and two are taken here as an example.
[0084] After confirming to start packaging, prepare the environment. After starting compilation, determine whether this compilation task hits the cache. If it does not hit the cache, when the source code needs to be compiled, the compilation task can be marked to indicate that this compilation task does not hit the cache.
[0085] When the compilation is finished, the local cache is updated according to the compilation products after packaging. In the local cache, the missed compilation products are extracted according to the recorded tags, the compilation products are packaged, and cache synchronization is started through broadcasting. The target of the broadcast is other machines in the same distributed cache cluster. The machines included in the distributed cache cluster can be pre-set, and the corresponding broadcast addresses are assigned to different machines to facilitate broadcasting between each other.
[0086] When the first packager broadcasts to the second packager and the third packager, the second packager and the third packager receive the broadcast through their own cache framework, determine the file sent synchronously in the broadcast (also called the packaging result), decompress the file, and obtain the corresponding cache product, through which the local cache of the packager is updated.
[0087] When updating, batch cache merging can be used to merge multiple cache requests or operations into one batch request or operation, thereby improving system performance and efficiency, reducing frequent access to the cache system, and reducing system load and latency.
[0088] Furthermore, if the cache product is not hit, after the compilation product is generated by the native compilation command, the cache needs to be updated based on the compilation product. Of course, if the cache product is hit, incremental compilation is performed based on the cache product, and after the corresponding incremental compilation product is obtained, the cache can also be updated based on the incremental compilation product.
[0089] When the cache mode is distributed cache, first update the local cache according to the incremental compilation product. At this time, obtain the compilation entity factors corresponding to the cache product (for example, it may include the department to which it belongs, the R&D personnel, the project to which it belongs, etc.), and determine the packaging machine corresponding to the compilation entity factors in the distributed cache (hereinafter referred to as the corresponding packaging machine). Generally speaking, based on actual needs, each department, or each R&D personnel, or each project will have an independent machine for code compilation, and an independent packaging machine is also set up in the machine. The corresponding correspondence can be set in each machine to correspond to the relationship between each packaging machine and the compilation entity factors, and the compilation entity factors can be obtained based on the records in the cache product.
[0090] At this time, for the corresponding packager, since it is obtained by incremental compilation based on the cache product of the corresponding entity, when broadcasting to the corresponding packager, the corresponding tag is added to the incremental compilation product, so that after the corresponding packager obtains the incremental compilation product, it no longer merges the cache in batches, but updates its local cache immediately, so that it can know the subsequent status of its own cache product as soon as possible.
[0091] Figure 5 A schematic diagram of a cache framework for an application scenario is provided for one or more embodiments of this specification. The compiled cache implementation method in the embodiments of this specification is implemented based on a pre-built cache framework. Based on the cache framework, multiple functional capabilities can be implemented, multiple cache objects can be supported, and multiple cache capabilities can be implemented.
[0092] Specifically, the cache framework includes: an integration module, a cache module, and a general module.
[0093] The integration module integrates a variety of compilation tools, such as the integrated development environment IDE, the client development platform (CI platform for short) responsible for the continuous integration and delivery of internal client products, and the command line tool (CLI) that provides a series of debugging and optimization capabilities to improve the efficiency of daily development. The integrated compilation tools can make the compilation process smoother and improve the efficiency of research and development.
[0094] The cache module is used to support cache strategies. For example, when the cache mode is distributed cache, its cache strategy may include synchronization strategies between different packagers, and cache merging mode may be batch cache merging strategy.
[0095] The general module is used to support general configuration information and statistical information. For example, it may include configuration capabilities and statistical capabilities for each module.
[0096] Furthermore, through each module in the cache framework, corresponding cache core capabilities can also be realized, including command extraction, cache calculation, product management, etc.
[0097] Command extraction can be used to extract corresponding native compilation commands, compiler startup commands, and other commands related to code or compilation, including Hook commands, Launcher commands, command decomposition, etc.
[0098] Cache calculation can include: tool chain management, parameter analysis, environment analysis, dependency analysis, hash calculation (Hash calculation), and product addressing. Among them, the tool chain management includes various tools including compilation tools to facilitate the research and development work of R&D personnel. Parameter analysis is used to determine whether the parameters in each component dimension (for example, compilation parameters) are used for addressing, and to perform other related analysis on each parameter. Environment analysis can analyze whether the current compilation environment is abnormal and whether it is suitable for the execution of this compilation task. Dependency analysis can be used to analyze dependency information files to extract header file information. Hash calculation is used to perform hash calculations on each component dimension and related parameters. Product addressing determines whether the cache is hit based on the hash result.
[0099] Product management can manage the storage location and storage duration of cache products and compiled products, including cache updates, cache restoration, product compression, etc. Among them, cache update refers to updating the cache product through the obtained product after the native compilation command or incremental compilation is completed. Cache restoration can include restoring cache products that have been cached for more than a preset time, and product compression can include compressing and packaging the products, compressing image resources, etc.
[0100] The cache framework is equipped with corresponding compilation tools, which enables the compilation of source code in different compilation scenarios. For example, it is equipped with corresponding compilation tools for compilation scenarios such as iOS, Android, and Internet of Things (IoT).
[0101] Also based on the onboard caching tool, it can support caching functions for multiple objects including C / C++, Objective-C, Swift, Java, and image resources. When facing different caching objects, it uses the corresponding caching tools to cache files in the corresponding format.
[0102] In one or more embodiments of the present specification, based on the differences in the compilation projects corresponding to the cache framework, different means may be used to obtain the compilation elements of the source code.
[0103] Specifically, for example, when a Hook command is received to indicate that a compilation task needs to be executed, for the first type of compilation project in which the cache framework does not modify the compiler environment variables (for example, for some cache architectures, the compiler environment variables are often not modified for CMake-type cache projects), the compiler can be added directly based on the compiler startup command, and then the cache framework can directly build the compiler startup command (for example, through the function DCMAKE_C_COMPILER_LAUNCHER to represent the compiler startup command). At this time, the cache framework can easily obtain compilation elements such as compiler information and compilation parameters.
[0104] For some second-type compilation projects that have modified the compiler environment variables, the upstream build system will use the cache framework as a compiler to perform compilation tasks. However, the cache framework is mainly used to provide cache-related capabilities, not as an actual compiler itself, but to call the compiler to perform compilation tasks. At this time, the actual compiler path is obtained based on the PATH environment variable or configuration file information, and the corresponding compiler information and compilation parameters are obtained based on the compiler path.
[0105] In one or more embodiments of the present specification, generally speaking, the dependency information file records the list of header files that the source file (source code) depends on when compiling. Changes in these header files will affect the compilation results of the source files, so when performing incremental builds, the compilation system can determine which files need to be recompiled by comparing information such as the modification timestamps of the header files.
[0106] Based on this, if it is determined that the dependency information file exists, but according to the first hash result and the second hash result, it is determined that there is no cache product, in addition to the reason that the source code has not been compiled, there may be two other reasons that lead to the occurrence of this abnormal situation.
[0107] The first reason is that due to the abnormal cache update of the distributed cache, the header file information recorded in the dependency information file is updated incorrectly when the local cache is updated. At this time, the header file information contained in the dependency information file is read, and the latest modification timestamp corresponding to each header file information is determined, and then the header file information is restored based on the latest modification timestamp. Of course, the restoration here does not require modifying the original dependency information file, but reading out the data therein and restoring the data.
[0108] At this time, the second hash result corresponding to the restored header file information is obtained based on the hash algorithm, and based on the second hash result and the first hash result, it is re-determined whether there is a cache product in the corresponding path information. If the corresponding cache product is read at this time, it can be provided to the R&D personnel. Of course, it can be marked so that the R&D personnel can check the dependent file information and use the cache product if there is an error.
[0109] If the cached product still does not exist in the corresponding path information after re-determining it, it may be the second reason. The source code has actually been compiled in other machines, but due to communication anomalies, broadcast anomalies or other reasons, the local cache is not updated in time.
[0110] Based on this, based on broadcasting, the update cache of other nodes in the distributed cache is obtained, and the local cache is instantly updated based on the update cache, so as to perform hash addressing again based on the first hash result and the second hash result before restoration.
[0111] Based on the same idea, one or more embodiments of this specification also provide devices and apparatuses corresponding to the above methods, such as Figure 6 , Figure 7 shown.
[0112] Figure 6 A schematic diagram of a compile cache implementation device provided in one or more embodiments of this specification, the device comprising:
[0113] An element determination module 602 obtains source code and determines compilation elements of the source code;
[0114] A cache addressing module 604 performs addressing in a cache based on the compilation element to determine whether the source code hits the cache;
[0115] The extraction module 606 extracts the corresponding cache product if the determination result of the cache addressing module is a hit;
[0116] The compile update module 608 executes a native compile command for the source code to obtain a compile product if the determination result of the cache addressing module is a miss, and updates the cache according to the compile product.
[0117] Optionally, the cache addressing module 604 determines that the compilation elements include multiple component dimensions on which the code compilation implementation process depends;
[0118] For the component dimension, obtaining a first hash result corresponding to the component dimension based on a hash algorithm;
[0119] Hash addressing is performed based on the first hash result to determine whether the source code hits the cache.
[0120] Optionally, the cache addressing module 604 performs hash addressing according to the first hash result to determine whether there is a dependency information file in the corresponding path information;
[0121] If it exists, read the header file information contained in the dependency information file, and obtain a second hash result corresponding to the header file information based on a hash algorithm;
[0122] Hash addressing is performed according to the first hash result and the second hash result to determine whether there is a cache product in the corresponding path information.
[0123] Optionally, the cache addressing module 604 determines that the composition dimension includes at least one of: compiler information, compilation parameters, and source file content;
[0124] Among them, among the compilation parameters, some compilation parameters that do not affect the compilation results are screened out; and for some compilation parameters used to represent access to a specified file, a hash result corresponding to the file content of the accessed specified file is used as part of the content in the first hash result corresponding to the compilation parameter.
[0125] Optionally, the cache addressing module 604 constructs a compiler startup command through the cache framework for the first type of compilation project in which the compiler environment variables are not modified by the cache framework, and adds a compiler based on the compiler startup command to obtain the compiler information and the compilation parameters;
[0126] For the second type of compilation project in which the compiler environment variables have been modified by the cache framework, the compiler path is obtained based on the environment variables or configuration file information, and the corresponding compiler information and the compilation parameters are obtained based on the compiler path.
[0127] Optionally, the cache framework includes: an integration module, a cache module, and a general module;
[0128] Wherein, the integrated module integrates a variety of compilation tools;
[0129] The cache module is used to support the cache strategy of the cache;
[0130] The general module is used to support general configuration information and statistical information.
[0131] Optionally, after determining whether there is a cache product in the corresponding path information, the cache addressing module 604 further includes:
[0132] Determining that the dependency information file exists based on the first hash result, and determining that no cache product exists based on the first hash result and the second hash result;
[0133] If the cache mode is distributed cache, read the header file information contained in the dependency information file, and determine the latest modification timestamp corresponding to each header file information;
[0134] Based on the latest modification timestamp, the header file information is restored, and a second hash result corresponding to the restored header file information is obtained based on the hash algorithm. Based on the second hash result obtained again and the first hash result, it is re-determined whether there is a cache product in the corresponding path information.
[0135] Optionally, after the cache addressing module 604 re-determines whether there is a cache product in the corresponding path information, the method further includes:
[0136] Re-determining the corresponding path information, there is still no cache product;
[0137] Based on the broadcast, the update cache of other nodes in the distributed cache is obtained, and the local cache is updated instantly based on the update cache.
[0138] Optionally, the compilation update module 608 updates the local cache according to the compilation product, extracts the missed compilation products from the local cache, and packages the compilation products;
[0139] The packaging result is synchronized to other packaging machines in the distributed cache, so that other packaging machines receive the packaging result, perform decompression operations, and perform batch cache merging to update the distributed cache.
[0140] Optionally, the device further includes: an incremental update module 610;
[0141] The incremental update module 610 performs incremental compilation based on the cached product to obtain a corresponding incremental compilation product;
[0142] Update the local cache according to the incremental compilation product;
[0143] Obtaining a compilation entity factor corresponding to the cache product, and determining a packer corresponding to the compilation entity factor in the distributed cache;
[0144] Broadcasting is performed to the corresponding packer, so that the corresponding packer can update its local cache immediately after obtaining the incremental compilation product.
[0145] Figure 7A schematic diagram of a compile cache implementation device provided in one or more embodiments of this specification, the device comprising:
[0146] at least one processor; and,
[0147] a memory communicatively connected to the at least one processor; wherein,
[0148] The memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to:
[0149] Obtaining source code and determining compilation elements of the source code;
[0150] Addressing in a cache based on the compilation element to determine whether the source code hits the cache;
[0151] If there is a hit, the corresponding cache product is extracted;
[0152] If there is no hit, a native compilation command is executed on the source code to obtain a compilation product, and the cache is updated according to the compilation product.
[0153] Based on the same idea, one or more embodiments of this specification also provide a non-volatile computer storage medium corresponding to the above method, storing computer executable instructions, wherein the computer executable instructions are configured as follows:
[0154] Obtaining source code and determining compilation elements of the source code;
[0155] Addressing in a cache based on the compilation element to determine whether the source code hits the cache;
[0156] If there is a hit, the corresponding cache product is extracted;
[0157] If there is no hit, a native compilation command is executed on the source code to obtain a compilation product, and the cache is updated according to the compilation product.
[0158] In the 1990s, improvements to a technology could be clearly distinguished as hardware improvements (for example, improvements to the circuit structure of diodes, transistors, switches, etc.) or software improvements (improvements to the method flow). However, with the development of technology, many improvements to the method flow today can be regarded as direct improvements to the hardware circuit structure. Designers almost always obtain the corresponding hardware circuit structure by programming the improved method flow into the hardware circuit. Therefore, it cannot be said that an improvement in a method flow cannot be implemented using a hardware entity module. For example, a programmable logic device (PLD) (such as a field programmable gate array (FPGA)) is such an integrated circuit whose logical function is determined by the user's programming of the device. Designers can "integrate" a digital system on a PLD by programming it themselves, without having to ask a chip manufacturer to design and produce a dedicated integrated circuit chip. Moreover, nowadays, instead of manually making integrated circuit chips, this kind of programming is mostly implemented by "logic compiler" software, which is similar to the software compiler used when developing and writing programs, and the original code before compilation must also be written in a specific programming language, which is called hardware description language (HDL). There is not only one HDL, but many kinds, such as ABEL (Advanced Boolean Expression Language), AHDL (Altera Hardware Description Language), Confluence, CUPL (Cornell University Programming Language), HDCal, JHDL (Java Hardware Description Language), Lava, Lola, MyHDL, PALASM, RHDL (Ruby Hardware Description Language), etc. The most commonly used ones are VHDL (Very-High-Speed Integrated Circuit Hardware Description Language) and Verilog. Those skilled in the art should also know that it is only necessary to program the method flow slightly in the above-mentioned hardware description languages and program it into the integrated circuit, and then it is easy to obtain the hardware circuit that implements the logic method flow.
[0159] The controller can be implemented in any appropriate manner, for example, the controller can take the form of a microprocessor or processor and a computer-readable medium storing a computer-readable program code (such as software or firmware) that can be executed by the (micro)processor, a logic gate, a switch, an application-specific integrated circuit (ASIC), a programmable logic controller, and an embedded microcontroller. Examples of controllers include, but are not limited to, the following microcontrollers: ARC 625D, Atmel AT91SAM, Microchip PIC18F26K20, and Silicone Labs C8051F320. The memory controller can also be implemented as part of the control logic of the memory. Those skilled in the art also know that in addition to implementing the controller in a purely computer-readable program code manner, the controller can be implemented in the form of a logic gate, a switch, an application-specific integrated circuit, a programmable logic controller, and an embedded microcontroller by logically programming the method steps. Therefore, this controller can be considered as a hardware component, and the devices included therein for implementing various functions can also be regarded as structures within the hardware component. Or even, the devices for implementing various functions can be regarded as both software modules for implementing the method and structures within the hardware component.
[0160] The systems, devices, modules or units described in the above embodiments may be implemented by computer chips or entities, or by products with certain functions. A typical implementation device is a computer. Specifically, the computer may be, for example, a personal computer, a laptop computer, a cellular phone, a camera phone, a smart phone, a personal digital assistant, a media player, a navigation device, an email device, a game console, a tablet computer, a wearable device, or a combination of any of these devices.
[0161] For the convenience of description, the above device is described in various units according to their functions. Of course, when implementing this specification, the functions of each unit can be implemented in the same or multiple software and / or hardware.
[0162] Those skilled in the art will appreciate that the embodiments of this specification may be provided as methods, systems, or computer program products. Therefore, the embodiments of this specification may be in the form of complete hardware embodiments, complete software embodiments, or embodiments in combination with software and hardware. Moreover, the embodiments of this specification may be in the form of a computer program product implemented in one or more computer-usable storage media (including but not limited to disk storage, CD-ROM, optical storage, etc.) that contain computer-usable program code.
[0163] This specification is described with reference to the flowcharts and / or block diagrams of the methods, devices (systems), and computer program products according to the embodiments of this specification. It should be understood that each process and / or box in the flowchart and / or block diagram, as well as the combination of the processes and / or boxes in the flowchart and / or block diagram, can be implemented by computer program instructions. These computer program instructions can be provided to a processor of a general-purpose computer, a special-purpose computer, an embedded processor, or other programmable data processing device to produce a machine, so that the instructions executed by the processor of the computer or other programmable data processing device generate instructions for implementing the processes in the flowchart and / or block diagram. Figure 1 A process or multiple processes and / or boxes Figure 1 A device that provides the functions specified in a block or multiple blocks.
[0164] These computer program instructions may also be stored in a computer-readable memory capable of directing a computer or other programmable data processing device to operate in a specific manner, so that the instructions stored in the computer-readable memory produce an article of manufacture comprising an instruction device, which implements the process Figure 1 A process or multiple processes and / or boxes Figure 1 A function specified in one or more boxes.
[0165] These computer program instructions can also be loaded onto a computer or other programmable data processing device so that a series of operating steps are executed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions for implementing the process. Figure 1 A process or multiple processes and / or boxes Figure 1 The steps for the functions specified in one or more boxes.
[0166] In a typical configuration, a computing device includes one or more processors (CPU), input / output interfaces, network interfaces, and memory.
[0167] The memory may include non-permanent storage in a computer-readable medium, random access memory (RAM) and / or non-volatile memory in the form of read-only memory (ROM) or flash RAM. The memory is an example of a computer-readable medium.
[0168] Computer readable media include permanent and non-permanent, removable and non-removable media that can be implemented by any method or technology to store information. Information can be computer readable instructions, data structures, program modules or other data. Examples of computer storage media include, but are not limited to, phase change memory (PRAM), static random access memory (SRAM), dynamic random access memory (DRAM), other types of random access memory (RAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), flash memory or other memory technology, compact disk read-only memory (CD-ROM), digital versatile disk (DVD) or other optical storage, magnetic cassettes, magnetic tape magnetic disk storage or other magnetic storage devices or any other non-transmission media that can be used to store information that can be accessed by a computing device. As defined herein, computer readable media does not include temporary computer readable media (transitory media), such as modulated data signals and carrier waves.
[0169] It should also be noted that the terms "include", "comprises" or any other variations thereof are intended to cover non-exclusive inclusion, so that a process, method, commodity or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, commodity or device. In the absence of more restrictions, the elements defined by the sentence "comprises a ..." do not exclude the existence of other identical elements in the process, method, commodity or device including the elements.
[0170] This specification may be described in the general context of computer-executable instructions executed by a computer, such as program modules. Generally, program modules include routines, programs, objects, components, data structures, etc. that perform specific tasks or implement specific abstract data types. This specification may also be practiced in distributed computing environments where tasks are performed by remote processing devices connected through a communication network. In a distributed computing environment, program modules may be located in local and remote computer storage media, including storage devices.
[0171] Each embodiment in this specification is described in a progressive manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device, equipment, and non-volatile computer storage medium embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiment.
[0172] The above is a description of a specific embodiment of the specification. Other embodiments are within the scope of the appended claims. In some cases, the actions or steps recorded in the claims can be performed in an order different from that in the embodiments and still achieve the desired results. In addition, the processes depicted in the drawings do not necessarily require the specific order or continuous order shown to achieve the desired results. In some embodiments, multitasking and parallel processing are also possible or may be advantageous.
[0173] The above description is only one or more embodiments of this specification and is not intended to limit this specification. For those skilled in the art, one or more embodiments of this specification may have various changes and variations. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of one or more embodiments of this specification shall be included in the scope of the claims of this specification.
Claims
1. A compilation cache implementation method, comprising: Obtaining source code and determining compilation elements of the source code; Addressing in a cache based on the compilation element to determine whether the source code hits the cache; If there is a hit, the corresponding cache product is extracted; If there is no hit, a native compilation command is executed on the source code to obtain a compilation product, and the cache is updated according to the compilation product.
2. The method according to claim 1, wherein addressing in a cache based on the compilation element to determine whether the source code hits the cache specifically comprises: Determining that the compilation elements include a plurality of component dimensions on which the code compilation implementation process depends; For the component dimension, obtaining a first hash result corresponding to the component dimension based on a hash algorithm; Hash addressing is performed based on the first hash result to determine whether the source code hits the cache.
3. The method according to claim 2, wherein performing hash addressing based on the first hash result to determine whether the source code hits the cache specifically comprises: Perform hash addressing according to the first hash result to determine whether there is a dependency information file in the corresponding path information; If it exists, read the header file information contained in the dependency information file, and obtain a second hash result corresponding to the header file information based on a hash algorithm; Hash addressing is performed according to the first hash result and the second hash result to determine whether there is a cache product in the corresponding path information.
4. The method according to claim 2, wherein for the component dimension, obtaining a first hash result corresponding to the component dimension based on a hash algorithm specifically comprises: Determining that the composition dimensions include: at least multiple of compiler information, compilation parameters, and source file content; Among them, among the compilation parameters, some compilation parameters that do not affect the compilation results are screened out; and for some compilation parameters used to represent access to a specified file, a hash result corresponding to the file content of the accessed specified file is used as part of the content in the first hash result corresponding to the compilation parameter.
5. The method according to claim 4, wherein determining the compilation elements of the source code specifically comprises: For the first type of compilation project in which the compiler environment variables are not modified by the cache framework, a compiler startup command is constructed through the cache framework, and a compiler is added based on the compiler startup command to obtain the compiler information and the compilation parameters; For the second type of compilation project in which the compiler environment variables have been modified by the cache framework, the compiler path is obtained based on the environment variables or configuration file information, and the corresponding compiler information and the compilation parameters are obtained based on the compiler path.
6. The method of claim 5, wherein the cache framework comprises: Integration module, cache module, general module; Wherein, the integrated module integrates a variety of compilation tools; The cache module is used to support the cache strategy of the cache; The general module is used to support general configuration information and statistical information.
7. The method according to claim 3, after determining whether there is a cache product in the corresponding path information, the method further comprises: Determining that the dependency information file exists based on the first hash result, and determining that no cache product exists based on the first hash result and the second hash result; If the cache mode is distributed cache, read the header file information contained in the dependency information file, and determine the latest modification timestamp corresponding to each header file information; Based on the latest modification timestamp, the header file information is restored, and a second hash result corresponding to the restored header file information is obtained based on the hash algorithm. Based on the second hash result obtained again and the first hash result, it is re-determined whether there is a cache product in the corresponding path information.
8. The method according to claim 7, after re-determining whether there is a cache product in the corresponding path information, the method further comprises: Re-determining the corresponding path information, there is still no cache product; Based on the broadcast, the update cache of other nodes in the distributed cache is obtained, and the local cache is updated instantly based on the update cache.
9. The method according to claim 1, wherein updating the cache according to the compiled product specifically comprises: The local cache is updated according to the compilation product, and the missed compilation products are extracted from the local cache, and the compilation products are packaged; The packaging result is synchronized to other packaging machines in the distributed cache, so that other packaging machines receive the packaging result, perform decompression operations, and perform batch cache merging to update the distributed cache.
10. The method according to claim 9, after extracting the corresponding cache product, the method further comprises: Performing incremental compilation based on the cached product to obtain a corresponding incremental compilation product; Update the local cache according to the incremental compilation product; Obtaining a compilation entity factor corresponding to the cache product, and determining a packer corresponding to the compilation entity factor in the distributed cache; Broadcasting is performed to the corresponding packer, so that the corresponding packer can update its local cache immediately after obtaining the incremental compilation product.
11. A compile cache implementation device, comprising: An element determination module obtains source code and determines compilation elements of the source code; A cache addressing module, which addresses the cache based on the compilation element to determine whether the source code hits the cache; an extraction module, which extracts a corresponding cache product if the determination result of the cache addressing module is a hit; The compile update module executes a native compile command for the source code to obtain a compile product if the determination result of the cache addressing module is a miss, and updates the cache according to the compile product.
12. The apparatus according to claim 11, wherein the cache addressing module determines that the compilation elements include a plurality of component dimensions on which a code compilation implementation process depends; For the component dimension, obtaining a first hash result corresponding to the component dimension based on a hash algorithm; Hash addressing is performed based on the first hash result to determine whether the source code hits the cache.
13. The device according to claim 12, wherein the cache addressing module performs hash addressing according to the first hash result to determine whether there is a dependency information file in the corresponding path information; If it exists, read the header file information contained in the dependency information file, and obtain a second hash result corresponding to the header file information based on a hash algorithm; Hash addressing is performed according to the first hash result and the second hash result to determine whether there is a cache product in the corresponding path information.
14. The apparatus according to claim 12, wherein the cache addressing module determines the component dimension comprising: At least some of compiler information, compilation parameters, and source file contents; Among them, among the compilation parameters, some compilation parameters that do not affect the compilation results are screened out; and for some compilation parameters used to represent access to a specified file, a hash result corresponding to the file content of the accessed specified file is used as part of the content in the first hash result corresponding to the compilation parameter.
15. The device according to claim 14, wherein the cache addressing module, for a first type of compilation project in which the compiler environment variables are not modified by the cache framework, constructs a compiler startup command through the cache framework, and adds a compiler based on the compiler startup command to obtain the compiler information and the compilation parameters; For the second type of compilation project in which the compiler environment variables have been modified by the cache framework, the compiler path is obtained based on the environment variables or configuration file information, and the corresponding compiler information and the compilation parameters are obtained based on the compiler path.
16. The apparatus of claim 15, wherein the cache framework comprises: Integration module, cache module, general module; Wherein, the integrated module integrates a variety of compilation tools; The cache module is used to support the cache strategy of the cache; The general module is used to support general configuration information and statistical information.
17. The device according to claim 13, wherein the cache addressing module, after determining whether there is a cache product in the corresponding path information, further comprises: Determining that the dependency information file exists based on the first hash result, and determining that no cache product exists based on the first hash result and the second hash result; If the cache mode is distributed cache, read the header file information contained in the dependency information file, and determine the latest modification timestamp corresponding to each header file information; Based on the latest modification timestamp, the header file information is restored, and a second hash result corresponding to the restored header file information is obtained based on the hash algorithm. Based on the second hash result obtained again and the first hash result, it is re-determined whether there is a cache product in the corresponding path information.
18. The apparatus according to claim 17, wherein the cache addressing module, after re-determining whether there is a cache product in the corresponding path information, the method further comprises: Re-determining the corresponding path information, there is still no cache product; Based on the broadcast, the update cache of other nodes in the distributed cache is obtained, and the local cache is updated instantly based on the update cache.
19. The device according to claim 11, wherein the compile update module updates the local cache according to the compiled product, extracts the missed compiled products from the local cache, and packages the compiled products; The packaging result is synchronized to other packaging machines in the distributed cache, so that other packaging machines receive the packaging result, perform decompression operations, and perform batch cache merging to update the distributed cache.
20. The apparatus of claim 19, further comprising: Incremental update module; The incremental update module performs incremental compilation based on the cached product to obtain a corresponding incremental compilation product; Update the local cache according to the incremental compilation product; Obtaining a compilation entity factor corresponding to the cache product, and determining a packer corresponding to the compilation entity factor in the distributed cache; Broadcasting is performed to the corresponding packer, so that the corresponding packer can update its local cache immediately after obtaining the incremental compilation product.
21. A device comprising: at least one processor; as well as, a memory communicatively connected to the at least one processor; wherein, The memory stores instructions executable by the at least one processor, the instructions being executed by the at least one processor to enable the at least one processor to: Obtaining source code and determining compilation elements of the source code; Addressing in a cache based on the compilation element to determine whether the source code hits the cache; If there is a hit, the corresponding cache product is extracted; If there is no hit, a native compilation command is executed on the source code to obtain a compilation product, and the cache is updated according to the compilation product.
