File processing method and device, electronic equipment and medium

By analyzing inline cache information in JavaScript code at runtime, extracting the type information of the target object and compiling it, the problems of increased development workload and low operation efficiency caused by relying on type annotation systems in the existing technology are solved, and more efficient program operation is achieved.

CN119883357APending Publication Date: 2025-04-25ZEBRED NETWORK TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411954373.2
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-26
Publication Date
2025-04-25

AI Technical Summary

Technical Problem

When the existing technology improves the running efficiency of JavaScript code, it relies heavily on the type annotation system, resulting in additional development workload and affects the running efficiency of files.

Method used

By analyzing the inline cache information of each object in the source file at runtime, extracting the type information of the target object, and representing it in the form of a hidden class, the source file is then compiled and processed to generate an optimized target file.

Benefits of technology

No additional development work is required, and the operation efficiency of programs written in dynamic languages ​​can be effectively improved and the overhead of querying attributes during runtime can be reduced.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119883357A_ABST
    Figure CN119883357A_ABST
Patent Text Reader

Abstract

The invention provides a file processing method and device, electronic equipment and a medium, and relates to the technical field of computers. The method comprises the steps of obtaining a source file; wherein the source file is a program file written based on a dynamic language; generating inline cache information of each object in the source file, and extracting type information of a target object from the inline cache information of all the objects; wherein the target object is an object with a fixed position in the memory of the virtual machine, and the type information is expressed in a hidden class form; and according to the type information of the target object, compiling the source file to obtain a target file. According to the mode, the file operation efficiency is improved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a file processing method, device, electronic device and medium. Background Art

[0002] Static languages ​​(i.e. statically typed languages) are languages ​​in which the data type of a variable can be determined at compile time. Most statically typed languages ​​require that the data type must be declared before using the variable. Examples include C++, Java, and C#. Unlike statically typed languages, dynamic languages ​​(i.e. dynamically typed languages) determine the data type at runtime. The type of a variable does not need to be declared before use. Usually, the type of the variable is the type of the object being assigned. Examples include Python, JavaScript, and Ruby. For dynamically typed languages, a series of operations such as type judgment, parsing the specific attributes to be accessed based on the actual parameter type, and the specific functions to be called all occur during runtime, which makes programs written in dynamically typed languages ​​run slower and reduces the user experience.

[0003] To improve operating efficiency, relevant technologies solve the problem of unclear data type information in JavaScript code during compilation by introducing intermediate files with annotation information. Based on pre-generated hidden classes, source files are optimized to avoid the overhead of adding attributes to create hidden classes and extending object layout at runtime, thereby improving operating efficiency.

[0004] However, the related technology requires adding annotation information to the data type of the JavaScript code, and converting an intermediate file with annotation information by introducing a type annotation system to annotate the compilation. Therefore, this method is heavily dependent on the type annotation system, and requires additional development work for the annotation type. Summary of the invention

[0005] The present application provides a file processing method, device, electronic device and medium to solve the problem of low file operation efficiency caused by the need for additional development workload in related technologies.

[0006] According to a first aspect of the present application, a file processing method is provided, comprising:

[0007] Obtain a source file; wherein the source file is a program file written based on a dynamic language;

[0008] Generate inline cache information of each object in the source file, and extract type information of the target object from the inline cache information of all the objects; wherein the target object is an object with a fixed position in the memory of the virtual machine, and the type information is represented in the form of a hidden class;

[0009] The source file is compiled according to the type information of the target object to obtain a target file.

[0010] Optionally, generating inline cache information of each object in the source file includes:

[0011] Compiling the source file to generate a corresponding bytecode file;

[0012] The bytecode file is interpreted and executed to obtain inline cache information of each object.

[0013] Optionally, extracting the type information of the target object from the inline cache information of all the objects includes:

[0014] Identify the object type in the inline cache information of all the objects, and use the object of the preset type as the target object; wherein the target object is a built-in object, and the built-in object includes a basic object and a utility function formulated based on the dynamic language;

[0015] The location information of the target object is searched from a preset built-in object set, and the location information of the target object is used as the type information of the target object.

[0016] Optionally, after extracting the type information of the target object from the inline cache information of all the objects, the method further includes:

[0017] A mapping table between the calling point where the object is located and the inline cache information is created, and the mapping table is stored.

[0018] Optionally, compiling the source file according to the type information of the target object to obtain the target file includes:

[0019] Loading the type information of the target object to a corresponding node of the target object in an abstract syntax tree; wherein the abstract syntax tree is generated according to the source file;

[0020] After the loading is completed, according to the type information of the target object, the target object is stored in a hidden class;

[0021] The source file is compiled according to the target function to obtain the target file.

