Small program running method and device, storage medium and electronic equipment
By obtaining the number of nested layers of the first objective function in the applet and delaying processing, the problem of low startup efficiency of applets is solved, and the startup time is shortened and memory optimization is achieved, ensuring efficient execution of functions.
Patent Information
- Application Number
- CN202411173603.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-23
- Publication Date
- 2024-12-17
AI Technical Summary
With the widespread application of mini programs, improving the efficiency of mini programs has become an urgent problem to be solved, and it is difficult for existing technology to effectively shorten the startup time of mini programs.
By obtaining the number of nested layers of the first objective function in the applet, determining its function type. If it is a delayed parsing function type, the function body and parent function will be simplified, and a simplified bytecode object will be generated and added to the delay function , reduce the number of parsed and compiled functions, thereby shortening the startup time.
It achieves the efficiency of mini program startup, reduces memory usage, and ensures the efficiency of function execution.
Smart Images

Figure CN119149043A_ABST
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and more specifically, to a method, device, storage medium and electronic device for running a small program in the field of computer technology. Background Art
[0002] Nowadays, with the continuous development of information technology, applications have developed mini-programs corresponding to various functions in order to enrich the types of functions provided. There is no need to download the applications corresponding to each function. Multiple different types of functions can be used in one application. However, with the widespread application of mini-programs, improving the startup efficiency of mini-programs has become an urgent problem to be solved. Summary of the invention
[0003] The present application provides a method, device, storage medium and electronic device for running a mini-program. The method can shorten the startup time of the mini-program by processing the first target function as a delay function, and reduce the number of functions that need to be parsed and compiled by delaying the delay function, thereby improving the efficiency of the mini-program startup.
[0004] In a first aspect, a method for running a small program is provided, the method comprising:
[0005] For a startup operation of a mini-program, obtaining a nesting level of a first target function in the mini-program, and determining a function type of the first target function based on the nesting level, wherein the first target function is any function in the mini-program;
[0006] If the function type is a delayed parsing function type, simplifying the function body of the first objective function and the parent function corresponding to the first objective function to obtain a second objective function;
[0007] A simplified bytecode object corresponding to the first target function is generated based on the function description information of the first target function, and the simplified bytecode object is added to the second target function to obtain a delay function corresponding to the second target function. The function description information is used to characterize the basic information of the first target function, and the delay function is a function that delays parsing when controlling the startup of the mini program in response to the startup operation.
[0008] Through the above technical scheme, it is possible to obtain the nesting number of the first target function, determine the function type of the first target function based on the nesting number, and when the function type of the first target function is a delayed parsing function type, process the first target function as a delayed function, thereby reducing the number of functions that need to be parsed and compiled by using the delayed function for delayed processing, thereby shortening the startup time of the mini program and improving the efficiency of the mini program startup.
[0009] In conjunction with the first aspect, in some possible implementations, obtaining the number of nesting levels of the first objective function in the mini-program, and determining the function type of the first objective function based on the number of nesting levels includes:
[0010] Obtain a description structure corresponding to the first objective function in the mini-program, determine the number of nesting levels of the first objective function based on a layer number field in the description structure, and compare the number of nesting levels with a preset number of levels;
[0011] The function type of the first objective function is determined based on a comparison result of the nesting number and the preset number of layers.
[0012] In combination with the first aspect and the above implementation manner, in some possible implementation manners, simplifying the function body in the first objective function and the parent function corresponding to the first objective function to obtain the second objective function includes:
[0013] Obtaining a preset bytecode, replacing the bytecode in the function body of the first target function with the preset bytecode, and obtaining a delay mark corresponding to the first target function, wherein the content of the preset bytecode is preset content;
[0014] The delay mark and the preset bytecode are added to the parent function of the first target function to obtain a second target function corresponding to the first target function.
[0015] Through the above technical solution, the first objective function is simplified to obtain a second objective function with shortened initialization time and reduced memory, so as to improve the efficiency of mini-program startup.
[0016] In combination with the first aspect and the foregoing implementation manner, in some possible implementation manners, generating a simplified bytecode object corresponding to the first target function based on the function description information of the first target function, and adding the simplified bytecode object to the second target function includes:
[0017] Generate a simplified bytecode object corresponding to the first target function based on the function description information of the first target function, and add the simplified bytecode object to the second target function;
[0018] Obtain a description field in the function description information, and add the description field to the execution object corresponding to the second target function.
[0019] Through the above technical solution, the second target function can be identified as a function requiring delayed parsing based on the simplified bytecode object and the description field, and it is ensured that the function can be restored.
[0020] In combination with the first aspect and the foregoing implementation manner, in some possible implementation manners, after obtaining the delay function corresponding to the second objective function, the method further includes:
[0021] Starting the mini-program based on the delay function and the start function, wherein the start function is other functions in the mini-program except the delay function;
[0022] If the delay function is called after the mini program is started, the delay function is fully parsed, the delay function is restored to the first target function, and the first target function is executed.
[0023] Through the above technical solution, by delaying the parsing of the first target function and parsing the first target function when calling the first target function, the startup efficiency of the mini program is improved and the execution of the mini program function is guaranteed.
[0024] In combination with the first aspect and the foregoing implementation manner, in some possible implementation manners, the fully parsing the delay function, restoring the delay function to obtain the first objective function, and executing the first objective function include:
[0025] Detecting the delay function to obtain a description field, and determining that the delay function is a delay resolution function type based on the description field;
[0026] Deleting the description field in the delay function, and restoring the delay function to the function state of the first objective function;
[0027] Execute function body parsing and bytecode generation corresponding to the delay function based on the simplified bytecode object to obtain a first target function corresponding to the delay function;
[0028] The first objective function is executed.
[0029] In combination with the first aspect and the above implementation manner, in some possible implementation manners, a closure variable identifier corresponding to the first objective function is obtained, where the closure variable identifier is used to indicate whether the objective function includes a closure variable;
[0030] Obtaining a closure variable identifier corresponding to the first objective function, where the closure variable identifier is used to indicate whether the first objective function includes a closure variable;
[0031] If the first objective function includes the closure variable, then based on the analysis of the closure variable of the first objective function, determining the association relationship between the first objective function and the parent-child function, wherein the association relationship is used to associate the closure variables;
[0032] If the first objective function does not include the closure variable, a closure variable corresponding to the first objective function is generated based on a grammar specification.
[0033] In a second aspect, a mini-program running device is provided, the device comprising:
[0034] A type determination unit, configured to obtain, for a startup operation of a mini-program, a nesting number of a first target function in the mini-program, and determine a function type of the target function based on the nesting number of the first target function, wherein the first target function is any function in the mini-program;
[0035] a function simplification unit, configured to simplify the function body of the first objective function and the parent function corresponding to the first objective function to obtain a second objective function if the function type is a delayed parsing function type;
[0036] A delay function generation unit is used to generate a simplified bytecode object corresponding to the first target function based on the function description information of the first target function, add the simplified bytecode object to the second target function, and obtain a delay function corresponding to the second target function. The function description information is used to characterize the basic information of the first target function, and the delay function is a function that delays parsing when controlling the startup of the mini program in response to the startup operation.
[0037] According to a third aspect, a computer program product is provided, comprising: a computer program code, which, when executed on a computer, enables the computer to execute the method according to the first aspect or any possible implementation of the first aspect.
[0038] In a fourth aspect, a computer-readable storage medium is provided, which stores a computer program code. When the computer program code runs on a computer, the computer executes the method in the above-mentioned first aspect or any possible implementation manner of the first aspect.
[0039] According to a fifth aspect, an electronic device is provided, comprising: a processor and a memory; wherein the memory stores a computer program, and the computer program is suitable for being loaded by the processor and executing the steps of the above method. BRIEF DESCRIPTION OF THE DRAWINGS
[0040] Figure 1 This is an application scenario diagram of a mini-program running method provided in an embodiment of the present application;
[0041] Figure 2 It is a flowchart of a method for running a small program provided in an embodiment of the present application;
[0042] Figure 3It is a flowchart of a method for running a small program provided in an embodiment of the present application;
[0043] Figure 4 is an example schematic diagram of a layer number field provided in an embodiment of the present application;
[0044] Figure 5 It is a structural diagram of a small program running device provided in an embodiment of the present application;
[0045] Figure 6 It is a structural diagram of a small program running device provided in an embodiment of the present application;
[0046] Figure 7 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION
[0047] The technical solution in the present application will be described clearly and in detail below in conjunction with the accompanying drawings. In the description of the embodiments of the present application, unless otherwise specified, " / " means or, for example, A / B can mean A or B: "and / or" in the text is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, "multiple" means two or more than two.
[0048] In the following, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as suggesting or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features.
[0049] Figure 1 This is an application scenario diagram of a mini-program operation method provided in an embodiment of the present application. Figure 1 As shown, the mini-program running method provided in the embodiment of the present application can be applied to electronic devices, and the electronic device can be a device with a mini-program running function, such as a personal computer, a smart phone, a tablet computer and other devices, to implement the process of simplifying the first objective function to obtain a delay function. In the application scenario provided in the embodiment of the present application, the electronic device receives a selection operation to start the mini-program, so that the display page of the electronic device is switched to display the display interface of the mini-program after it is started.
[0050] In the related technology, with the continuous development of information technology, in order to enrich the types of functions provided, applications have developed small programs corresponding to various functions, so that there is no need to download the applications corresponding to each function. Multiple functions of different types can be used with one application. However, with the widespread application of small programs, improving the startup efficiency of small programs has become an urgent problem to be solved.
[0051] Through the embodiments of the present application, for the startup operation of the mini-program, the function type of the first target function is determined based on the number of nested layers of the first target function in the acquired mini-program, and if the function type is a delayed parsing function type, the function body of the first target function and the parent function corresponding to the first target function are simplified to obtain the second target function, and a simplified bytecode object corresponding to the first target function is generated based on the function description information of the first target function, and the simplified bytecode object is added to the second target function to obtain a delayed function corresponding to the second target function. When the mini-program is started, the delayed function is delayed by delaying the processing to reduce the number of functions that need to be parsed and compiled, thereby shortening the startup time of the mini-program and improving the efficiency of the mini-program startup.
[0052] based on Figure 1 The system architecture shown below will be combined with Figure 2-Figure 4 , the mini-program running method provided in the embodiment of the present application is introduced in detail.
[0053] See also Figure 2 , which is a flowchart of a method for running a small program according to an embodiment of the present application. Figure 2 As shown, the method of the embodiment of the present application may include the following steps S102 to S106.
[0054] S102, for the mini-program startup operation, obtaining the number of nesting levels of the first objective function in the mini-program, and determining the function type of the first objective function based on the number of nesting levels;
[0055] In one embodiment, for the startup operation of the mini-program, the nesting number of the first target function in the mini-program is obtained. The first target function can be any function in the mini-program. The nesting number can be the number of function layers used to characterize the first target function. The function type of the first target function is determined based on the nesting number. The function type can be a function type used to characterize whether the first target function is a delayed resolution function type. The delayed resolution function type can be a function type used to indicate that delayed resolution is required for the first target function.
[0056] S104, if the function type is a delayed parsing function type, simplifying the function body of the first objective function and the parent function corresponding to the first objective function to obtain a second objective function;
[0057] In one embodiment, if the function type of the first target function is a delayed parsing function type, the function body of the first target function and the parent function of the first target function are simplified to obtain a simplified second target function. It can be understood that since the second target function is a simplified function, when the mini program is started to run the second target function, the parsing process of the second target function can be postponed, thereby reducing the startup time of the mini program.
[0058] Specifically, the method for simplifying the function body of the first objective function and the parent function corresponding to the first objective function can be: replacing the function body of the first objective function with a storage size of the storage content that is smaller than a preset size to postpone the parsing process of the first objective function and obtain a function body that occupies less memory; it can be understood that in order to ensure that the mini program can start and run, the parent function of the first objective function is adaptively adjusted according to the simplified function body of the first objective function.
[0059] S106, generating a simplified bytecode object corresponding to the first objective function based on the function description information of the first objective function, adding the simplified bytecode object to the second objective function, and obtaining a delay function corresponding to the second objective function;
[0060] In one embodiment, function description information of the first target function is obtained, and the function description information may be basic information used to characterize the first target function. A simplified bytecode object corresponding to the first target function is generated based on the function description information, and the simplified bytecode object may be simplified description information used to characterize the first target function. The simplified bytecode object is added to the second target function, and a delay function corresponding to the second target function is obtained to ensure that the delay function can be restored according to the simplified bytecode object, and to ensure that the mini program can call the delay function to execute the function corresponding to the first target function. The delay function may be a function that delays parsing when controlling the startup of the mini program in response to a startup operation, thereby reducing the number of functions that need to be parsed and compiled by the mini program through the process of delayed parsing and compilation, thereby shortening the startup time of the mini program.
[0061] In an embodiment of the present application, by obtaining the nesting number of the first target function, the function type of the first target function is determined based on the nesting number, and when the function type of the first target function is a delayed parsing function type, the first target function is processed as a delayed function, thereby reducing the number of functions that need to be parsed and compiled by using a delayed function for delayed processing, thereby shortening the startup time of the mini program and improving the efficiency of the mini program startup.
[0062] The following will be combined Figure 3 A small program running method provided in an embodiment of the present application is described in detail with a specific example.
[0063] S202, for the mini-program startup operation, obtain a description structure corresponding to the first objective function in the mini-program, determine the number of nesting levels of the first objective function based on the layer number field in the description structure, and compare the number of nesting levels with a preset number of levels;
[0064] In one embodiment, for the startup operation of the mini-program, a description structure corresponding to the first objective function in the mini-program is obtained. The first objective function can be any function in the mini-program. The description structure can be a structure corresponding to the function description information in the first objective function. The number of nested layers of the first objective function is determined based on the number of layers field in the description structure. The number of layers field can be a field in the description structure used to characterize the number of nested layers of the first objective function. The number of nested layers can be the number of function layers included in the first objective function. The number of nested layers is compared with a preset number of layers. The preset number of layers can be a pre-set number of layers for determining the function type of the first objective function. The specific number of layers of the preset number of layers can be 2 layers, etc.
[0065] It should be noted that, since the description structure is a structure corresponding to the function description information in the first objective function, the layer number field in the description structure can be a field generated when the first objective function is generated, which is used to represent the number of nested layers of the first objective function. Figure 4 As shown, Figure 4 The nesting level of the first objective function in is 3, and the layer number field of the description structure corresponding to the first objective function is "total_scope_level==3", indicating that the nesting level of the first objective function is 3.
[0066] S204, determining a function type of the first objective function based on a comparison result between the number of nesting levels and a preset number of levels;
[0067] In one embodiment, the nesting number of the first objective function is compared with a preset number of layers, and the function type of the first objective function is determined based on the comparison result of the nesting number of layers and the preset number of layers. The delayed resolution function type can be used to indicate that delayed resolution is required for the first objective function.
[0068] It is understandable that if the nesting level of the first objective function is 1, the effect of delayed parsing of the first objective function is not good, and the need for delayed processing increases the processing steps. Therefore, setting the preset number of levels to 1 has a negative effect; if the nesting level of the first objective function is greater than or equal to 2, the time required to start the mini program can be reduced by postponing the parsing and compilation process of the first objective function. Therefore, the preset number of levels can be 2 or more, and can be set according to actual conditions.
[0069] Exemplarily, if the number of nesting layers is 3 and the preset number of layers is 2, since the number of nesting layers is greater than the preset number of layers, it can be determined that the function type of the first objective function is a delayed resolution function type.
[0070] S206, obtaining a preset bytecode, and replacing the bytecode in the function body of the first target function with the preset bytecode to obtain a delay mark corresponding to the first target function;
[0071] In one embodiment, a preset bytecode is obtained, and the content of the preset bytecode is preset content. It can be understood that in order to reduce the memory occupied by the preset bytecode, the preset bytecode can be a one-byte bytecode. The preset bytecode replaces the bytecode in the function body of the first target function to obtain a delay mark corresponding to the first target function. The delay mark can be used to characterize the delay analysis of the first target function.
[0072] It should be noted that if the return value is not set in the function body after deleting the content in the function body of the first target function, the mini program will execute the first target function infinitely, resulting in the mini program being unable to start. Therefore, in order to avoid the first target function that is delayed in parsing when the mini program starts affecting the startup of the mini program, it is necessary to set a return value for the function body in the first target function to ensure that the mini program can start. In order to reduce the content occupied by the function body, the preset bytecode can be a one-byte bytecode.
[0073] S208, adding a delay mark and a preset bytecode in the parent function of the first target function to obtain a second target function corresponding to the first target function;
[0074] In one embodiment, after the function body of the first target function is replaced, in order to ensure that the mini program can be started, a delay mark and a preset bytecode are added to the parent function of the first target function to obtain the second target function corresponding to the first target function. The second target function can be a function obtained by simplifying the first target function.
[0075] It can be understood that delay marks and preset bytecodes are added to the parent function to ensure that when the mini program is started to execute the parent function, delayed parsing and compilation of the first target function can be determined according to the delay marks and preset bytecodes, thereby realizing delayed parsing and compilation of the first target function.
[0076] S210, generating a simplified bytecode object corresponding to the first target function based on the function description information of the first target function, and adding the simplified bytecode object to the second target function;
[0077] In one embodiment, function description information of the first target function is obtained, and the function description information may be basic information used to characterize the first target function. A simplified bytecode object corresponding to the first target function is generated based on the function description information, and the simplified bytecode object may be simplified description information used to characterize the first target function. The simplified bytecode object is added to the second target function to ensure that the second target function can be restored to the first target function according to the simplified bytecode object when being called.
[0078] It can be understood that since the simplified bytecode object is data obtained by simplifying the function description information based on the first target function, the function name, input parameters, output parameters, function body and other contents corresponding to the first target function can be determined based on the simplified bytecode object, so that the second target function can be restored based on the simplified bytecode object.
[0079] Furthermore, the simplified bytecode object can be stored in a GC (Garbage Collection) list. Since the characteristic of the GC list is to temporarily store data and recycle the data when the data is called or invalid, storing the simplified bytecode object in the GC list can ensure that the simplified bytecode object can be called and recycled in time after being called, thereby reducing the invalid occupation time of memory and improving memory utilization.
[0080] S212, obtaining a description field in the function description information, adding the description field to the execution object corresponding to the second objective function, and obtaining a delay function corresponding to the second objective function;
[0081] In one embodiment, a description field in the function description information is obtained. The description field may be a field in the function description information used to characterize that the function needs to be parsed when it is called. The description field is added to the execution object corresponding to the second target function. The execution object may be an execution function generated for the second target function. The execution object may be the function run when the second target function is called after the mini-program is started. The description field is added to the execution object to obtain a delay function corresponding to the second target function to ensure that when the mini-program executes the delay function, it can determine that the delay function is a function that is delayed in parsing and compiling according to the description field, and the delay function needs to be restored. The delay function may be a function corresponding to the first target function, which extends the parsing and compilation when the mini-program is started.
[0082] S214, starting the applet based on the delay function and the start function;
[0083] In one embodiment, after delay processing is performed on each function in the mini-program according to the number of nested layers of the function and the delay function corresponding to each first target function in the mini-program is obtained, the mini-program is started based on the delay function and the start function. The start function can be any function in the mini-program except the delay function.
[0084] Specifically, since the delay function is a simplified function and cannot be parsed and compiled, in the process of starting the mini program, the skip function is executed to skip the parsing process of the function body and function parameters of the delay function. The skip function can be a function used to skip the parsing process of the function body and function parameters, such as the "next_token function" and the like.
[0085] It is understandable that the startup function can be a function in the mini program with a nesting level less than a preset level. Since the startup function does not need to be delayed parsed and compiled, the startup function can be parsed and compiled in a conventional manner.
[0086] Specifically, the method of parsing and compiling in a conventional manner may be:
[0087] S216, if the delay function is called after the mini program is started, the delay function is fully parsed, the delay function is restored to the first target function, and the first target function is executed;
[0088] In one embodiment, if the delay function is called after the mini program is started, the delay function is fully parsed, the delay function is restored to obtain the first target function corresponding to the delay function, and the first target function is executed.
[0089] Exemplarily, the delay function is fully parsed to obtain the first target function, and the method for executing the first target function may be: detecting the delay function to obtain a description field, determining that the delay function is a delay parsing function type based on the description field, deleting the description field in the delay function, restoring the delay function to the function state of the first target function, performing function body parsing and bytecode generation corresponding to the delay function based on the simplified bytecode object, obtaining the first target function corresponding to the delay function, and executing the first target function.
[0090] Specifically, the execution object in the delay function is detected to obtain the description field corresponding to the delay function, the function type of the delay function is determined to be a delay parsing function type based on the description field, the description field in the delay function is deleted, and the delay function is restored to the function state of the first target function to avoid the first target function being misidentified as having a function type of the delay parsing function type in the future, and the first target function is repeatedly parsed, resulting in unnecessary waste of resources.
[0091] Further, the simplified bytecode object in the GC list is accessed, and the function body and function parameters of the delay function are generated based on the content stored in the simplified bytecode object. The specific generation method can be to use the function generation specification to generate the parameter relationship between the function parameters in the function body of the delay function and the corresponding bytecode based on the simplified bytecode object, so as to obtain the first target function corresponding to the delay function. For example, based on the simplified bytecode object, it is determined that the delay function includes input parameters "1", "2" and output parameter "y", as well as bytecodes "+" and "=", so as to obtain the first target function corresponding to the delay, and the first target function is "y=1+2".
[0092] The first objective function is executed, and the output result of the first objective function is obtained according to the function body and function parameters in the first objective function. For example, the first objective function "y=1+2" is executed, and the output result of the first objective function is "3".
[0093] Furthermore, after fully parsing the delay function to obtain the first target function, in order to ensure that the functions in the mini program can read each other's corresponding parameters and output results, it is necessary to parse the closure variables corresponding to the first target function to determine the association relationship between the parent and child functions.
[0094] Specifically, the method for parsing the closure variables corresponding to the first objective function may be: obtaining the closure variable identifier corresponding to the first objective function, the closure variable identifier is used to characterize whether the first objective function includes the closure variable; if the first objective function includes the closure variable, then based on the parsing of the closure variables of the first objective function, determining the association relationship between the parent and child functions corresponding to the first objective function, the association relationship is used to associate the closure variables; if the first objective function does not include the closure variable, then generating the closure variable corresponding to the first objective function based on the grammatical specification.
[0095] It is understandable that if the first objective function includes closure variables, the data of other functions in the mini program cannot be obtained when the first objective function is executed, which makes the first objective function unable to be executed, affecting the mini program's execution of the function corresponding to the first objective function. Therefore, it is necessary to generate a closure variable corresponding to the first objective function, and then complete the association relationship between the first objective function and other functions to ensure that the mini program can execute the function corresponding to the first objective function.
[0096] Furthermore, in order to improve the startup rate of the mini program, a feasible method is to optimize the compiler of the mini program. Specifically, the external function whose calling frequency is greater than the first preset frequency is inlined in the engine corresponding to the mini program. The specific value of the first preset frequency can be set according to the actual situation. The engine can be a QuickJS engine, etc. The function body of the external function is inserted into and replaces the instruction of calling the external function in the engine to reduce the number of calling layers required when the engine calls the external function, thereby improving the startup efficiency of the mini program.
[0097] Furthermore, the method for optimizing the compiler may also be: deleting the code supported or required by the applet framework or engine syntax, and the code with a calling frequency lower than the second preset frequency, thereby reducing the complexity of the optimization and code generation stages.
[0098] Furthermore, the compiler optimization method can also be: optimizing the preset statement types in the code of the mini-program to improve the data processing efficiency of the mini-program. For example: when executing a task matching the opcode for a switch-case statement, all opcodes and their corresponding function addresses are stored in a preset table, so that the preset table can be searched according to each opcode, the corresponding function address can be extracted, and the corresponding task can be executed by jumping to the function address.
[0099] Furthermore, in order to detect the degree of performance optimization of starting a mini-program by generating a delay function, a feasible method may be: testing the time required for starting the mini-program and the memory occupied, determining the degree of performance optimization based on the test results, and then being able to make targeted adjustments to the generation and application methods of the delay function according to the degree of performance optimization.
[0100] In the embodiment of the present application, by obtaining the number of nesting levels of the first target function, the function type of the first target function is determined based on the number of nesting levels, and when the function type of the first target function is a delayed parsing function type, the first target function is processed as a delay function, thereby reducing the number of functions that need to be parsed and compiled by the delay function that is processed by delay, thereby shortening the startup time of the mini program and improving the efficiency of the mini program startup. Further, since the function body of the delay function is replaced by the preset content, the memory occupied by the delay function is reduced, thereby optimizing the memory occupation, avoiding unnecessary memory occupation, and saving system resources of the electronic device. Further, by calling the delay function after starting the mini program, the delay function is restored to the first target function based on the simplified bytecode object to ensure that the mini program can execute the first target function, thereby ensuring the operation of each function while improving the startup efficiency of the mini program; further, by optimizing the compiler of the mini program, the performance of the engine is improved, thereby improving the startup efficiency and processing efficiency of the mini program.
[0101] based on Figure 1 The system architecture will be combined with Figure 5 and Figure 6 , the mini-program running device provided in the embodiment of the present application is introduced in detail. It should be noted that, Figure 5 The applet running device 1 in the present application is used to execute Figure 2-Figure 4 For the convenience of explanation, only the part related to the embodiment of the present application is shown. For the specific technical details not disclosed, please refer to the present application. Figure 2-Figure 4 The embodiment shown.
[0102] A type determination unit 11 is used to obtain the number of nesting levels of a first target function in the mini-program for a startup operation of the mini-program, and determine the function type of the first target function based on the number of nesting levels, where the first target function is any function in the mini-program;
[0103] A function simplification unit 12, configured to simplify the function body of the first objective function and the parent function corresponding to the first objective function to obtain a second objective function if the function type is a delayed parsing function type;
[0104] A delay function generation unit 13 is used to generate a simplified bytecode object corresponding to the first target function based on the function description information of the first target function, add the simplified bytecode object to the second target function, and obtain a delay function corresponding to the second target function. The function description information is used to characterize the basic information of the first target function, and the delay function is a function that delays parsing when controlling the startup of the mini program in response to the startup operation.
[0105] Optionally, the type determination unit 11 is further configured to:
[0106] Obtain a description structure corresponding to the first objective function in the mini-program, determine the number of nesting levels of the first objective function based on a layer number field in the description structure, and compare the number of nesting levels with a preset number of levels;
[0107] The function type of the first objective function is determined based on a comparison result of the nesting number and the preset number of layers.
[0108] Optionally, the function simplification unit 12 is further used for:
[0109] Obtaining a preset bytecode, replacing the bytecode in the function body of the first target function with the preset bytecode, and obtaining a delay mark corresponding to the first target function, wherein the content of the preset bytecode is preset content;
[0110] The delay mark and the preset bytecode are added to the parent function of the first target function to obtain a second target function corresponding to the first target function.
[0111] Optionally, the function simplification unit 12 is further used for:
[0112] Generate a simplified bytecode object corresponding to the first target function based on the function description information of the first target function, and add the simplified bytecode object to the second target function;
[0113] Obtain a description field in the function description information, and add the description field to the execution object corresponding to the second target function.
[0114] Optionally, as shown in the figure, the mini-program running device further includes:
[0115] A mini-program starting unit 14, configured to start the mini-program based on the delay function and a start function, wherein the start function is other functions in the mini-program except the delay function;
[0116] The mini-program execution unit 15 is used to fully parse the delay function, restore the delay function to the first target function, and execute the first target function if the delay function is called after the mini-program is started.
[0117] Optionally, the applet execution unit 15 is further used for:
[0118] Detecting the delay function to obtain a description field, and determining that the delay function is a delay resolution function type based on the description field;
[0119] Deleting the description field in the delay function, and restoring the delay function to the function state of the first objective function;
[0120] Execute function body parsing and bytecode generation corresponding to the delay function based on the simplified bytecode object to obtain a first target function corresponding to the delay function;
[0121] The first objective function is executed.
[0122] Optionally, the applet execution unit 15 is further used for:
[0123] Obtaining a closure variable identifier corresponding to the first objective function, where the closure variable identifier is used to indicate whether the first objective function includes a closure variable;
[0124] If the first objective function includes the closure variable, then based on the analysis of the closure variable of the first objective function, determining the association relationship between the first objective function and the parent-child function, wherein the association relationship is used to associate the closure variables;
[0125] If the first objective function does not include the closure variable, a closure variable corresponding to the first objective function is generated based on a grammar specification.
[0126] In the embodiment of the present application, by obtaining the number of nesting levels of the first target function, the function type of the first target function is determined based on the number of nesting levels, and when the function type of the first target function is a delayed parsing function type, the first target function is processed as a delay function, thereby reducing the number of functions that need to be parsed and compiled by the delay function that is processed by delay, thereby shortening the startup time of the mini program and improving the efficiency of the mini program startup. Further, since the function body of the delay function is replaced by the preset content, the memory occupied by the delay function is reduced, thereby optimizing the memory occupation, avoiding unnecessary memory occupation, and saving system resources of the electronic device. Further, by calling the delay function after starting the mini program, the delay function is restored to the first target function based on the simplified bytecode object to ensure that the mini program can execute the first target function, thereby ensuring the operation of each function while improving the startup efficiency of the mini program; further, by optimizing the compiler of the mini program, the performance of the engine is improved, thereby improving the startup efficiency and processing efficiency of the mini program.
[0127] The present application also provides a computer storage medium that can store multiple program instructions, which are suitable for being loaded and executed by a processor as described above. Figure 1-Figure 4 The method steps of the embodiment shown in the figure can be found in the specific execution process. Figure 1-Figure 4 The specific description of the illustrated embodiment will not be repeated here.
[0128] The embodiment of the present application also provides a computer program product, which stores at least one instruction, and the at least one instruction is loaded and executed by the processor as described above. Figure 1-Figure 4 The applet running method of the embodiment shown in the figure can be found in the specific execution process. Figure 1-Figure 4 The specific description of the illustrated embodiment will not be repeated here.
[0129] See also Figure 7 , is a schematic diagram of the structure of an electronic device provided in an embodiment of the present application. Figure 7 As shown, the electronic device 1000 may include: at least one processor 1001, such as a CPU, at least one network interface 1004, an input / output interface 1003, a memory 1005, and at least one communication bus 1002. The communication bus 1002 is used to realize the connection and communication between these components. The network interface 1004 may optionally include a standard wired interface, a wireless interface (such as a WI-FI interface). The memory 1005 may be a high-speed RAM memory, or a non-volatile memory (non-volatile memory), such as at least one disk storage. The memory 1005 may optionally be at least one storage device located away from the aforementioned processor 1001. As shown in FIG. Figure 7 As shown, the memory 1005 as a computer storage medium may include an operating system, a network communication module, an input and output interface module, and a small program running application program.
[0130] exist Figure 7 In the electronic device 1000 shown, the input-output interface 1003 is mainly used to provide an input interface for the user and obtain data input by the user.
[0131] In one embodiment, the processor 1001 may be used to call the applet stored in the memory 1005 to run the application program, and specifically perform the following operations:
[0132] For a startup operation of a mini-program, obtaining a nesting level of a first target function in the mini-program, and determining a function type of the first target function based on the nesting level, wherein the first target function is any function in the mini-program;
[0133] If the function type is a delayed parsing function type, simplifying the function body of the first objective function and the parent function corresponding to the first objective function to obtain a second objective function;
[0134] A simplified bytecode object corresponding to the first target function is generated based on the function description information of the first target function, and the simplified bytecode object is added to the second target function to obtain a delay function corresponding to the second target function. The function description information is used to characterize the basic information of the first target function, and the delay function is a function that delays parsing when controlling the startup of the mini program in response to the startup operation.
[0135] Optionally, when the processor 1001 obtains the number of nesting levels of the first objective function in the mini-program and determines the function type of the first objective function based on the number of nesting levels, the processor 1001 specifically performs the following operations:
[0136] Obtain a description structure corresponding to the first objective function in the mini-program, determine the number of nesting levels of the first objective function based on a layer number field in the description structure, and compare the number of nesting levels with a preset number of levels;
[0137] The function type of the first objective function is determined based on a comparison result of the nesting number and the preset number of layers.
[0138] Optionally, when the processor 1001 simplifies the function body in the first objective function and the parent function corresponding to the first objective function to obtain the second objective function, specifically executes:
[0139] Obtaining a preset bytecode, replacing the bytecode in the function body of the first target function with the preset bytecode, and obtaining a delay mark corresponding to the first target function, wherein the content of the preset bytecode is preset content;
[0140] The delay mark and the preset bytecode are added to the parent function of the first target function to obtain a second target function corresponding to the first target function.
[0141] Optionally, when the processor 1001 generates a simplified bytecode object corresponding to the first target function based on the function description information of the first target function and adds the simplified bytecode object to the second target function, the processor 1001 specifically performs the following operations:
[0142] Generate a simplified bytecode object corresponding to the first target function based on the function description information of the first target function, and add the simplified bytecode object to the second target function;
[0143] Obtain a description field in the function description information, and add the description field to the execution object corresponding to the second target function.
[0144] Optionally, after executing to obtain the delay function corresponding to the second objective function, the processor 1001 further performs the following operations:
[0145] Starting the mini-program based on the delay function and the start function, wherein the start function is other functions in the mini-program except the delay function;
[0146] If the delay function is called after the mini program is started, the delay function is fully parsed, the delay function is restored to the first target function, and the first target function is executed.
[0147] Optionally, when the processor 1001 performs full parsing of the delay function, restores the delay function to obtain the first objective function, and executes the first objective function, the following operations are specifically performed:
[0148] Detecting the delay function to obtain a description field, and determining that the delay function is a delay resolution function type based on the description field;
[0149] Deleting the description field in the delay function, and restoring the delay function to the function state of the first objective function;
[0150] Execute function body parsing and bytecode generation corresponding to the delay function based on the simplified bytecode object to obtain a first target function corresponding to the delay function;
[0151] The first objective function is executed.
[0152] Optionally, the processor 1001 further performs the following operations:
[0153] Obtaining a closure variable identifier corresponding to the first objective function, where the closure variable identifier is used to indicate whether the first objective function includes a closure variable;
[0154] If the first objective function includes the closure variable, then based on the analysis of the closure variable of the first objective function, determining the association relationship between the first objective function and the parent-child function, wherein the association relationship is used to associate the closure variables;
[0155] If the first objective function does not include the closure variable, a closure variable corresponding to the first objective function is generated based on a grammar specification.
[0156] In the embodiment of the present application, by obtaining the number of nesting levels of the first target function, the function type of the first target function is determined based on the number of nesting levels, and when the function type of the first target function is a delayed parsing function type, the first target function is processed as a delay function, thereby reducing the number of functions that need to be parsed and compiled by the delay function that is processed by delay, thereby shortening the startup time of the mini program and improving the efficiency of the mini program startup. Further, since the function body of the delay function is replaced by the preset content, the memory occupied by the delay function is reduced, thereby optimizing the memory occupation, avoiding unnecessary memory occupation, and saving system resources of the electronic device. Further, by calling the delay function after starting the mini program, the delay function is restored to the first target function based on the simplified bytecode object to ensure that the mini program can execute the first target function, thereby ensuring the operation of each function while improving the startup efficiency of the mini program; further, by optimizing the compiler of the mini program, the performance of the engine is improved, thereby improving the startup efficiency and processing efficiency of the mini program.
[0157] A person skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.
[0158] The above disclosure is only the preferred embodiment of this specification, which certainly cannot be used to limit the scope of rights of this specification. Therefore, equivalent changes made according to the claims of this specification are still within the scope covered by this specification.
Claims
1. A method for running a small program, the method comprising: For a startup operation of a mini-program, obtaining a nesting level of a first target function in the mini-program, and determining a function type of the first target function based on the nesting level, wherein the first target function is any function in the mini-program; If the function type is a delayed parsing function type, simplifying the function body of the first objective function and the parent function corresponding to the first objective function to obtain a second objective function; A simplified bytecode object corresponding to the first target function is generated based on the function description information of the first target function, and the simplified bytecode object is added to the second target function to obtain a delay function corresponding to the second target function. The function description information is used to characterize the basic information of the first target function, and the delay function is a function that delays parsing when controlling the startup of the mini program in response to the startup operation.
2. According to the method of claim 1, the obtaining the number of nesting levels of the first objective function in the mini-program and determining the function type of the first objective function based on the number of nesting levels comprises: Obtain a description structure corresponding to the first objective function in the mini-program, determine the number of nesting levels of the first objective function based on a layer number field in the description structure, and compare the number of nesting levels with a preset number of levels; The function type of the first objective function is determined based on a comparison result of the nesting number and the preset number of layers.
3. According to the method of claim 1, the simplifying of the function body in the first objective function and the parent function corresponding to the first objective function to obtain the second objective function comprises: Obtaining a preset bytecode, replacing the bytecode in the function body of the first target function with the preset bytecode, and obtaining a delay mark corresponding to the first target function, wherein the content of the preset bytecode is preset content; The delay mark and the preset bytecode are added to the parent function of the first target function to obtain a second target function corresponding to the first target function.
4. The method according to claim 1, wherein generating a simplified bytecode object corresponding to the first target function based on the function description information of the first target function, and adding the simplified bytecode object to the second target function comprises: Generate a simplified bytecode object corresponding to the first target function based on the function description information of the first target function, and add the simplified bytecode object to the second target function; Obtain a description field in the function description information, and add the description field to the execution object corresponding to the second target function.
5. The method according to claim 1, after obtaining the delay function corresponding to the second objective function, further comprising: Starting the mini-program based on the delay function and the start function, wherein the start function is other functions in the mini-program except the delay function; If the delay function is called after the mini program is started, the delay function is fully parsed, the delay function is restored to the first target function, and the first target function is executed.
6. The method according to claim 5, wherein the step of fully parsing the delay function, restoring the delay function to obtain the first target function, and executing the first target function comprises: Detecting the delay function to obtain a description field, and determining that the delay function is a delay resolution function type based on the description field; Deleting the description field in the delay function, and restoring the delay function to the function state of the first objective function; Execute function body parsing and bytecode generation corresponding to the delay function based on the simplified bytecode object to obtain a first target function corresponding to the delay function; The first objective function is executed.
7. The method according to claim 5, further comprising: Obtaining a closure variable identifier corresponding to the first objective function, where the closure variable identifier is used to indicate whether the first objective function includes a closure variable; If the first objective function includes the closure variable, then based on the analysis of the closure variable of the first objective function, determining the association relationship between the first objective function and the parent-child function, wherein the association relationship is used to associate the closure variables; If the first objective function does not include the closure variable, a closure variable corresponding to the first objective function is generated based on a grammar specification.
8. A small program running device, the device comprising: A type determination unit, configured to obtain, for a startup operation of a mini-program, a nesting number of a first target function in the mini-program, and determine a function type of the first target function based on the nesting number of the first target function, wherein the first target function is any function in the mini-program; a function simplification unit, configured to simplify the function body of the first objective function and the parent function corresponding to the first objective function to obtain a second objective function if the function type is a delayed parsing function type; A delay function generation unit is used to generate a simplified bytecode object corresponding to the first target function based on the function description information of the first target function, add the simplified bytecode object to the second target function, and obtain a delay function corresponding to the second target function. The function description information is used to characterize the basic information of the first target function, and the delay function is a function that delays parsing when controlling the startup of the mini program in response to the startup operation.
9. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program code, and when the computer program code is executed, the method according to any one of claims 1 to 7 is implemented.
10. An electronic device, comprising: A processor and a memory; wherein the memory stores a computer program, and the computer program is suitable for being loaded by the processor and executing the steps of the method as claimed in any one of claims 1 to 7.
11. A computer program product having at least one instruction stored thereon, wherein when the at least one instruction is executed by a processor, the steps of the method according to any one of claims 1 to 7 are implemented.
