A method and apparatus for compiling
By determining the target decompression algorithm to decompress the compilation output during the Android project compilation process, the problem of low compression efficiency in existing technologies is solved, and compilation efficiency is improved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- DOUYIN VISION CO LTD
- Filing Date
- 2022-03-24
- Publication Date
- 2026-05-01
AI Technical Summary
During the compilation process of Android projects, existing technologies use common compression algorithms, resulting in low compression and decompression efficiency, which fails to fully leverage the compilation speed advantage of higher-performance computer devices.
By determining the target decompression algorithm that matches the compressed compilation output, and using the target decompression algorithm to decompress the compilation output, the compilation output of different compression algorithms can be decompressed, thereby improving compilation efficiency.
It improves the flexibility of compile-time compression algorithm selection and compilation efficiency, ensuring that higher-performance computer devices can fully utilize their compilation speed advantage.
Smart Images

Figure CN114610323B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and more specifically, to a compilation method and apparatus. Background Technology
[0002] During the compilation process of an Android project, the entire compilation process can be broken down into multiple compilation tasks. Each compilation task, as the smallest unit of the compilation process, is also called a task. Before each compilation task is executed, it is usually necessary to determine whether there is cached data corresponding to the compilation output of the compilation task. If so, the cached data can be decompressed and the compilation result can be generated using the decompressed cached data, thereby reducing the workload of compilation.
[0003] Since the compiled output is stored in the form of a cache, it needs to be compressed when storing it as cache data. After reading the cache, it also needs to be decompressed. When compressing the compiled output, the program will uniformly choose a more common compression algorithm in order to adapt the cache data to various devices, resulting in low compression and decompression efficiency. Summary of the Invention
[0004] This disclosure provides at least one compilation method and apparatus.
[0005] In a first aspect, embodiments of this disclosure provide a compilation method, including:
[0006] Obtain the code to be compiled and generate multiple compilation tasks corresponding to the code to be compiled;
[0007] For any compilation task, before starting the execution of the compilation task, determine the target code segment corresponding to the compilation task;
[0008] Locate the cached compressed compilation product corresponding to the target code segment. If the compressed compilation product is successfully found, determine the target decompression algorithm that matches the compressed compilation product from a variety of candidate decompression algorithms.
[0009] The compressed compilation product is decompressed using the target decompression algorithm to obtain the decompressed compilation product corresponding to the compilation task;
[0010] Based on the obtained decompressed compilation product, an executable file corresponding to the code to be compiled is generated.
[0011] In one optional implementation, the method further includes:
[0012] If the cached compressed compilation product is not found, the compilation task is executed to compile the target code segment and obtain the compilation product corresponding to the compilation task.
[0013] Based on the compilation artifacts obtained by executing the compilation task, an executable file corresponding to the code to be compiled is generated.
[0014] In an optional implementation, after executing the compilation task to compile the target code segment and obtain the compilation product corresponding to the compilation task, the method further includes:
[0015] Based on the configuration information of the computer device performing the compilation task, a target compression algorithm is selected from a variety of candidate compression algorithms;
[0016] The compilation product is compressed using the target compression algorithm to obtain the compressed compilation product corresponding to the target code fragment, and the compressed compilation product is cached.
[0017] In one optional implementation, caching the compressed compilation output includes:
[0018] Determine the hash value of the target code fragment;
[0019] Establish a matching relationship between the hash value corresponding to the target code fragment and the compressed compilation product, and cache the matching relationship and the compressed compilation product;
[0020] The process of finding the cached compressed compilation artifact corresponding to the target code fragment includes:
[0021] Determine the hash value of the target code fragment;
[0022] Based on the matching relationship, find the compressed compilation product corresponding to the hash value of the target code fragment.
[0023] In one optional implementation, determining a target decompression algorithm that matches the compressed compiled product from a plurality of candidate decompression algorithms includes:
[0024] From the various candidate decompression algorithms, a target decompression algorithm that matches the selected target compression algorithm is determined.
[0025] In one optional implementation, the step of selecting a target compression algorithm from a variety of candidate compression algorithms based on the configuration information of the computer device performing the compilation task includes:
[0026] Obtain the runtime configuration requirements corresponding to the various candidate compression algorithms;
[0027] From the various candidate compression algorithms, the compression algorithm whose operation configuration requirements match the configuration information is selected as the target compression algorithm.
[0028] In one optional implementation, compiling the target code fragment includes:
[0029] Based on the target code fragment and the cached intermediate compilation products, determine the available intermediate products among the intermediate compilation products;
[0030] Based on the available intermediate products, the target code fragment is incrementally compiled;
[0031] If no usable intermediate products are found in the compilation intermediate products, then the target code segment is fully compiled.
[0032] Secondly, embodiments of this disclosure also provide a compilation apparatus, comprising:
[0033] The acquisition module is used to acquire the code to be compiled and generate multiple compilation tasks corresponding to the code to be compiled.
[0034] The determination module is used to determine the target code segment corresponding to any compilation task before starting the execution of the compilation task;
[0035] The query module is used to find the cached compressed compilation product corresponding to the target code fragment. If the compressed compilation product is successfully found, the target decompression algorithm that matches the compressed compilation product is determined from a variety of candidate decompression algorithms.
[0036] The decompression module is used to decompress the compressed compilation product using the target decompression algorithm to obtain the decompressed compilation product corresponding to the compilation task.
[0037] The compilation module is used to generate an executable file corresponding to the code to be compiled based on the obtained decompressed compilation product.
[0038] In one optional implementation, the compilation module is further configured to:
[0039] If the cached compressed compilation product is not found, the compilation task is executed to compile the target code segment and obtain the compilation product corresponding to the compilation task.
[0040] Based on the compilation artifacts obtained by executing the compilation task, an executable file corresponding to the code to be compiled is generated.
[0041] In an optional embodiment, the apparatus further includes a caching module, which, after executing the compilation task, compiling the target code segment, and obtaining the compilation artifact corresponding to the compilation task, is used for:
[0042] Based on the configuration information of the computer device performing the compilation task, a target compression algorithm is selected from a variety of candidate compression algorithms;
[0043] The compilation product is compressed using the target compression algorithm to obtain the compressed compilation product corresponding to the target code fragment, and the compressed compilation product is cached.
[0044] In one optional implementation, the caching module, when caching the compressed compilation output, is used to:
[0045] Determine the hash value of the target code fragment;
[0046] Establish a matching relationship between the hash value corresponding to the target code fragment and the compressed compilation product, and cache the matching relationship and the compressed compilation product;
[0047] When the query module searches for the cached compressed compilation artifact corresponding to the target code fragment, it is used for:
[0048] Determine the hash value of the target code fragment;
[0049] Based on the matching relationship, find the compressed compilation product corresponding to the hash value of the target code fragment.
[0050] In an optional implementation, when determining a target decompression algorithm that matches the compressed compiled product from a variety of candidate decompression algorithms, the query module is used to:
[0051] From the various candidate decompression algorithms, a target decompression algorithm that matches the selected target compression algorithm is determined.
[0052] In one optional implementation, when the caching module selects a target compression algorithm from a variety of candidate compression algorithms based on the configuration information of the computer device performing the compilation task, it is used to:
[0053] Obtain the runtime configuration requirements corresponding to the various candidate compression algorithms;
[0054] From the various candidate compression algorithms, the compression algorithm whose operation configuration requirements match the configuration information is selected as the target compression algorithm.
[0055] In one optional implementation, the compilation module, when compiling the target code fragment, is used to:
[0056] Based on the target code fragment and the cached intermediate compilation products, determine the available intermediate products among the intermediate compilation products;
[0057] Based on the available intermediate products, the target code fragment is incrementally compiled;
[0058] If no usable intermediate products are found in the compilation intermediate products, then the target code segment is fully compiled.
[0059] Thirdly, embodiments of this disclosure also provide an electronic device, including: a processor, a memory, and a bus, wherein the memory stores machine-readable instructions executable by the processor, and when the electronic device is running, the processor communicates with the memory via the bus, and when the machine-readable instructions are executed by the processor, the steps of the first aspect above, or any possible implementation of the first aspect, are performed.
[0060] Fourthly, embodiments of this disclosure also provide a computer-readable storage medium storing a computer program that, when executed by a processor, performs the steps of the first aspect or any possible implementation of the first aspect.
[0061] The compilation method and apparatus provided in this disclosure first obtain the code to be compiled and generate multiple compilation tasks corresponding to the code to be compiled. Then, for any compilation task, before starting to execute the compilation task, the target code segment corresponding to the compilation task is determined. Next, the cached compressed compilation product corresponding to the target code segment is searched. If the compressed compilation product is successfully found, a target decompression algorithm matching the compressed compilation product is determined from multiple candidate decompression algorithms. Next, the compressed compilation product is decompressed using the target decompression algorithm to obtain the decompressed compilation product corresponding to the compilation task. Finally, based on the obtained decompressed compilation product, an executable file corresponding to the code to be compiled is generated. This disclosure, by determining the target decompression algorithm matching the compressed compilation product and then using the determined target decompression algorithm to decompress the compilation product, achieves decompression of compilation products using different compression algorithms, thereby diversifying the selection of compression algorithms in the compilation scenario, improving the flexibility of compression algorithm selection during compilation, and improving compilation efficiency through appropriate compression algorithms.
[0062] To make the above-mentioned objects, features and advantages of this disclosure more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0063] To more clearly illustrate the technical solutions of the embodiments of this disclosure, the accompanying drawings used in the embodiments will be briefly described below. These drawings are incorporated in and constitute a part of this specification. They illustrate embodiments conforming to this disclosure and, together with the specification, serve to explain the technical solutions of this disclosure. It should be understood that the following drawings only show some embodiments of this disclosure and should not be considered as limiting the scope. Those skilled in the art can obtain other related drawings based on these drawings without creative effort.
[0064] Figure 1 A flowchart of a compilation method provided by an embodiment of this disclosure is shown;
[0065] Figure 2 A flowchart of another compilation method provided by an embodiment of this disclosure is shown;
[0066] Figure 3 A schematic diagram of a compilation apparatus provided in an embodiment of this disclosure is shown;
[0067] Figure 4 A schematic diagram of an electronic device provided in an embodiment of the present disclosure is shown. Detailed Implementation
[0068] To make the objectives, technical solutions, and advantages of the embodiments of this disclosure clearer, the technical solutions of the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only a part of the embodiments of this disclosure, and not all of them. The components of the embodiments of this disclosure described and shown in the accompanying drawings can generally be arranged and designed in various different configurations. Therefore, the following detailed description of the embodiments of this disclosure provided in the accompanying drawings is not intended to limit the scope of the claimed disclosure, but merely represents selected embodiments of this disclosure. All other embodiments obtained by those skilled in the art based on the embodiments of this disclosure without inventive effort are within the scope of protection of this disclosure.
[0069] It should be noted that similar labels and letters in the following figures indicate similar items. Therefore, once an item is defined in one figure, it does not need to be further defined and explained in subsequent figures.
[0070] In this document, the term "and / or" merely describes a relationship, indicating that three relationships can exist. For example, A and / or B can represent three cases: A alone, A and B simultaneously, and B alone. Furthermore, the term "at least one" in this document means any combination of at least two of any one or more elements. For example, including at least one of A, B, and C can mean including any one or more elements selected from the set consisting of A, B, and C.
[0071] Research has revealed that due to the varying performance of computer devices executing the compilation process, lower-performance devices typically run older, more stable compression and decompression algorithms. These algorithms generally have lower compression and decompression efficiencies, while higher-version, more efficient compression and decompression algorithms may not be able to run. Therefore, in practical compilation scenarios, a more stable and universally applicable compression algorithm is usually chosen to compress the compilation output. This results in the compilation speed of higher-performance computer devices being limited by lower-version compression and decompression algorithms, preventing them from fully utilizing their high-performance advantages and leading to lower efficiency.
[0072] Based on the above research, this disclosure provides a compilation method that determines the target decompression algorithm matching the compressed compilation product, and then uses the determined target decompression algorithm to decompress the compilation product. This enables the decompression of compilation products using different compression algorithms, thereby diversifying the selection of compression algorithms in the compilation scenario, improving the flexibility of compression algorithm selection during compilation, and improving compilation efficiency through appropriate compression algorithms.
[0073] To facilitate understanding of this embodiment, a compilation method disclosed in this disclosure will first be described in detail. The execution subject of the compilation method provided in this disclosure is generally a computer device with a certain computing power. In some possible implementations, this compilation method can be implemented by the processor calling computer-readable instructions stored in memory.
[0074] See Figure 1 The diagram shows a flowchart of a compilation method provided in an embodiment of this disclosure. The method includes steps S101 to S105, wherein:
[0075] S101. Obtain the code to be compiled and generate multiple compilation tasks corresponding to the code to be compiled.
[0076] The code to be compiled can be the source code of the application. By compiling the code to be compiled, the executable file of the application can be obtained. The application mentioned above can be an Android application. When compiling the code to be compiled, a compilation task list can be generated using a compilation framework. The compilation task list can record multiple compilation tasks corresponding to the code to be compiled, i.e., tasks.
[0077] The compilation tasks mentioned above can have different execution priorities. Compilation tasks with the same execution priority can be executed simultaneously. A compilation task with a lower priority may need to use the execution output of a compilation task with a higher priority. Therefore, it needs to be executed after the compilation task with a higher priority has finished. The compilation tasks can be sorted according to their priority to obtain the execution order of the compilation tasks.
[0078] S102. For any compilation task, before starting to execute the compilation task, determine the target code segment corresponding to the compilation task.
[0079] During the execution of compilation tasks in the order of execution, whenever a new compilation task is started, the target code segment corresponding to the compilation task can be determined before starting the execution of the compilation task. The target code segment can be the code segment that needs to be compiled as indicated by the compilation task. By compiling the target code segment, the compilation product corresponding to the target code segment can be obtained. The compilation product can be an executable file or an intermediate product required for compilation.
[0080] S103. Locate the cached compressed compilation product corresponding to the target code segment. If the compressed compilation product is successfully found, determine the target decompression algorithm that matches the compressed compilation product from a variety of candidate decompression algorithms.
[0081] After the target code segment is determined, the corresponding cached compressed compilation product can be found. This compressed compilation product can be the product obtained after the current computer device or other computer devices execute the target code segment. After compression, it is stored in a cache database, which can be a local database or a cloud database. The current computer device can access the cache database and retrieve the compressed compilation product stored in the cache database. The compressed compilation product can be decompressed and used as the product of the currently executed compilation task.
[0082] Here, the compressed compilation artifacts can carry a unique identifier corresponding to the target code segment through filenames or comments, and this unique identifier can be determined by calculating hash values or message digests.
[0083] After successfully finding the required compressed product, the target compression algorithm used for the compressed product can be determined. Then, the target decompression algorithm that matches the target compression algorithm is selected from a variety of candidate decompression algorithms.
[0084] S104. Decompress the compressed compilation product using the target decompression algorithm to obtain the decompressed compilation product corresponding to the compilation task.
[0085] Once the target decompression algorithm is determined, it can be used to decompress the compressed compilation output, yielding the decompressed compilation output for the given compilation task. Given sufficient computer performance, and since current computers support multiple compression algorithms and their corresponding decompression algorithms, it is possible to decompress compilation outputs using different compression algorithms. This allows for the selection of more efficient and effective compression algorithms without affecting the computer's normal compression and decompression functions, reducing compression and decompression time and improving compilation efficiency.
[0086] Furthermore, if the cached compressed compilation artifacts are not found, the compilation task can be executed directly to compile the target code fragments and obtain the compilation artifacts corresponding to the compilation task. After the compilation task is completed, other compilation tasks can be waited for to be executed, and then the executable file corresponding to the code to be compiled can be generated based on the compilation artifacts obtained from the compilation task.
[0087] When compiling a target code segment, you can first determine the available intermediate products in the compilation intermediate products based on the target code segment and the cached compilation intermediate products. The available intermediate products can be used as intermediate products in the compilation task, and the target code segment can be incrementally compiled directly using the available intermediate products, thereby saving compilation time. If no available intermediate products are found, the target code segment can be fully compiled directly to obtain the compilation products.
[0088] After executing the compilation task, a target compression algorithm matching the configuration information can be selected from a variety of candidate compression algorithms based on the configuration information of the computer device executing the compilation task. The runtime configuration requirements corresponding to the various candidate compression algorithms can be obtained. Then, the compression algorithm whose runtime configuration requirements match the configuration information is selected as the target compression algorithm. For example, based on the computer's configuration information and runtime configuration requirements, it can be determined whether the computer can run various candidate compression algorithms and the expected efficiency of running each candidate compression algorithm. The target compression algorithm can then be selected from the candidate compression algorithms based on the expected efficiency.
[0089] After selecting the target compression algorithm, the compilation product can be compressed using the target compression algorithm to obtain the compressed compilation product corresponding to the target code fragment. Then, the obtained compressed compilation product can be cached and stored in the aforementioned cache database, which can be accessed by the current computer device or other computer devices, so that the compressed compilation product can be reused.
[0090] Specifically, the compressed compilation output can be cached using the following steps:
[0091] Determine the hash value of the target code fragment;
[0092] Establish a matching relationship between the hash value corresponding to the target code fragment and the compressed compilation product, and cache the matching relationship and the compressed compilation product.
[0093] In this step, the hash value of the target code fragment can be calculated first, and then a matching relationship between the determined hash value and the compressed compilation product can be established. The form of this matching relationship can be achieved by generating key-value pairs, modifying the file name or comments of the compressed compilation product, etc. After that, the generated matching relationship and the compressed compilation product, or the compressed compilation product carrying the above matching relationship, can be stored in the cache database to achieve the caching of the above matching relationship and the compressed compilation product.
[0094] Accordingly, when searching for the cached compressed compilation product corresponding to the target code segment, the hash value of the target code segment can be determined first; then, based on the above matching relationship, the compressed compilation product corresponding to the hash value of the target code segment can be searched.
[0095] Furthermore, the aforementioned intermediate compilation products can also be compressed and cached in a similar manner to the compilation product types, producing similar effects.
[0096] S105. Based on the obtained decompressed compilation product, generate the executable file corresponding to the code to be compiled.
[0097] After obtaining the decompressed compilation output, it can be used as the output of the compilation task. Then, the decompressed compilation output can be used as input data for other compilation tasks according to the relationship between the compilation tasks. Finally, after all compilation tasks have been completed, the executable file corresponding to the code to be compiled can be obtained.
[0098] See Figure 2 As shown, another compilation method provided in this embodiment of the present disclosure is first performed during the execution of the compilation task. This compilation method first performs a skip check to check whether there is a cache of the compressed compilation product corresponding to the target code segment. If it exists, the cache is loaded and the decompression algorithm corresponding to the cache is determined. Then, the decompression algorithm is used to decompress the cache. If it does not exist, compilation is performed directly. After compilation, a suitable compression algorithm is selected according to the configuration information of the computer device, and the compilation product obtained by the compilation is compressed using the selected compression algorithm. The compressed compilation product is then stored as a cache.
[0099] The compilation method provided in this disclosure first obtains the code to be compiled and generates multiple compilation tasks corresponding to the code. Then, for any compilation task, before starting the execution of the compilation task, the target code segment corresponding to the compilation task is determined. Next, the cached compressed compilation product corresponding to the target code segment is searched. If the compressed compilation product is successfully found, a target decompression algorithm matching the compressed compilation product is determined from multiple candidate decompression algorithms. Next, the compressed compilation product is decompressed using the target decompression algorithm to obtain the decompressed compilation product corresponding to the compilation task. Finally, based on the obtained decompressed compilation product, an executable file corresponding to the code to be compiled is generated. This disclosure, by determining the target decompression algorithm matching the compressed compilation product and then using the determined target decompression algorithm to decompress the compilation product, enables the decompression of compilation products using different compression algorithms. This diversifies the selection of compression algorithms in the compilation scenario, improves the flexibility of compression algorithm selection during compilation, and improves compilation efficiency through appropriate compression algorithms.
[0100] The compilation method and apparatus provided in this disclosure first obtain the code to be compiled and generate multiple compilation tasks corresponding to the code to be compiled. Then, for any compilation task, before starting to execute the compilation task, the target code segment corresponding to the compilation task is determined. Next, the cached compressed compilation product corresponding to the target code segment is searched. If the compressed compilation product is successfully found, a target decompression algorithm matching the compressed compilation product is determined from multiple candidate decompression algorithms. Next, the compressed compilation product is decompressed using the target decompression algorithm to obtain the decompressed compilation product corresponding to the compilation task. Finally, based on the obtained decompressed compilation product, an executable file corresponding to the code to be compiled is generated. This disclosure, by determining the target decompression algorithm matching the compressed compilation product and then using the determined target decompression algorithm to decompress the compilation product, achieves decompression of compilation products using different compression algorithms, thereby diversifying the selection of compression algorithms in the compilation scenario, improving the flexibility of compression algorithm selection during compilation, and improving compilation efficiency through appropriate compression algorithms.
[0101] Those skilled in the art will understand that, in the above-described method of the specific implementation, the order in which each step is written does not imply a strict execution order and does not constitute any limitation on the implementation process. The specific execution order of each step should be determined by its function and possible internal logic.
[0102] Based on the same inventive concept, this disclosure also provides a compilation device corresponding to the compilation method. Since the principle of the device in this disclosure for solving the problem is similar to the compilation method described above in this disclosure, the implementation of the device can refer to the implementation of the method, and the repeated parts will not be described again.
[0103] Reference Figure 3 The diagram shown is a schematic representation of a compilation apparatus provided in an embodiment of this disclosure. The apparatus includes:
[0104] The acquisition module 310 is used to acquire the code to be compiled and generate multiple compilation tasks corresponding to the code to be compiled.
[0105] The determination module 320 is used to determine the target code segment corresponding to any compilation task before starting to execute the compilation task;
[0106] The query module 330 is used to find the cached compressed compilation product corresponding to the target code fragment. If the compressed compilation product is successfully found, a target decompression algorithm matching the compressed compilation product is determined from a variety of candidate decompression algorithms.
[0107] The decompression module 340 is used to decompress the compressed compilation product using the target decompression algorithm to obtain the decompressed compilation product corresponding to the compilation task;
[0108] The compilation module 350 is used to generate an executable file corresponding to the code to be compiled based on the obtained decompressed compilation product.
[0109] In an optional implementation, the compilation module 350 is further configured to:
[0110] If the cached compressed compilation product is not found, the compilation task is executed to compile the target code segment and obtain the compilation product corresponding to the compilation task.
[0111] Based on the compilation artifacts obtained by executing the compilation task, an executable file corresponding to the code to be compiled is generated.
[0112] In an optional embodiment, the apparatus further includes a caching module, which, after executing the compilation task, compiling the target code segment, and obtaining the compilation artifact corresponding to the compilation task, is used for:
[0113] Based on the configuration information of the computer device performing the compilation task, a target compression algorithm is selected from a variety of candidate compression algorithms;
[0114] The compilation product is compressed using the target compression algorithm to obtain the compressed compilation product corresponding to the target code fragment, and the compressed compilation product is cached.
[0115] In one optional implementation, the caching module, when caching the compressed compilation output, is used to:
[0116] Determine the hash value of the target code fragment;
[0117] Establish a matching relationship between the hash value corresponding to the target code fragment and the compressed compilation product, and cache the matching relationship and the compressed compilation product;
[0118] When the query module 330 searches for the cached compressed compilation artifact corresponding to the target code fragment, it is used for:
[0119] Determine the hash value of the target code fragment;
[0120] Based on the matching relationship, find the compressed compilation product corresponding to the hash value of the target code fragment.
[0121] In an optional implementation, when determining a target decompression algorithm that matches the compressed compiled product from a variety of candidate decompression algorithms, the query module 330 is used to:
[0122] From the various candidate decompression algorithms, a target decompression algorithm that matches the selected target compression algorithm is determined.
[0123] In one optional implementation, when the caching module selects a target compression algorithm from a variety of candidate compression algorithms based on the configuration information of the computer device performing the compilation task, it is used to:
[0124] Obtain the runtime configuration requirements corresponding to the various candidate compression algorithms;
[0125] From the various candidate compression algorithms, the compression algorithm whose operation configuration requirements match the configuration information is selected as the target compression algorithm.
[0126] In one optional implementation, the compilation module 350, when compiling the target code fragment, is used to:
[0127] Based on the target code fragment and the cached intermediate compilation products, determine the available intermediate products among the intermediate compilation products;
[0128] Based on the available intermediate products, the target code fragment is incrementally compiled;
[0129] If no usable intermediate products are found in the compilation intermediate products, then the target code segment is fully compiled.
[0130] The processing flow of each module in the device and the interaction flow between each module can be referred to the relevant descriptions in the above method embodiments, and will not be detailed here.
[0131] Corresponding to Figure 1In addition to the compilation method described in the present disclosure, this embodiment also provides an electronic device 400, such as... Figure 4 The diagram shown is a structural schematic of an electronic device 400 provided in an embodiment of this disclosure, including:
[0132] The system includes a processor 41, a memory 42, and a bus 43. The memory 42 stores execution instructions and includes main memory 421 and external memory 422. The main memory 421, also called internal memory, temporarily stores the computational data in the processor 41, as well as data exchanged with external memory such as a hard disk. The processor 41 exchanges data with the external memory 422 through the main memory 421. When the electronic device 400 is running, the processor 41 communicates with the memory 42 through the bus 43, causing the processor 41 to execute the following instructions:
[0133] Obtain the code to be compiled and generate multiple compilation tasks corresponding to the code to be compiled;
[0134] For any compilation task, before starting the execution of the compilation task, determine the target code segment corresponding to the compilation task;
[0135] Locate the cached compressed compilation product corresponding to the target code segment. If the compressed compilation product is successfully found, determine the target decompression algorithm that matches the compressed compilation product from a variety of candidate decompression algorithms.
[0136] The compressed compilation product is decompressed using the target decompression algorithm to obtain the decompressed compilation product corresponding to the compilation task;
[0137] Based on the obtained decompressed compilation product, an executable file corresponding to the code to be compiled is generated.
[0138] In an optional implementation, the processor 41 further performs:
[0139] If the cached compressed compilation product is not found, the compilation task is executed to compile the target code segment and obtain the compilation product corresponding to the compilation task.
[0140] Based on the compilation artifacts obtained by executing the compilation task, an executable file corresponding to the code to be compiled is generated.
[0141] In an optional implementation, after executing the compilation task to compile the target code segment and obtain the compilation product corresponding to the compilation task, the instructions executed by the processor 41 further include:
[0142] Based on the configuration information of the computer device performing the compilation task, a target compression algorithm is selected from a variety of candidate compression algorithms;
[0143] The compilation product is compressed using the target compression algorithm to obtain the compressed compilation product corresponding to the target code fragment, and the compressed compilation product is cached.
[0144] In one optional implementation, the instructions executed by the processor 41 include caching the compressed compilation output, comprising:
[0145] Determine the hash value of the target code fragment;
[0146] Establish a matching relationship between the hash value corresponding to the target code fragment and the compressed compilation product, and cache the matching relationship and the compressed compilation product;
[0147] The process of finding the cached compressed compilation artifact corresponding to the target code fragment includes:
[0148] Determine the hash value of the target code fragment;
[0149] Based on the matching relationship, find the compressed compilation product corresponding to the hash value of the target code fragment.
[0150] In one optional implementation, the instructions executed by the processor 41 include determining a target decompression algorithm that matches the compressed compiled product from a plurality of candidate decompression algorithms, including:
[0151] From the various candidate decompression algorithms, a target decompression algorithm that matches the selected target compression algorithm is determined.
[0152] In one optional implementation, the instructions executed by the processor 41, including the step of selecting a target compression algorithm from a variety of candidate compression algorithms based on the configuration information of the computer device executing the compilation task, include:
[0153] Obtain the runtime configuration requirements corresponding to the various candidate compression algorithms;
[0154] From the various candidate compression algorithms, the compression algorithm whose operation configuration requirements match the configuration information is selected as the target compression algorithm.
[0155] In one optional implementation, the instructions executed by the processor 41, including compiling the target code segment, include:
[0156] Based on the target code fragment and the cached intermediate compilation products, determine the available intermediate products among the intermediate compilation products;
[0157] Based on the available intermediate products, the target code fragment is incrementally compiled;
[0158] If no usable intermediate products are found in the compilation intermediate products, then the target code segment is fully compiled.
[0159] This disclosure also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, performs the steps of the compilation method described in the above method embodiments. The storage medium can be a volatile or non-volatile computer-readable storage medium.
[0160] This disclosure also provides a computer program product carrying program code. The program code includes instructions that can be used to execute the steps of the compilation method described in the above method embodiments. For details, please refer to the above method embodiments, which will not be repeated here.
[0161] The aforementioned computer program product can be implemented through hardware, software, or a combination thereof. In one optional embodiment, the computer program product is specifically embodied in a computer storage medium; in another optional embodiment, the computer program product is specifically embodied in a software product, such as a software development kit (SDK), etc.
[0162] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working processes of the systems and devices described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here. In the several embodiments provided in this disclosure, it should be understood that the disclosed systems, devices, and methods can be implemented in other ways. The device embodiments described above are merely illustrative. For example, the division of units is only a logical functional division; in actual implementation, there may be other division methods. Furthermore, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Another point is that the displayed or discussed mutual coupling or direct coupling or communication connection may be through some communication interfaces; the indirect coupling or communication connection of devices or units may be electrical, mechanical, or other forms.
[0163] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0164] In addition, the functional units in the various embodiments of this disclosure can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.
[0165] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a processor-executable, non-volatile, computer-readable storage medium. Based on this understanding, the technical solution of this disclosure, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this disclosure. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0166] Finally, it should be noted that the above-described embodiments are merely specific implementations of this disclosure, used to illustrate the technical solutions of this disclosure, and not to limit it. The protection scope of this disclosure is not limited thereto. Although this disclosure has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments, or make equivalent substitutions for some of the technical features, within the scope of the technology disclosed in this disclosure. Such modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this disclosure, and should all be covered within the protection scope of this disclosure. Therefore, the protection scope of this disclosure should be determined by the protection scope of the claims.
Claims
1. A compilation method, characterized in that, include: Obtain the code to be compiled, and generate multiple compilation tasks corresponding to the code to be compiled, wherein the compilation tasks have execution priorities; For any compilation task, before starting the execution of the compilation task, determine the target code segment corresponding to the compilation task; Locate the cached compressed compilation product corresponding to the target code fragment. If the compressed compilation product is successfully found, determine the target decompression algorithm that matches the compressed compilation product from a variety of candidate decompression algorithms. Different compressed compilation products correspond to different target decompression algorithms. The compressed compilation product is decompressed using the target decompression algorithm to obtain the decompressed compilation product corresponding to the compilation task, wherein the different compressed compilation products are decompressed using the different target decompression algorithms; Based on the obtained decompressed compilation product, an executable file corresponding to the code to be compiled is generated.
2. The method according to claim 1, characterized in that, The method further includes: If the cached compressed compilation product is not found, the compilation task is executed to compile the target code segment and obtain the compilation product corresponding to the compilation task. Based on the compilation artifacts obtained by executing the compilation task, an executable file corresponding to the code to be compiled is generated.
3. The method according to claim 2, characterized in that, After executing the compilation task to compile the target code segment and obtain the compilation product corresponding to the compilation task, the method further includes: Based on the configuration information of the computer device performing the compilation task, a target compression algorithm is selected from a variety of candidate compression algorithms; The compilation product is compressed using the target compression algorithm to obtain the compressed compilation product corresponding to the target code fragment, and the compressed compilation product is cached.
4. The method according to claim 3, characterized in that, Cache the compressed compilation output, including: Determine the hash value of the target code fragment; Establish a matching relationship between the hash value corresponding to the target code fragment and the compressed compilation product, and cache the matching relationship and the compressed compilation product; The process of finding the cached compressed compilation artifact corresponding to the target code fragment includes: Determine the hash value of the target code fragment; Based on the matching relationship, find the compressed compilation product corresponding to the hash value of the target code fragment.
5. The method according to claim 3, characterized in that, Determining a target decompression algorithm that matches the compressed compiled output from a variety of candidate decompression algorithms includes: From the various candidate decompression algorithms, a target decompression algorithm that matches the selected target compression algorithm is determined.
6. The method according to claim 3, characterized in that, The selection of a target compression algorithm from a variety of candidate compression algorithms is based on the configuration information of the computer device performing the compilation task, including: Obtain the runtime configuration requirements corresponding to the various candidate compression algorithms; From the various candidate compression algorithms, the compression algorithm whose operation configuration requirements match the configuration information is selected as the target compression algorithm.
7. The method according to claim 2, characterized in that, The compilation of the target code fragment includes: Based on the target code fragment and the cached intermediate compilation products, determine the available intermediate products among the intermediate compilation products; Based on the available intermediate products, the target code fragment is incrementally compiled; If no usable intermediate products are found in the compilation intermediate products, then the target code segment is fully compiled.
8. A compiler apparatus, characterized in that, include: The acquisition module is used to acquire the code to be compiled and generate multiple compilation tasks corresponding to the code to be compiled, wherein the compilation tasks have execution priorities. The determination module is used to determine the target code segment corresponding to any compilation task before starting the execution of the compilation task; The query module is used to find the cached compressed compilation product corresponding to the target code fragment. If the compressed compilation product is successfully found, the target decompression algorithm that matches the compressed compilation product is determined from a variety of candidate decompression algorithms. Different compressed compilation products correspond to different target decompression algorithms. The decompression module is used to decompress the compressed compilation product using the target decompression algorithm to obtain the decompressed compilation product corresponding to the compilation task, wherein the different compressed compilation products are decompressed using the different target decompression algorithms; The compilation module is used to generate an executable file corresponding to the code to be compiled based on the obtained decompressed compilation product.
9. An electronic device, characterized in that, include: The device includes a processor, a memory, and a bus. The memory stores machine-readable instructions executable by the processor. When the electronic device is running, the processor communicates with the memory via the bus. When the machine-readable instructions are executed by the processor, the steps of the compilation method as described in any one of claims 1 to 7 are performed.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, performs the steps of the compilation method as described in any one of claims 1 to 7.
Citation Information
Patent Citations
Code compiling method, host computer and system
CN102193812A
A data storage method and device
CN109445719A
Internet of Things application online compiling method based on multi-user cache
CN111176654A
File compiling method and device, equipment and storage medium
CN112783508A