[0022] Optionally, compiling the source file according to the target function to obtain the target file includes:

[0023] Obtaining a currently running function object in the abstract syntax tree, and determining whether the function object carries corresponding type information;

[0024] In the case where the function object carries the corresponding type information, determining the function object as a target object, and translating a first program code corresponding to the target object in the source file into a first channel code by using the type information of the target object;

[0025] A target file is constructed according to the second program code corresponding to all target objects; wherein the second program code is the first channel code or the second channel code.

[0026] Optionally, after determining whether the function object carries corresponding type information, the method further includes:

[0027] In a case where the function object does not carry the corresponding type information, the first program code corresponding to the target object in the source file is translated into the second channel code; wherein the second channel code is different from the first channel code.

[0028] According to a second aspect of the present application, there is provided a file processing device, comprising:

[0029] An acquisition module, used for acquiring a source file; wherein the source file is a program file written based on a dynamic language;

[0030] generating an extraction module, which is used to generate inline cache information of each object in the source file, and extract type information of the target object from the inline cache information of all the objects; wherein the target object is an object with a fixed position in the memory of the virtual machine, and the type information is represented in the form of a hidden class;

[0031] The compiling processing module is used to compile the source file according to the type information of the target object to obtain the target file.

[0032] According to a third aspect of the present application, there is provided an electronic device, comprising: at least one processor and a memory;

[0033] The memory stores computer-executable instructions;

[0034] The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor executes the file processing method as described in the first aspect above.

[0035] According to a fourth aspect of the present application, a computer-readable storage medium is provided, wherein the computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, they are used to implement the file processing method described in the first aspect above.

[0036] According to a fifth aspect of the present application, a computer program product is provided, comprising a computer program, which implements the file processing method described in the first aspect when executed by a processor.

[0037] A file processing method provided by the present application includes: obtaining a source file; wherein the source file is a program file written in a dynamic language; generating inline cache information of each object in the source file, and extracting type information of a target object from the inline cache information of all the objects; wherein the target object is an object with a fixed position in a virtual machine memory, and the type information is represented in the form of a hidden class; and compiling the source file according to the type information of the target object to obtain a target file.

[0038] In order to improve the operating efficiency of source files written in dynamic languages, the present application proposes that the inline cache information of each object in the source file can be analyzed at runtime, and then the type information of the target object can be extracted. The type information of the target object is context-independent and reusable type information. Therefore, the present application can obtain the inline cache information of each object in advance, and then optimize the source file based on the extracted type information to avoid the overhead of querying attributes at runtime, thereby improving operating efficiency.

[0039] It should be understood that the content described in this section is not intended to identify the key or important features of the embodiments of the present application, nor is it intended to limit the scope of the present application. Other features of the present application will become easily understood through the following description. BRIEF DESCRIPTION OF THE DRAWINGS

[0040] The accompanying drawings, which are incorporated in and constitute a part of this specification, illustrate embodiments consistent with the present application and, together with the description, serve to explain the principles of the present application.

[0041] Figure 1 A schematic diagram of a code optimization method provided for related technologies;

[0042] Figure 2 A flowchart of a file processing method provided in an embodiment of the present application;

[0043] Figure 3 for Figure 2 Schematic diagram of the process of step S20;

[0044] Figure 4 A schematic diagram of a flow chart of a reusable type information extraction method provided in an embodiment of the present application;

[0045] Figure 5 for Figure 2 Schematic diagram of the process of step S30;

[0046] Figure 6A flowchart of a code optimization compilation method provided in an embodiment of the present application;

[0047] Figure 7 A schematic flow chart of generating optimized code based on hidden classes according to an embodiment of the present application;

[0048] Figure 8 A schematic diagram of the structure of a file processing device provided in an embodiment of the present application;

[0049] Fig. 9 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application.

[0050] The above drawings have shown clear embodiments of the present application, which will be described in more detail later. These drawings and text descriptions are not intended to limit the scope of the present application in any way, but to illustrate the concept of the present application to those skilled in the art by referring to specific embodiments. DETAILED DESCRIPTION

[0051] Exemplary embodiments will be described in detail herein, examples of which are shown in the accompanying drawings. When the following description refers to the drawings, the same numbers in different drawings represent the same or similar elements unless otherwise indicated. The implementations described in the following exemplary embodiments do not represent all implementations consistent with the present application. Instead, they are merely examples of devices and methods consistent with some aspects of the present application as detailed in the appended claims.

[0052] Figure 1 A schematic diagram of a code optimization method provided for related technologies. Figure 1 As shown, the method includes the following steps: obtaining a source file; obtaining an intermediate file with annotation information based on the source file; obtaining an abstract syntax tree based on the program code in the intermediate file, analyzing the annotation information to obtain type description information of the corresponding program code, and attaching the type description information to the node corresponding to the program code in the abstract syntax tree; traversing the abstract syntax tree, based on the type description information of the node, obtaining the attributes and type information of the object, thereby generating a hidden class, and attaching it to the node of the abstract syntax tree corresponding to the object; generating optimized code based on the hidden class on the node of the abstract syntax tree.

[0053] This method solves the problem of unclear object type information at compile time by introducing intermediate files, generates hidden classes by obtaining object layout information in advance, and optimizes source files based on pre-generated hidden classes to avoid the overhead of adding attributes to create hidden classes and extending object layout at runtime, thereby improving operating efficiency.

[0054] However, the related technology requires additional annotation information for the data type of the JS code, by introducing a type annotation system or using a type system based on TypeScript to annotate and compile the source file with the additional annotation information. It can be seen that the related technology is heavily dependent on the type annotation system, and additional development work is required for annotating types. In addition, the accuracy of the annotation seriously affects the quality of the optimized code generated subsequently, and it is even easy to cause inefficiency that decreases instead of increases.

[0055] In order to solve the above technical problems, the overall inventive concept of the present application is to provide a method applied in the computer field to improve the efficiency of file operation.

[0056] The technical solution of the present application and how the technical solution of the present application solves the above-mentioned technical problems are described in detail below with specific embodiments. The following specific embodiments can be combined with each other, and the same or similar concepts or processes may not be repeated in some embodiments. The embodiments of the present application will be described below in conjunction with the accompanying drawings.

[0057] Embodiment 1:

[0058] In the related art, dynamic type languages ​​introduce the concept of hidden classes to describe the type information and memory layout of objects, but the relevant data of hidden classes are cleared each time they are executed, so that the startup time of programs developed in dynamic type languages ​​cannot be optimized using the relevant information of hidden classes. Therefore, the present application proposes a file processing method, which optimizes programs written in dynamic type languages ​​by extracting context-independent and reusable type information from inline cache information. Applying the method of this embodiment to the system baseline can improve the cold start time of applications by about 10%.

[0059] Figure 2 A flowchart of a file processing method provided in an embodiment of the present application is shown below. Figure 2 As shown, the method of this embodiment includes:

[0060] S10, obtaining a source file; wherein the source file is a program file written in a dynamic language. Exemplarily, the dynamic language may be JavaScript, Python, Ruby, etc. wherein JavaScript is a dynamic language used for web page programming, and JS is the abbreviation of JavaScript language.

[0061] This embodiment is described as follows using JavaScript as an example, and in the embodiment of the present application, the virtual machine used in the subsequent process is analyzed as follows using the JS virtual machine as an example. The JS virtual machine is a JavaScript language execution engine for compiling and running JavaScript source code.

[0062] S20. Generate inline cache information of each object in the source file, and extract type information of the target object from the inline cache information of all objects; wherein the target object is an object with a fixed position in the virtual machine memory, and the type information is represented in the form of a hidden class.

[0063] Among them, everything in the JavaScript language is an object, and inline caching (IC) information is also called IC information, IC-related information, object memory layout information, object layout information, memory layout information, etc., where inline caching refers to speeding up runtime method binding by remembering the results of previous method queries directly at the call point. In addition, the type information of the target object is context-independent, reusable type information in the inline cache information (i.e., the following reusable data, reusable type information, etc.), which can be understood as reusable hidden class-related type information.

[0064] The above-mentioned context-independent means that it is not bound to any fixed memory address. The above-mentioned reusability refers to the invariants (i.e., target objects) existing in the IC-related information created by the dynamic type language program at the beginning of each execution; and the variables existing in the IC-related information are cleared before the end of execution, which results in the re-creation of objects for each execution, and the memory addresses of the objects are usually different. Hidden Class (HC) is a data structure used to describe the dynamic object layout of a dynamic type language. It should be noted that this step is described in detail in Example 2 of the embodiment of the present application and will not be repeated here.

[0065] S30. Compile the source file according to the type information of the target object to obtain the target file.

[0066] In the embodiment of the present application, the purpose of the compilation process is to optimize the code in the source file. Generally speaking, the file processing method provided by the present application optimizes the program written in the dynamic type language by reusing the type information related to the hidden class in step S30, thereby improving the execution efficiency of the program written in the dynamic type language. It should be noted that this step is described in detail in Example 3 of this embodiment, and will not be repeated here.

[0067] In the above process, the embodiment of the present application fully automatically extracts and utilizes type information, does not require developers to pay additional workload, and does not rely on the quality of external annotation types, so as to improve the operating efficiency of programs that can be executed correctly.

[0068] In summary, in order to improve the operating efficiency of source files written in dynamic languages, the file processing method proposed in the embodiment of the present application can analyze object layout information at runtime and extract context-independent and reusable type information therein, so that the object layout information can be known in advance, and the source file can be optimized based on the pre-generated IC information to avoid the overhead of querying attributes at runtime, thereby improving operating efficiency.

[0069] It should be noted that this embodiment mainly involves dynamic type languages, such as JavaScript, Smalltalk, Self, Python, Ruby, etc. This embodiment is currently implemented using JavaScript, and replacing JavaScript with any other dynamic type language can achieve the same effect as the embodiment of the present application.

[0070] Based on the above embodiments, the technical solution of the present application is described in more detail below in combination with several specific embodiments.

[0071] Embodiment 2:

[0072] Figure 3 for Figure 2 The flowchart of step S20 in FIG. Figure 2 Based on the embodiment shown, this embodiment focuses on Figure 2 The S20 in the figure is refined. Figure 3 As shown, in step S20, inline cache information of each object in the source file is generated, including:

[0073] S201, compile the source file to generate a corresponding bytecode file.

[0074] The bytecode file is a collection of bytecodes. This embodiment compiles the source file to obtain a bytecode file represented in binary format. This embodiment can execute the program by parsing the bytecode during runtime.

[0075] S202: interpret and execute the bytecode file to obtain inline cache information of each object.

[0076] This step is used to collect and fill in IC information. The specific analysis is as follows: dynamic languages ​​determine object types at runtime, and actual access to properties and calling of functions are dynamically queried at runtime. This embodiment collects runtime type information and property / method query results, and in the subsequent execution process, reduces the consumption of dynamic queries and directly uses the previously collected information.

[0077] The embodiments of the present application provide technical support for the subsequent fully automatic extraction and use of type information, so that the operating efficiency of programs that can be executed correctly can be improved without requiring developers to pay additional workload and without relying on the quality of external annotation types.

[0078] In one possible implementation, Figure 3 As shown, in step S20, the type information of the target object is extracted from the inline cache information of all objects, including:

[0079] S203, identifying the object types in the inline cache information of all objects, and taking the object of the preset type as the target object; wherein the target object is a built-in object, and the built-in object includes basic objects and utility functions formulated based on a dynamic language.

[0080] S204: Search for location information of the target object from a preset built-in object set, and use the location information of the target object as type information of the target object.

[0081] It should be understood that the preset built-in object set is a set of basic objects and utility functions established by the dynamic language standard. The purpose of step S203 to step S204 is to extract context-independent and reusable data in the IC information. The specific analysis is as follows:

[0082] Since objects of dynamic languages ​​are created at runtime, the addresses at each creation are not fixed, and the addresses of previously created objects cannot be reused after being collected. However, the distribution of the basic objects and built-in objects of utility functions established by the dynamic language standard in the virtual machine memory is fixed. Therefore, based on this, this embodiment can classify and parse the scalar types and object types in the IC information. The scalar types include but are not limited to: integer type scalar int, integer type scalar long, single-precision floating point type scalar float, double-precision floating point type scalar double, Boolean type scalar Boolean, etc. Find the location information of the object type in the built-in object collection, and record the location information as reusable data.

[0083] In the above process, the embodiment of the present application fully automatically extracts type information and utilizes it in subsequent processes. It does not require developers to pay additional workload and does not rely on the quality of external annotation types. It can improve the operating efficiency of programs that can be executed correctly.

[0084] In a possible implementation, after extracting the type information of the target object from the inline cache information of all objects, the method further includes:

[0085] S205: Create a mapping table between the call site where the object is located and the inline cache information, and store the mapping table. The call site is used to indicate the location where the function or process occurs, and usually corresponds to the line number of the source code.

[0086] This embodiment constructs a mapping table of call sites and reusable IC information by executing step S205. When the type information of the call site changes, the context-independent and reusable type information in the IC information is re-extracted, and the IC information of the call site is updated. When the program startup phase is completed, the mapping table is recorded to the disk for use in subsequent program startups.

[0087] By executing the operations in the above steps, the embodiment of the present application can analyze the context-related feature information in the dynamic type language, extract the context-independent and reusable type information therein, and use it in the source file compilation process to generate optimized code, thereby improving the program running efficiency.

[0088] The embodiment of the present application mainly includes a reusable type information extraction process and an optimized compilation process. In embodiment 2, the reusable type information extraction process is exemplarily described.

[0089] Figure 4 A schematic diagram of a flow chart of a reusable type information extraction method provided in an embodiment of the present application. Figure 4 As shown, the reusable type information extraction method includes the following steps:

[0090] S110, obtaining source files. The specific implementation of step S110 can refer to step S10 in embodiment 1, and this embodiment of the present application will not be described in detail.

[0091] S120, generating a bytecode file based on the source file. The specific implementation of step S120 can refer to the above step S201, and this embodiment of the application will not be repeated here.

[0092] S130, collecting and filling IC information. The specific implementation of step S130 can refer to the above step S202, and this embodiment of the application will not be repeated here.

[0093] S140, extracting context-independent reusable data. Reusable data is also called reusable IC data. The specific implementation of step S140 can refer to the above steps S203-S204, and this embodiment of the application will not be repeated here.

[0094] S150, create a mapping table and save it to disk. It should be understood that the mapping table is used to record the mapping relationship between the call site and the context-independent reusable data in the IC information. The specific implementation of step S150 can refer to the above step S205, and the embodiment of the present application will not be repeated here.

[0095] In the above process, the embodiment of the present application fully automatically extracts type information and utilizes it in subsequent processes. It does not require developers to pay additional workload and does not rely on the quality of external annotation types. It can improve the operating efficiency of programs that can be executed correctly.

[0096] Embodiment 3:

[0097] Figure 5 for Figure 2 The flowchart of step S30 in the above Figure 2 Based on the embodiment shown, this embodiment describes the specific implementation of S30 in more detail. Figure 5 As shown, step S30, compile the source file according to the type information of the target object to obtain the target file, including:

[0098] S301. Load type information of a target object to a corresponding node of the target object in an abstract syntax tree; wherein the abstract syntax tree is generated according to a source file.

[0099] After obtaining the reusable type information, this embodiment attaches the reusable type information to the corresponding node of the corresponding program code in the abstract syntax tree.

[0100] S302: After loading is completed, store the target object in a hidden class according to the type information of the target object.

[0101] This embodiment analyzes the type information of the target object and installs IC information such as hidden classes. That is, this embodiment can find corresponding objects in the built-in object collection according to the location information of the reusable IC information, and then install these objects into the data structure of the IC information in advance.

[0102] S303: Compile the source file according to the target function to obtain the target file.

[0103] This embodiment generates efficient optimized code based on the function with IC information such as hidden class. The specific steps of generating efficient optimized code are in steps S331 to S334, and Figure 7 The steps S310 to S340 are described in detail.

[0104] By executing the operations in the above steps, the embodiment of the present application can extract context-independent and reusable type information and use it to generate optimized code during the source file compilation process to improve the program running efficiency.

[0105] The embodiments of the present application mainly include a reusable type information extraction process and an optimized compilation process. In Embodiment 3, an exemplary description of the optimized compilation process is given.

[0106] Figure 6 A flowchart of a code optimization compilation method provided in an embodiment of the present application. The code optimization compilation method comprises the following steps:

[0107] S210, obtaining source files. The specific implementation of step S210 can refer to step S10 in embodiment 1, and this embodiment of the present application will not be described in detail.

[0108] S220, generating a bytecode file based on the source file. The specific implementation of step S220 can refer to step S201 in embodiment 2, and this embodiment of the present application will not be described in detail.

[0109] S230, loading reusable data. The specific description of step S230 is as described in the above step S301, which will not be repeated here.

[0110] S240, install hidden classes. In this step, the embodiment of the present application installs IC data such as HC. The specific description of step S240 is shown in the above step S302, which will not be repeated here.

[0111] S250, generating optimized code. The specific description of step S250 is as described in the above step S303, which will not be repeated here.

[0112] In the above process, the embodiment of the present application fully automatically extracts and utilizes type information, does not require developers to pay additional workload, and does not rely on the quality of external annotation types, so as to improve the operating efficiency of programs that can be executed correctly.

[0113] In a possible implementation, step S303, compiling the source file according to the target function to obtain the target file, includes:

[0114] S331. Obtain the currently running function object in the abstract syntax tree, and determine whether the function object carries corresponding type information.

[0115] S332: In the case where the function object carries corresponding type information, the function object is determined as a target object, and the first program code corresponding to the target object in the source file is translated into a first channel code by using the type information of the target object.

[0116] It should be understood that the first channel code may refer to the IC-FAST-PATH code, or called the optimization code. This embodiment explains the IC-FAST-PATH code as follows: the current hidden class is consistent with the generated hidden class, indicating that the generated hidden class can describe the current object layout, and the read and write operations on the object can be completed quickly.

[0117] S333: Construct a target file according to the second program codes corresponding to all target objects.

[0118] It should be understood that the second program code is the first channel code or the second channel code.

[0119] The embodiment of the present application describes the entire compilation process in detail. Through the above process, the embodiment of the present application can extract context-independent and reusable type information and use it in the source file compilation process to generate optimized code, thereby improving the program running efficiency.

[0120] In a possible implementation, after determining whether the function object carries corresponding type information, the method further includes:

[0121] S334. When the function object does not carry corresponding type information, translate the first program code corresponding to the target object in the source file into a second channel code; wherein the second channel code is different from the first channel code.

[0122] It should be understood that the second channel code may refer to the IC-SLOW-PATH code. This embodiment explains the IC-SLOW-PATH code as follows: when the current hidden class and the generated hidden class are inconsistent, it is necessary to query the object attributes, obtain the memory location information of the attributes, and regenerate the hidden class to describe the current object layout.

[0123] The embodiment of the present application uses IC-SLOW-PATH and IC-FAST-PATH to refer to the slow path and the fast path. The slow path refers to the absence of IC optimization information such as hidden classes at runtime or the hidden classes stored in the IC information are inconsistent with the objects encountered at runtime. In this case, it is necessary to execute step S130 to generate a new hidden class to describe the current object layout. The embodiment can also obtain the index of the attribute to be accessed in the object layout by querying the newly generated hidden class, and then obtain the memory location information of the attribute to be accessed before the access operation can be performed. The fast path refers to the hidden class stored in the IC information that can describe the object layout that appears at runtime, so there is no need to query the index of the attribute to be accessed in the hidden class in the object layout.

[0124] This embodiment enables the embodiment of the present application to utilize context-independent, reusable type information during source file compilation after extraction. If the function object does not carry the corresponding type information, IC-SLOW-PATH code is generated, and then IC optimization information carrying hidden classes is collected, ultimately ensuring the generation of optimized code and improving program running efficiency.

[0125] Figure 7 The following is a schematic flow chart of generating optimized code based on hidden classes according to an embodiment of the present application. Figure 7 As shown, the embodiment of the present application includes the following steps:

[0126] S310, obtaining a running function.

[0127] S320, determine whether it contains a hidden class; if so, execute step S330; if not, execute step S340.

[0128] S330. Generate IC-FAST-PATH code.

[0129] S340, generate IC-SLOW-PATH code. After executing step S340, continue to execute step S130 until the hidden class is included in the running function.

[0130] It should be understood that the specific implementation method of step S310 to step S340 is consistent with the implementation method of the above-mentioned step S331 to step S334, and will not be repeated here.

[0131] This embodiment obtains the currently running function object in step S310; and before the function object is executed, jumps to step S320 to determine whether IC optimization information is attached. If the currently running function object is attached with optimization information containing hidden classes, this embodiment can execute step S330, that is, use the hidden class information to translate into efficient optimized code that can be executed using the hidden class, for example, it can be translated into IC-FAST-PATH code. If the currently running function object does not carry optimization information containing hidden classes, step S340 is executed to translate into non-optimized code that obtains hidden classes at runtime and executes based on the obtained hidden classes, for example, it can be translated into IC-SLOW-PATH code. After the translation is completed, it can jump to step S130 to collect IC optimization information such as hidden classes for generating IC-FAST-PATH code during subsequent execution.

[0132] The embodiment of the present application analyzes and classifies the object types occurring at the call site, extracts and utilizes context-independent and reusable type information, and generates optimized code. The method has the following advantages: the embodiment does not require additional type annotations for the source code, and does not require developers to do additional development work, thereby improving program operation efficiency.

[0133] That is, this embodiment automatically records and reuses the memory layout information of the object, without requiring the developer to do extra work. In addition, this embodiment does not rely on the quality of the external annotation type, and can improve the operating efficiency of the program that can be executed correctly. This method can ensure that the performance is improved by about 10%.

[0134] Embodiment 4:

[0135] Figure 8 This is a schematic diagram of the structure of a file processing device provided in an embodiment of the present application. The device of this embodiment may be in the form of software and / or hardware. Figure 8 As shown, the file processing device provided in this embodiment includes: an acquisition module 81, a generation and extraction module 82 and a compilation and processing module 83. Among them:

[0136] The acquisition module 81 is used to acquire a source file; wherein the source file is a program file written based on a dynamic language.

[0137] The generation and extraction module 82 is used to generate inline cache information of each object in the source file, and extract the type information of the target object from the inline cache information of all objects; wherein the target object is an object with a fixed position in the virtual machine memory, and the type information is represented in the form of a hidden class.

[0138] The compiling module 83 is used to compile the source file according to the type information of the target object to obtain the target file.

[0139] In a possible implementation, the generating and extracting module 82 is further used for:

[0140] Compile the source file to generate the corresponding bytecode file.

[0141] Interpret and execute the bytecode file to obtain the inline cache information of each object.

[0142] In a possible implementation, the generating and extracting module 82 is further used for:

[0143] Identify the object type in the inline cache information of all objects, and take the object whose object type is a preset type as the target object; wherein the target object is a built-in object, and the built-in object includes a basic object and a utility function formulated based on a dynamic language.

[0144] The location information of the target object is searched from a preset built-in object set, and the location information of the target object is used as the type information of the target object.

[0145] In a possible implementation, the file processing device is further used to:

[0146] A mapping table between the call site where the object is located and the inline cache information is created, and the mapping table is stored.

[0147] In a possible implementation, the compiling processing module 83 is further used to:

[0148] Load the type information of the target object to the corresponding node of the target object in the abstract syntax tree; wherein the abstract syntax tree is generated according to the source file.

[0149] After loading is completed, the target object is stored in a hidden class according to the type information of the target object.

[0150] The source file is compiled according to the target function to obtain the target file.

[0151] In a possible implementation, the compiling processing module 83 is further used to:

[0152] Get the currently running function object in the abstract syntax tree and determine whether the function object carries the corresponding type information.

[0153] In the case where the function object carries corresponding type information, the function object is determined as a target object, and the first program code corresponding to the target object in the source file is translated into a first channel code using the type information of the target object.

[0154] A target file is constructed according to the second program code corresponding to all target objects; the second program code is the first channel code or the second channel code.

[0155] In a possible implementation, the compiling processing module 83 is further used to:

[0156] In the case where the function object does not carry corresponding type information, the first program code corresponding to the target object in the source file is translated into a second channel code; wherein the second channel code is different from the first channel code.

[0157] The file processing device provided in this embodiment can be used to execute the file processing method provided by any of the above method embodiments. Its implementation principles and technical effects are similar and will not be described in detail here.

[0158] It should be noted that the user information and data involved in this application (including but not limited to data used for analysis, stored data, displayed data, etc.) are all information and data authorized by the user or fully authorized by all parties, and the collection, use and processing of relevant data must comply with the relevant laws, regulations and standards of relevant countries and regions, and provide corresponding operation entrances for users to choose to authorize or refuse.

[0159] That is to say, in the technical solution of this application, the collection, storage, use, processing, transmission, provision and disclosure of user personal information involved are in compliance with the relevant laws and regulations and do not violate public order and good morals.

[0160] According to an embodiment of the present application, the present application also provides an electronic device and a readable storage medium.

[0161] Fig. 9 A schematic diagram of the structure of an electronic device provided in an embodiment of the present application. The electronic device includes a receiver 90, a transmitter 91, at least one processor 92 and a memory 93. The electronic device composed of the above components can be used to implement the above-mentioned several specific embodiments of the present application, which will not be repeated here.

[0162] The embodiment of the present application further provides a computer-readable storage medium, in which computer-executable instructions are stored. When a processor executes the computer-executable instructions, each step of the method in the above embodiment is implemented.

[0163] An embodiment of the present application also provides a computer program product, including a computer program, which implements each step of the method in the above embodiment when executed by a processor.

[0164] Various embodiments of the systems and techniques described above in the present application can be implemented in digital electronic circuit systems, integrated circuit systems, field programmable gate arrays (FPGAs), application specific integrated circuits (ASICs), application specific standard products (ASSPs), systems on chips (SOCs), load programmable logic devices (CPLDs), computer hardware, firmware, software, and / or combinations thereof. These various embodiments may include: being implemented in one or more computer programs, which may be executed and / or interpreted on a programmable system including at least one programmable processor, which may be a dedicated or general programmable processor, which may receive data and instructions from a storage system, at least one input device, and at least one output device, and transmit data and instructions to the storage system, the at least one input device, and the at least one output device.

[0165] The program code for implementing the method of the present application can be written in any combination of one or more programming languages. These program codes can be provided to a processor or controller of a general-purpose computer, a special-purpose computer, or other programmable data processing device, so that the program code, when executed by the processor or controller, enables the functions / operations specified in the flow chart and / or block diagram to be implemented. The program code can be executed entirely on the machine, partially on the machine, partially on the machine as a stand-alone software package and partially on a remote machine, or entirely on a remote machine or electronic device.

[0166] In the context of the present application, a computer-readable storage medium may be a tangible medium that may contain or store a program for use by or in conjunction with an instruction execution system, device, or equipment. A computer-readable storage medium may be a machine-readable signal medium or a machine-readable storage medium. A computer-readable storage medium may include, but is not limited to, an electronic, magnetic, optical, electromagnetic, infrared, or semiconductor system, device, or device, or any suitable combination of the foregoing. A more specific example of a computer-readable storage medium may include an electrical connection based on one or more communication lines, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.

[0167] To provide interaction with a user, the systems and techniques described herein can be implemented on a computer having: a display device (e.g., a CRT (cathode ray tube) or LCD (liquid crystal display) monitor) for displaying information to the user; and a keyboard and pointing device (e.g., a mouse or trackball) through which the user can provide input to the computer. Other types of devices can also be used to provide interaction with the user; for example, the feedback provided to the user can be any form of sensory feedback (e.g., visual feedback, auditory feedback, or tactile feedback); and input from the user can be received in any form (including acoustic input, voice input, or tactile input).

[0168] The systems and techniques described herein may be implemented in a computing system that includes back-end components (e.g., as a data electronic device), or a computing system that includes middleware components (e.g., an application electronic device), or a computing system that includes front-end components (e.g., a user computer with a graphical user interface or a web browser through which a user can interact with implementations of the systems and techniques described herein), or a computing system that includes any combination of such back-end components, middleware components, or front-end components. The components of the system may be interconnected by any form or medium of digital data communication (e.g., a communication network). Examples of communication networks include: a local area network (LAN), a wide area network (WAN), and the Internet.

[0169] It should be understood that the various forms of processes shown above can be used to reorder, add or delete steps. For example, the steps disclosed in this application can be performed in parallel, sequentially or in different orders, as long as the desired results of the technical solution disclosed in this application can be achieved, and this document does not limit this.

[0170] The above specific implementations do not constitute a limitation on the protection scope of this application. It should be understood by those skilled in the art that various modifications, combinations, sub-combinations and substitutions can be made according to design requirements and other factors. Any modification, equivalent substitution and improvement made within the principles of this application should be included in the protection scope of this application.

Claims

1. A file processing method, characterized in that: include: Obtain a source file; wherein the source file is a program file written based on a dynamic language; Generate inline cache information of each object in the source file, and extract type information of the target object from the inline cache information of all the objects; wherein the target object is an object with a fixed position in the memory of the virtual machine, and the type information is represented in the form of a hidden class; The source file is compiled according to the type information of the target object to obtain a target file.

2. The method according to claim 1, characterized in that The generating of inline cache information of each object in the source file includes: Compiling the source file to generate a corresponding bytecode file; The bytecode file is interpreted and executed to obtain inline cache information of each object.

3. The method according to claim 1, characterized in that The step of extracting the type information of the target object from the inline cache information of all the objects includes: Identify the object type in the inline cache information of all the objects, and use the object of the preset type as the target object; wherein the target object is a built-in object, and the built-in object includes a basic object and a utility function formulated based on the dynamic language; The location information of the target object is searched from a preset built-in object set, and the location information of the target object is used as the type information of the target object.

4. The method according to any one of claims 1 to 3, characterized in that: After extracting the type information of the target object from the inline cache information of all the objects, the method further includes: A mapping table between the calling point where the object is located and the inline cache information is created, and the mapping table is stored.

5. The method according to claim 1, characterized in that The compiling the source file according to the type information of the target object to obtain the target file includes: Loading the type information of the target object to a corresponding node of the target object in an abstract syntax tree; wherein the abstract syntax tree is generated according to the source file; After the loading is completed, according to the type information of the target object, the target object is stored in a hidden class; The source file is compiled according to the target function to obtain the target file.

6. The method according to claim 5, characterized in that The source file is compiled according to the target function to obtain the target file, including: Obtaining a currently running function object in the abstract syntax tree, and determining whether the function object carries corresponding type information; In the case where the function object carries the corresponding type information, determining the function object as a target object, and translating a first program code corresponding to the target object in the source file into a first channel code by using the type information of the target object; A target file is constructed according to the second program code corresponding to all target objects; wherein the second program code is the first channel code or the second channel code.

7. The method according to claim 6, characterized in that After determining whether the function object carries corresponding type information, the method further includes: In a case where the function object does not carry the corresponding type information, the first program code corresponding to the target object in the source file is translated into the second channel code; wherein the second channel code is different from the first channel code.

8. A file processing device, characterized in that: include: An acquisition module, used for acquiring a source file; wherein the source file is a program file written based on a dynamic language; generating an extraction module, which is used to generate inline cache information of each object in the source file, and extract type information of the target object from the inline cache information of all the objects; wherein the target object is an object with a fixed position in the memory of the virtual machine, and the type information is represented in the form of a hidden class; The compiling processing module is used to compile the source file according to the type information of the target object to obtain the target file.

9. An electronic device, characterized in that: include: at least one processor and memory; The memory stores computer-executable instructions; The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor executes the file processing method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-executable instructions, and when the computer-executable instructions are executed by a processor, they are used to implement the file processing method according to any one of claims 1 to 7.