Invocation method, invocation apparatus and computer device

By utilizing PGO and AOT technologies in the ArkTS engine to collect NAPI object information and generate machine code files, the cross-language calling process is optimized, solving the problem of low calling efficiency between ArkTS and C++, and achieving more efficient code execution and an improved developer experience.

WO2026103476A1PCT designated stage Publication Date: 2026-05-21HUAWEI TECH CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
HUAWEI TECH CO LTD
Filing Date
2025-10-24
Publication Date
2026-05-21

AI Technical Summary

Technical Problem

In existing technologies, cross-language calls between ArkTS and C++ are inefficient, resulting in low code file execution efficiency and affecting the developer's user experience.

Method used

By using PGO and AOT technologies in the ArkTS engine, information such as the type information, loop count, and branch weight of NAPI objects is collected to generate machine code files, optimize the cross-language calling process, achieve fast path processing, and reduce the overhead of prototype chain lookup and type judgment.

Benefits of technology

It improves the efficiency of cross-language calls, enhances the execution efficiency of code files, and improves the user experience for developers.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2025129827_21052026_PF_FP_ABST
    Figure CN2025129827_21052026_PF_FP_ABST
Patent Text Reader

Abstract

Provided in the present application are an invocation method, an invocation apparatus and a computer device. The method comprises: on the basis of a first source code file, determining collection information of one or more NAPI objects, wherein the first source code file comprises a first code statement, and the first code statement is used for indicating the invocation of information of one or more NAPI objects in a second source code file; on the basis of the first source code file and the collection information of the one or more NAPI objects, generating a machine code file; and running the machine code file, so as to obtain the information of the one or more NAPI objects in the second source code file. In the invocation method, the invocation apparatus and the computer device provided in the present application, collection information of a NAPI object is used for guiding the compilation of a first source code file, and a machine code obtained by means of compilation can run efficiently, thereby improving the efficiency of cross-language invocation and also improving the user experience.
Need to check novelty before this filing date? Find Prior Art

Description

Method invocation, invocation device, and computer equipment

[0001] This application claims priority to Chinese Patent Application No. 202411644380.2, filed on November 18, 2024, entitled "Method of Invoking, Apparatus of Invoking and Computer Equipment", the entire contents of which are incorporated herein by reference. Technical Field

[0002] This application relates to computer technology, and more specifically, to a method of invoking, an apparatus for invoking, and a computer device. Background Technology

[0003] ArkTS (Ark TypeScript) is a programming language. Cross-language calls between ArkTS and C or C++ are a common requirement in system development. To achieve cross-language calls, a node application programming interface (NAPI) is provided. After loading a NAPI object, developers can access its properties and call its functions at the ArkTS layer. Therefore, the efficiency of cross-language calls significantly impacts the execution of code files.

[0004] Therefore, improving the efficiency of cross-language calls and the execution efficiency of code files, thereby enhancing the user experience for developers, is an urgent problem to be solved. Summary of the Invention

[0005] This application provides a method for invoking, an invoking device, and a computer device. This method can improve the efficiency of cross-language invocation, increase the execution efficiency of code files, and thus enhance the developer's user experience.

[0006] In a first aspect, a calling method is provided, which is applied to a computer device. The method includes: determining the acquisition information of one or more node application programming interfaces (NAPIs) based on a first source code file, the first source code file including first code statements, the first code statements being used to instruct the invocation of the information of the one or more NAPI objects in a second source code file; generating a machine code file based on the first source code file and the acquisition information of the one or more NAPI objects; and running the machine code file to obtain the information of the one or more NAPI objects in the second source code file.

[0007] Based on the above scheme, the collected information of one or more NAPI objects is used to guide the compilation of the first source code file to obtain a machine code file, which can run efficiently, thereby improving the efficiency of cross-language calls, and obtaining information of one or more NAPI objects in the second source code file.

[0008] In conjunction with the first aspect, in some implementations of the first aspect, during the compilation phase, the acquisition information of one or more NAPI objects is determined based on the first source code file; and a machine code file is generated based on the first source code file and the acquisition information of one or more NAPI objects.

[0009] In conjunction with the first aspect, in some implementations of the first aspect, during the sampling guidance optimization PGO stage, the sampling information of one or more NAPI objects is determined based on the first source code file.

[0010] In conjunction with the first aspect, in some implementations of the first aspect, during the AOT compilation stage, the machine code file is generated based on the first source code file and the acquisition information of one or more NAPI objects.

[0011] Based on the above scheme, during the profile-guided optimization (PGO) phase, the collected information of one or more NAPI objects is obtained and used to guide the compilation process in the ahead-of-time (AOT) phase, so as to run the code efficiently, improve the efficiency of cross-language calls, and enhance the user experience.

[0012] In conjunction with the first aspect, in some implementations of the first aspect, during the runtime phase, the machine code file is run to obtain information about one or more NAPI objects in the second source code file.

[0013] In conjunction with the first aspect, in some implementations of the first aspect, the information collected by the one or more NAPI objects includes at least one of type information, loop count, and branch weight.

[0014] In conjunction with the first aspect, in some implementations of the first aspect, the information of the one or more NAPIs includes at least one of the following: the properties of the one or more NAPI objects, and the methods of the one or more NAPI objects.

[0015] In conjunction with the first aspect, in some implementations of the first aspect, determining the acquisition information of one or more node application programming interface (NAPI) objects based on the first source code file includes: compiling the first source code file to obtain the hidden class of the first object; determining the hidden class of the one or more NAPI objects based on the hidden class of the first object; and acquiring the acquisition information of the hidden class of the one or more NAPI objects.

[0016] For example, the first object can be a regular object, and the hidden class of the first object can be obj.instance hclass. The hidden class of the NAPI object can be NAPI obj.instance.hclass. NAPI obj.instance.hclass is obtained by copying obj.instance hclass, and NAPI obj.instance.hclass overrides the original obj.instance.hclass.

[0017] In simple terms, the scope of `obj.instance.hclass` is larger than that of `NAPI obj.instance.hclass`. During the PGO phase, only information about `NAPI obj.instance.hclass` objects (e.g., type information) is collected. This avoids collecting too much information, conserves content, and ensures that key information is not lost, thus improving the efficiency of information acquisition.

[0018] In conjunction with the first aspect, in some implementations of the first aspect, obtaining the collection information of the hidden classes of the one or more NAPI objects includes: adding the hidden classes of the one or more NAPI objects to a first data set; and obtaining the collection information of the hidden classes of the one or more NAPI objects in the first data set.

[0019] For example, the first data set is the ROOT set. After isolating NAPI objects from ordinary objects, NAPI obj.instance.hclass can be added to the ROOT set, thereby collecting information from the NAPI objects in the ROOT set, reducing memory usage while improving the efficiency of obtaining collected information.

[0020] In conjunction with the first aspect, in certain implementations of the first aspect, generating a machine code file based on the first source code file and the acquisition information of the one or more NAPI objects includes: determining a migration tree of the one or more NAPI objects based on the acquisition information of the one or more NAPI objects, wherein the migration tree of the one or more NAPI objects includes at least one node, and the at least one node corresponds to the hidden class of the one or more NAPI objects; storing the migration tree of the one or more NAPI objects in a first memory; and generating the machine code file based on the first source code file and the migration tree of the one or more NAPI objects.

[0021] For example, the transition tree of the NAPI object is reconstructed based on the collected information of the NAPI object, and the reconstructed NAPI obj.instance.hclass is serialized and stored in a snapshot. This allows the hclass generated during AOT compilation to enter the fast path at runtime by parsing the snapshot. Nodes in the transition tree can be NAPI objects with different attributes. The process of adding attributes to a NAPI object can be understood as a migration process. Each migration results in a new hclass. Each node in the transition tree corresponds to an hclass.

[0022] Storing the migration tree of one or more NAPI objects in the first memory can be understood as serializing and storing the hidden class of one or more NAPI objects corresponding to the nodes in the migration tree of one or more NAPI objects in a snapshot.

[0023] In conjunction with the first aspect, in some implementations of the first aspect, running the machine code file includes: at runtime, determining a fast path by calling a first memory location; and running the machine code file through that fast path.

[0024] It's important to note that accessing the first memory location can be understood as retrieving the `hclass` from the snapshot and replacing the original `NAPI obj.instance.hclass`. The `hclass` generated during AOT compilation allows for faster path resolution at runtime by parsing the snapshot. Ultimately, this faster code executes to access NAPI object properties and make function calls.

[0025] Based on the above scheme, information about the NAPI object is recorded during the PGO phase, and the transition tree of the NAPI object is reconstructed using the information collected during the AOT phase. After optimization using AOT technology, when loading properties, the corresponding hclass can be found in the reconstructed transition tree. By directly loading the hclass, property access and function calls are achieved through a fast path, reducing the overhead of checking and crawling the prototype chain through a slow path, improving the efficiency of cross-language calls, and enhancing the user experience.

[0026] In conjunction with the first aspect, in some implementations of the first aspect, the first source code file is an ArkTypeScript code file.

[0027] In conjunction with the first aspect, in some implementations of the first aspect, the first source code file is a JavaScript code file.

[0028] In a second aspect, an electronic device is provided, comprising: one or more processors; one or more memories; the one or more memories storing one or more computer programs, the one or more computer programs including instructions that, when executed by the one or more processors, cause the electronic device to perform the following steps: determining acquisition information of one or more Node Application Programming Interface (NAPI) objects based on a first source code file, the first source code file including first code statements used to instruct the invocation of information of the one or more NAPI objects in a second source code file; generating a machine code file based on the first source code file and the acquisition information of the one or more NAPI objects; and running the machine code file to obtain information of the one or more NAPI objects in the second source code file.

[0029] In conjunction with the second aspect, in some implementations of the second aspect, when the instruction is executed by the one or more processors, the electronic device performs the following steps: during the compilation phase, determining the acquisition information of the one or more NAPI objects based on the first source code file; and generating a machine code file based on the first source code file and the acquisition information of the one or more NAPI objects.

[0030] In conjunction with the second aspect, in some implementations of the second aspect, when the instruction is executed by the one or more processors, the electronic device performs the following steps: during the sampling guidance optimization (PGO) phase, determining the acquisition information of the one or more NAPI objects based on the first source code file.

[0031] In conjunction with the second aspect, in some implementations of the second aspect, when the instruction is executed by the one or more processors, the electronic device performs the following steps: during the AOT (Advanced Time-of-Use) compilation phase, the machine code file is generated based on the first source code file and the acquisition information of the one or more NAPI objects.

[0032] In conjunction with the second aspect, in some implementations of the second aspect, when the instruction is executed by the one or more processors, the electronic device performs the following steps: during the runtime phase, running the machine code file to obtain information about the one or more NAPI objects in the second source code file.

[0033] In conjunction with the second aspect, in some implementations of the second aspect, the information collected by the one or more NAPI objects includes at least one of type information, loop count, and branch weight.

[0034] In conjunction with the second aspect, in some implementations of the second aspect, the information of the one or more NAPIs includes at least one of the following: the properties of the one or more NAPI objects, and the methods of the one or more NAPI objects.

[0035] In conjunction with the second aspect, in some implementations of the second aspect, the acquisition information of one or more NAPI objects is determined based on the first source code file. When the instruction is executed by one or more processors, the electronic device performs the following steps: compiling the first source code file to obtain the hidden class of the first object; determining the hidden class of the one or more NAPI objects based on the hidden class of the first object; and acquiring the acquisition information of the hidden class of the one or more NAPI objects.

[0036] In conjunction with the second aspect, in some implementations of the second aspect, when the instruction to acquire the hidden class information of one or more NAPI objects is executed by one or more processors, the electronic device performs the following steps: adding the hidden class of one or more NAPI objects to a first data set; and acquiring the acquisition information of the hidden class of one or more NAPI objects in the first data set.

[0037] In conjunction with the second aspect, in some implementations of the second aspect, the machine code file is generated based on the first source code file and the acquisition information of the one or more NAPI objects. When the instruction is executed by the one or more processors, the electronic device performs the following steps: determining the migration tree of the one or more NAPI objects based on the acquisition information of the one or more NAPI objects, the migration tree of the one or more NAPI objects including at least one node, the at least one node corresponding to the hidden class of the one or more NAPI objects; storing the migration tree of the one or more NAPI objects in a first memory; and generating the machine code file based on the first source code file and the migration tree of the one or more NAPI objects.

[0038] In conjunction with the second aspect, in some implementations of the second aspect, the machine code file is executed such that when the instruction is executed by one or more processors, the electronic device performs the following steps: at runtime, a fast path is determined by calling a first memory; and the machine code file is executed through the fast path.

[0039] In conjunction with the second aspect, in some implementations of the second aspect, the first source code file is an ArkTypeScript code file.

[0040] Thirdly, a calling device is provided, comprising: a module / unit for executing the first aspect described above and any possible implementation thereof.

[0041] Fourthly, a computer device is provided, comprising: one or more processors; one or more memories; the one or more memories storing one or more computer programs, the one or more computer programs including instructions that, when executed by the one or more processors, cause the method of the first aspect and any possible implementation thereof to be performed.

[0042] Fifthly, a chip is provided that includes a processor and a communication interface for receiving a signal and transmitting the signal to the processor, which processes the signal such that the method described in the first aspect and any possible implementation thereof is executed.

[0043] In a sixth aspect, a computer-readable storage medium is provided that stores computer instructions that, when executed on a computer, cause the methods described in the first aspect and any possible implementation thereof to be performed.

[0044] In a seventh aspect, a computer program product is provided, the computer program product including instructions for performing methods as described in the first aspect and any possible implementation thereof. Attached Figure Description

[0045] Figure 1 is a schematic diagram of the structure of an electronic device.

[0046] Figure 2 is a schematic flowchart of a calling method provided in an embodiment of this application.

[0047] Figure 3 is a schematic flowchart of a calling method provided in an embodiment of this application.

[0048] Figure 4 is a schematic diagram illustrating the isolation of NAPI objects from ordinary objects according to an embodiment of this application.

[0049] Figure 5 is a schematic flowchart of a calling method provided in an embodiment of this application.

[0050] Figure 6 is a structural block diagram of a calling device provided in an embodiment of this application.

[0051] Figure 7 is a structural block diagram of a calling device provided in an embodiment of this application.

[0052] Figure 8 is a structural block diagram of a computer device provided in an embodiment of this application. Detailed Implementation

[0053] The technical solutions in this application will now be described with reference to the accompanying drawings.

[0054] The terminology used in the following embodiments is for the purpose of describing particular embodiments only and is not intended to be limiting of this application. As used in the specification and appended claims of this application, the singular expressions “a,” “an,” “the,” “the,” “the,” and “this” are intended to also include expressions such as “one or more,” unless the context clearly indicates otherwise. It should also be understood that in the following embodiments of this application, “at least one” and “one or more” refer to one, two, or more than two. The term “and / or” is used to describe the relationship between related objects, indicating that three relationships may exist; for example, A and / or B can indicate: A alone, A and B simultaneously, or B alone, where A and B can be singular or plural. The character “ / ” generally indicates that the preceding and following related objects are in an “or” relationship.

[0055] References to "one embodiment" or "some embodiments" as described in this specification mean that one or more embodiments of this application include a specific feature, structure, or characteristic described in connection with that embodiment. Therefore, the phrases "in one embodiment," "in some embodiments," "in other embodiments," "in still other embodiments," etc., appearing in different parts of this specification do not necessarily refer to the same embodiment, but rather mean "one or more, but not all, embodiments," unless otherwise specifically emphasized. The terms "comprising," "including," "having," and variations thereof mean "including but not limited to," unless otherwise specifically emphasized.

[0056] The compilation method provided in this application can be implemented by an electronic device, and this application does not limit the specific type and implementation form of the electronic device. For example, the electronic device can be a desktop computer, smartphone, tablet computer, laptop computer, personal computer (PC), ultra-mobile personal computer (UMPC), netbook, personal digital assistant (PDA), in-vehicle device, wearable device, foldable device, etc., and can also be applied to mobile devices such as in-vehicle systems and robots. The electronic device includes, but is not limited to, devices equipped with... Or electronic devices with other operating systems.

[0057] For example, Figure 1 shows a schematic diagram of the structure of an electronic device 100. The electronic device 100 may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a speaker 170A, a receiver 170B, a microphone 170C, a headphone jack 170D, a sensor module 180, buttons 190, a motor 191, an indicator 192, a camera 193, a display screen 194, and a subscriber identification module (SIM) card interface 195, etc. The sensor module 180 may include a pressure sensor 180A, a gyroscope sensor 180B, a barometric pressure sensor 180C, a magnetic sensor 180D, an accelerometer sensor 180E, a distance sensor 180F, a proximity sensor 180G, a fingerprint sensor 180H, a temperature sensor 180J, a touch sensor 180K, an ambient light sensor 180L, a bone conduction sensor 180M, etc.

[0058] It is understood that the structures illustrated in the embodiments of this application do not constitute a specific limitation on the electronic device 100. In other embodiments of this application, the electronic device 100 may include more or fewer components than illustrated, or combine some components, or split some components, or have different component arrangements. The illustrated components may be implemented in hardware, software, or a combination of software and hardware.

[0059] Processor 110 may include one or more processing units, such as: application processor (AP), modem processor, graphics processing unit (GPU), image signal processor (ISP), controller, memory, video codec, digital signal processor (DSP), baseband processor, and / or neural network processing unit (NPU), etc. Different processing units may be independent devices or integrated into one or more processors.

[0060] The controller can be the nerve center and command center of the electronic device 100. The controller can generate operation control signals according to the instruction opcode and timing signals to complete the control of fetching and executing instructions.

[0061] The processor 110 may also include a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. This memory can store instructions or data that the processor 110 has just used or that are used repeatedly. If the processor 110 needs to use the instruction or data again, it can retrieve it directly from the memory. This avoids repeated accesses, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.

[0062] In some embodiments, the processor 110 may include one or more interfaces. Interfaces may include an inter-integrated circuit (I2C) interface, an inter-integrated circuit sound (I2S) interface, a pulse code modulation (PCM) interface, a universal asynchronous receiver / transmitter (UART) interface, a mobile industry processor interface (MIPI), a general-purpose input / output (GPIO) interface, a subscriber identity module (SIM) interface, and / or a universal serial bus (USB) interface, etc.

[0063] The wireless communication function of electronic device 100 can be realized through antenna 1, antenna 2, mobile communication module 150, wireless communication module 160, modem processor and baseband processor, etc.

[0064] Antenna 1 and antenna 2 are used to transmit and receive electromagnetic wave signals. Each antenna in electronic device 100 can be used to cover one or more communication frequency bands. Different antennas can also be multiplexed to improve antenna utilization. For example, antenna 1 can be multiplexed as a diversity antenna for a wireless local area network. In some other embodiments, the antennas can be used in conjunction with tuning switches.

[0065] The mobile communication module 150 can provide solutions for wireless communication, including 2G / 3G / 4G / 5G, applied to the electronic device 100. The mobile communication module 150 may include at least one filter, switch, power amplifier, low noise amplifier (LNA), etc. The mobile communication module 150 can receive electromagnetic waves via antenna 1, and perform filtering, amplification, and other processing on the received electromagnetic waves before transmitting them to a modem processor for demodulation. The mobile communication module 150 can also amplify the signal modulated by the modem processor and convert it into electromagnetic waves for radiation via antenna 1.

[0066] The modem processor may include a modulator and a demodulator. The modulator modulates the low-frequency baseband signal to be transmitted into a mid-to-high frequency signal. The demodulator demodulates the received electromagnetic wave signal into a low-frequency baseband signal. The demodulator then transmits the demodulated low-frequency baseband signal to the baseband processor for processing. After processing by the baseband processor, the low-frequency baseband signal is transmitted to the application processor. The application processor outputs sound signals through audio devices (not limited to speaker 170A, receiver 170B, etc.) or displays images or videos through the display screen 194.

[0067] The wireless communication module 160 can provide solutions for wireless communication applications on the electronic device 100, including wireless local area networks (WLAN) (such as wireless fidelity (Wi-Fi) networks), Bluetooth (BT), global navigation satellite system (GNSS), frequency modulation (FM), near field communication (NFC), and infrared (IR) technologies. The wireless communication module 160 can be one or more devices integrating at least one communication processing module. The wireless communication module 160 receives electromagnetic waves via antenna 2, performs frequency modulation and filtering of the electromagnetic wave signals, and sends the processed signal to processor 110. The wireless communication module 160 can also receive signals to be transmitted from processor 110, perform frequency modulation and amplification, and convert them into electromagnetic waves for radiation via antenna 2.

[0068] In some embodiments, antenna 1 of electronic device 100 is coupled to mobile communication module 150, and antenna 2 is coupled to wireless communication module 160, enabling electronic device 100 to communicate with networks and other devices via wireless communication technology. The wireless communication technology may include Global System for Mobile Communications (GSM), General Packet Radio Service (GPRS), Code Division Multiple Access (CDMA), Wideband Code Division Multiple Access (WCDMA), Time-Division Code Division Multiple Access (TD-SCDMA), Long Term Evolution (LTE), BT, GNSS, WLAN, NFC, FM, and / or IR technologies, etc. The GNSS may include the Global Positioning System (GPS), the Global Navigation Satellite System (GLONASS), the BeiDou Navigation Satellite System (BDS), the Quasi-Zenith Satellite System (QZSS), and / or satellite-based augmentation systems (SBAS).

[0069] Electronic device 100 implements display functions through a GPU, a display screen 194, and an application processor. The GPU is a microprocessor for image processing, connected to the display screen 194 and the application processor. The GPU is used to perform mathematical and geometric calculations and for graphics rendering. Processor 110 may include one or more GPUs, which execute program instructions to generate or modify display information.

[0070] Display screen 194 is used to display images, videos, etc. Display screen 194 includes a display panel. The display panel can be a liquid crystal display (LCD), an organic light-emitting diode (OLED), an active-matrix organic light-emitting diode (AMOLED), a flexible light-emitting diode (FLED), a Mini LED, a MicroLED, a Micro-OLED, a quantum dot light-emitting diode (QLED), etc.

[0071] Electronic device 100 can perform shooting functions through ISP, camera 193, video codec, GPU, display 194 and application processor.

[0072] The ISP (Image Signal Processor) is used to process data fed back from the camera. For example, when taking a picture, the shutter is opened, and light is transmitted through the lens to the camera's image sensor. The light signal is converted into an electrical signal, and the image sensor transmits the electrical signal to the ISP for processing, transforming it into an image visible to the naked eye. The ISP can also perform algorithmic optimizations on image noise and brightness.

[0073] Camera 193 is used to capture still images or videos. An object passes through the lens, generating an optical image that is projected onto a photosensitive element. This photosensitive element can be a charge-coupled device (CCD) or a complementary metal-oxide-semiconductor (CMOS) phototransistor. The photosensitive element converts the light signal into an electrical signal, which is then passed to an ISP (Image Signal Processor) for conversion into a digital image signal. The ISP outputs the digital image signal to a DSP (Digital Signal Processor) for further processing. The DSP converts the digital image signal into standard RGB, YUV, or other image formats.

[0074] Digital signal processors (DSPs) are used to process digital signals. Besides digital image signals, they can also process other digital signals. For example, when electronic device 100 selects a frequency, the DSP can perform Fourier transforms on the frequency energy.

[0075] Video codecs are used to compress or decompress digital video. Electronic device 100 may support one or more video codecs. Thus, electronic device 100 can play or record videos in various encoding formats, such as Moving Picture Experts Group (MPEG) 1, MPEG2, MPEG3, MPEG4, etc.

[0076] An NPU (Neural Processing Unit) is a computational processor for neural networks (NNs). By borrowing the structure of biological neural networks, such as the transmission patterns between neurons in the human brain, it can rapidly process input information and continuously learn on its own. NPUs enable intelligent cognitive applications in electronic devices, such as image recognition, facial recognition, speech recognition, and text understanding.

[0077] The external storage interface 120 can be used to connect an external memory card, such as a Micro SD card, to expand the storage capacity of the electronic device 100. The external memory card communicates with the processor 110 through the external storage interface 120 to perform data storage functions. For example, music, video, and other files can be saved on the external memory card.

[0078] Internal memory 121 can be used to store one or more computer programs, which include instructions. Processor 110 can execute the instructions stored in internal memory 121. Internal memory 121 may include a program storage area and a data storage area. The program storage area may store an operating system; it may also store one or more applications (such as a gallery, contacts, etc.). The data storage area may store data created during the use of electronic device 101 (such as photos, contacts, etc.). In addition, internal memory 121 may include high-speed random access memory and may also include non-volatile memory, such as one or more disk storage components, flash memory components, universal flash storage (UFS), embedded multimedia card (eMMC), etc. In some embodiments, processor 110 can execute instructions stored in internal memory 121 and / or instructions stored in memory disposed in processor 110 to cause electronic device 101 to perform the methods provided in the embodiments of this application, as well as other applications and data processing. Electronic device 100 can implement audio functions such as music playback and recording through audio module 170, speaker 170A, receiver 170B, microphone 170C, headphone jack 170D, and application processor.

[0079] Before introducing the embodiments of this application, let’s first introduce the concepts related to the embodiments of this application.

[0080] ArkTS (Ark TypeScript)

[0081] ArkTS is a development language for the HarmonyOS system, based on and extended from TypeScript. ArkTS provides capabilities such as a declarative UI paradigm and state management support, enabling developers to create applications in a simpler and more natural way. It maintains the basic syntax of TypeScript and strengthens static analysis and checking through standardized methods to detect more errors during development before runtime, improving code robustness and achieving better performance.

[0082] C++

[0083] C++ is a general-purpose object-oriented programming language. While retaining the efficiency and flexibility of C, it introduces features such as object-oriented programming, generic programming, and exception handling. It can be widely used in the development of systems, application software, games, as well as in high-performance servers, client applications, real-time systems, embedded firmware, and other fields.

[0084] Cross-language calls

[0085] Cross-language calls refer to the use of code written in multiple programming languages ​​within a single program, allowing these codes to call and interact with each other. In the development of the HarmonyOS system, cross-language calls between ArkTS and C / C++ are a common requirement.

[0086] Node Application Programming Interface (NAPI)

[0087] NAPI is a set of C++ APIs provided by Node.js for writing native extension modules for Node.js. In the HarmonyOS system, NAPI functionality can be used to call C++ libraries. In scenarios where ArkTS calls C++, after loading the NAPI object, developers can access its properties and call its functions at the ArkTS layer.

[0088] Profile-guided optimization (PGO)

[0089] Point-of-Go (PGO) is a commonly used optimization technique. For ArkTS source code, data can be collected before compilation to obtain information, and this information can be used to optimize the compilation process, improving program performance. This collected information can be presented as intermediate files to optimize the compilation process. The process of using collected information to optimize the compilation process is called PGO. It can also be understood as collecting data during the interpretation and execution of ArkTS source code, obtaining data, and then using this data to guide optimization of the compilation process to obtain an optimized program.

[0090] Ahead-of-time (AOT) compilation

[0091] AOT (Ahead-of-Time) is a compilation technique that refers to the process of compiling high-level language code into machine code before the program runs. In the case of ArkTS source code, sampling during the interpreted execution process provides information that can guide the optimization of the AOT phase.

[0092] SO Library

[0093] SO refers to Shared Object Files, a binary file format used to store executable code and data of programs.

[0094] Crawling prototype chain

[0095] Climbing the prototype chain refers to the process of searching upwards along an object's prototype chain for a property or method. The prototype chain is a mechanism for implementing inheritance and property sharing, allowing objects to share properties and methods. Every object has a prototype object. When accessing a property or method of an object, if the object itself does not define that property or method, the search can proceed upwards along the prototype chain until the prototype object that defines the property or method is found.

[0096] ArkTS source code files can include objects, as well as their properties or methods. After defining properties or methods (functions) for an object in an ArkTS source code file, the corresponding properties or methods (functions) in C++ can be invoked using the cross-language calling capabilities provided by NAPI.

[0097] Currently, cross-language calls between ArkTS and C++ are quite cumbersome. After developers load NAPI objects, accessing properties and making function calls requires various validations (e.g., type checking) and prototype chain crawling, which consumes a significant amount of time.

[0098] Therefore, this application provides a calling method, a calling device, and a computer device. By creating NAPI objects in the ArkTS engine and leveraging the PGO type information collection mechanism within the ArkTS engine, type collection of NAPI objects is added. At the AOT (Ahead-of-Time) stage, the collected information from PGO (e.g., type information, loop count, branch weight, etc.) guides AOT compilation optimization, enabling fast path processing of NAPI objects. This improves the performance of operations such as object attribute access and function calls, enhances the efficiency of cross-language calls, improves the execution efficiency of code files, and ultimately enhances the developer's user experience.

[0099] The following section, with reference to the accompanying drawings, provides a detailed description of a method for invoking this application.

[0100] Figure 2 shows a schematic flowchart of a method invocation process, which mainly involves the ArkTS layer and the ArkTS engine. The ArkTS engine is primarily used for the underlying execution of the method invocation in this application.

[0101] It is easy to understand that the calling method provided in this application mainly includes a module initialization stage and a function call stage.

[0102] The module initialization phase includes:

[0103] S201, Import NAPI objects in the ArkTS layer.

[0104] For example, during the module initialization phase, the ArkTS source code file imports a NAPI object, which is pre-created in the ArkTS engine.

[0105] S202, calling NAPI objects in the ArkTS engine.

[0106] When importing NAPI objects into the ArkTS source code files, the NAPI objects need to be called from the SO library through the ArkTS engine's interface.

[0107] For example, the ArkTS source code engine can load module information. Upon the first invocation of the NAPI object, the SO library is loaded via the ModuleManager to trigger module registration, and module initialization is performed via the Native module.

[0108] S203, the ArkTS engine sends feedback information.

[0109] For example, after the ArkTS engine completes module initialization, it can send feedback information to the ArkTS layer. The feedback information may include the NAPI object associated with the initialized module to indicate that the module initialization is complete.

[0110] For example, after completing the module initialization process, the function call phase can begin, which includes:

[0111] S204, the ArkTS layer calls the ArkTS function.

[0112] S205, the ArkTS engine feeds back the call result to the ArkTS layer.

[0113] Understandably, during the function call phase, it is possible to call NAPI functions in the C++ source code file.

[0114] It's easy to understand that the import operations of NAPI objects in the developer's ArkTS source code files, as well as the access to properties and function calls of NAPI objects in the ArkTS layer after the developer loads the NAPI objects, are all executed in the underlying ArkTS engine.

[0115] It should be noted that NAPI provides cross-language calling between ArkTS and C++ modules. When accessing properties and making function calls to NAPI objects at the ArkTS layer, developers need to set properties and methods (functions) for the NAPI objects in the C++ source code file.

[0116] When developers perform cross-language code calls, they often use NAPI to call existing C++ libraries. NAPI's underlying implementation calls the ArkTS engine, allowing these objects to be treated as regular objects and optimized for accessing properties and making function calls. The ArkTS engine can utilize PGO's data collection information and return ArkTS's data collection and optimizations of NAPI objects during AOT compilation, thereby improving code execution efficiency.

[0117] Figure 3 shows a schematic flowchart of a calling method provided in an embodiment of this application. Based on the ArkTS engine's support for PGO and AOT technologies, this method may include:

[0118] S301 uses PGO to acquire collected information.

[0119] For example, the ArkTS source code file is split to obtain bytecode files. During the PGO phase, information (e.g., type information) is collected during the interpretation and execution of the ArkTS source code file.

[0120] It should be noted that the collected information can be stored in a specific information file in a specific format.

[0121] Understandably, NAPI objects need to be isolated from ordinary objects (e.g., object instances) before the collected information is obtained.

[0122] For ease of understanding, Figure 4 illustrates a schematic diagram of isolating NAPI objects from ordinary objects. The left side of Figure 4 shows the IHC (instance hidden class) structure of an instance (object, Obj.). Traversing from the root node of Obj.IHC, we can obtain the child nodes under the root node of Obj.IHC, each node corresponding to an Hclass. Copying the root node of Obj.IHC results in the root node of NAPIObj.IHC shown on the right side of Figure 4. Similarly, traversing this node yields the child nodes under the root node of NAPIObj.IHC. The copied NAPIObj.IHC replaces the original Obj.IHC, thus achieving isolation between NAPIObj.IHC and Obj.IHC, i.e., isolation between NAPI objects and ordinary objects.

[0123] For example, NAPI obj.instance.hclass is copied from obj.instance hclass, and NAPI obj.instance.hclass overrides the original obj.instance.hclass.

[0124] In simple terms, the scope of `obj.instance.hclass` is larger than that of `NAPI obj.instance.hclass`. During the PGO phase, only information about `NAPI obj.instance.hclass` objects (e.g., type information) is collected. This avoids collecting too much information, conserves content, and ensures that key information is not lost, thus improving the efficiency of information acquisition.

[0125] It should be noted that after isolating NAPI objects from ordinary objects, NAPI obj.instance.hclass can be added to the ROOT set, thereby collecting information from the NAPI objects in the ROOT set and storing the collected information in a specific information file in a specific format.

[0126] S302 optimizes AOT compilation by collecting information.

[0127] For example, the collected information in the specific information file obtained in step S301 above is read and then used to guide the compilation and execution of the bytecode file in the AOT stage.

[0128] Specifically, the transition tree of the NAPI object can be reconstructed based on the collected information, and the reconstructed NAPI obj.instance.hclass can be serialized and stored in a snapshot.

[0129] The transition tree is generated during AOT compilation. The restored NAPI obj.instance.hclass is serialized and stored in a snapshot, which makes it convenient for the hclass generated during AOT compilation to enter the fast path at runtime by parsing the snapshot.

[0130] It should be noted that the NAPI transition tree can represent the migration process and path of NAPI objects.

[0131] For example, NAPI's transition tree is as follows:

[0132] The `testNapi` above represents the original NAPI object. To distinguish it from the original NAPI object, attributes can be added. For example, adding an `x` attribute results in the `testNapi.x` object; adding a `y` attribute results in the `testNapi.y` object. Adding attributes to an object can also be understood as a migration process, and there is no limit to the number of times attributes can be added. For example, adding a `z` attribute to the `testNapi.x` object results in the `testNapi.z` object.

[0133] It should be noted that a new hlcass will be obtained each time a migration occurs.

[0134] For example, the information collected during the PGO phase can be the x, y, and z attributes of the testNapi object in the aforementioned transition tree. Each node in the aforementioned transition tree can correspond to an hclass, and serializing and storing the NAPI obj.instance.hclass in a snapshot can also be understood as serializing and storing each node in the aforementioned transition tree in a snapshot.

[0135] S303 runs the machine code compiled by AOT.

[0136] For example, at runtime, the hclass object in the snapshot is retrieved and replaced with the original NAPI obj.instance.hclass.

[0137] It should be noted that the hclass generated during AOT compilation allows for fast path resolution at runtime by parsing snapshots. Ultimately, this fast code executes to access NAPI object properties and make function calls.

[0138] For example, the following is an example of an ArkTS source code file:

[0139] In the ArkTS source code file mentioned above, the statement testNapi.ark2CppKong() on line 5 is used to access the properties of the testNapi object in C++ and to call its functions.

[0140] It is understandable that if the calling method provided in this application embodiment is not used, during the execution of the above-mentioned ArkTS source code file, the information of the NAPI object cannot be collected in the PGO phase. When frequently loading attributes in the For-Loop, the overhead of more checks and prototype chain crawling can only be achieved through the slow path. However, by using the calling method provided in this application embodiment, during the execution of the above-mentioned ArkTS source code file, the information of the NAPI object is recorded in the PGO phase, and in the AOT phase, the transition tree of the NAPI object is restored using the information collected in the PGO phase. After optimization using AOT technology, when loading attributes, the corresponding hclass can be found in the restored transition tree. By directly loading the hclass, attribute access and function calls can be achieved through the fast path, reducing the overhead of checking and prototype chain crawling through the slow path, improving the efficiency of cross-language calls, and enhancing the user experience.

[0141] Figure 5 shows a schematic flowchart of a calling method provided in an embodiment of this application. This method can be applied to computer devices and can be executed in the ArkTS engine. The method is described in detail below.

[0142] S501, determine the collection information of one or more NAPI objects based on the first source code file.

[0143] For example, the first source code file can be an ArkTS code file. The information collected from one or more NAPI objects may include at least one of the following: type information, loop count, and branch weight. The information from one or more NAPI objects may include at least one of the following: attributes of one or more NAPI objects, and methods (functions) of one or more NAPI objects.

[0144] It is understandable that during the PGO phase, the collected information (e.g., type information) is obtained by interpreting and executing the first source code file. The first source code file may include NAPI objects and ordinary objects. In the calling method provided in this application embodiment, the collected information of NAPI objects is obtained by interpreting and executing the first source code file.

[0145] For example, the collected information can be stored in a specific information file in a specific format.

[0146] It should be noted that when obtaining information during the PGO phase, NAPI objects need to be isolated from ordinary objects.

[0147] For example, the first source code file is compiled to obtain the hidden class of the first object; the hidden classes of one or more NAPI objects are determined based on the hidden class of the first object; and the collection information of the hidden classes of one or more NAPI objects is obtained.

[0148] For example, the first object can be a regular object, and the hidden class of the first object can be obj.instance hclass. The hidden class of the NAPI object can be NAPI obj.instance.hclass. NAPI obj.instance.hclass is obtained by copying obj.instance hclass, and NAPI obj.instance.hclass overrides the original obj.instance.hclass.

[0149] In simple terms, the scope of `obj.instance.hclass` is larger than that of `NAPI obj.instance.hclass`. During the PGO phase, only information about `NAPI obj.instance.hclass` objects (e.g., type information) is collected. This avoids collecting too much information, conserves content, and ensures that key information is not lost, thus improving the efficiency of information acquisition.

[0150] Furthermore, the hidden classes of one or more NAPI objects can be added to the first data set; and the collection information of the hidden classes of one or more NAPI objects in the first data set can be obtained.

[0151] For example, the first data set is the ROOT set. After isolating NAPI objects from ordinary objects, NAPI obj.instance.hclass can be added to the ROOT set, thereby collecting information from the NAPI objects in the ROOT set, reducing memory usage while improving the efficiency of obtaining collected information.

[0152] S502 generates a machine code file based on the first source code file and the collected information from one or more NAPI objects.

[0153] It should be noted that the information collected from one or more NAPI objects can be used to guide the compilation and execution of the first source code file during the AOT phase. After compilation and execution, an executable machine code file will be obtained.

[0154] For example, a migration tree of one or more NAPI objects is determined based on the collected information of one or more NAPI objects. The migration tree of one or more NAPI objects includes at least one node, and the at least one node corresponds to the hidden class of one or more NAPI objects. The migration tree of one or more NAPI objects is stored in a first memory. A machine code file is generated based on a first source code file and the migration tree of one or more NAPI objects.

[0155] For example, the transition tree of the NAPI object is reconstructed based on the collected information of the NAPI object, and the reconstructed NAPI obj.instance.hclass is serialized and stored in a snapshot. This allows the hclass generated during AOT compilation to enter the fast path at runtime by parsing the snapshot. Nodes in the transition tree can be NAPI objects with different attributes. The process of adding attributes to a NAPI object can be understood as a migration process. Each migration results in a new hclass. Each node in the transition tree corresponds to an hclass.

[0156] Storing the migration tree of one or more NAPI objects in the first memory can be understood as serializing and storing the hidden class of one or more NAPI objects corresponding to the nodes in the migration tree of one or more NAPI objects in a snapshot.

[0157] S503 runs the machine code file and obtains information about one or more NAPI objects from the second source code file.

[0158] For example, at runtime, a fast path is determined by calling the first memory, and the machine code file is run through the fast path.

[0159] Calling the first memory can be understood as retrieving hclass from the snapshot and replacing the original NAPI obj.instance.hclass.

[0160] It should be noted that the hclass generated during AOT compilation allows for fast path resolution at runtime by parsing snapshots. Ultimately, this fast code executes to access NAPI object properties and make function calls.

[0161] Based on the above scheme, during the PGO phase, the collected information of the NAPI object is recorded, and during the AOT phase, the collected information obtained in the PGO phase is used to reconstruct the transition tree of the NAPI object. After optimization using AOT technology, when loading properties, the corresponding hclass can be found in the reconstructed transition tree. By directly loading the hclass, property access and function calls are achieved through a fast path, reducing the overhead of checking and crawling the prototype chain through a slow path, improving the efficiency of cross-language calls, and enhancing the user experience.

[0162] The above describes the calling method provided by the embodiments of this application in conjunction with Figures 2 to 5. The calling device provided by the embodiments of this application will be described below in conjunction with Figures 6 and 7.

[0163] It is understood that, in order to achieve the functions in the above method embodiments, the apparatuses in Figures 6 and 7 include hardware structures and / or software modules corresponding to the execution of each function. Those skilled in the art should readily realize that, in conjunction with the units and method steps of the various examples described in the embodiments disclosed in this application, this application can be implemented in hardware or a combination of hardware and computer software. Whether a function is executed in hardware or by computer software driving hardware depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0164] This application embodiment can divide the device into functional modules according to the above method embodiment. For example, each function can be divided into a separate functional module, or two or more functions can be integrated into one module. The above modules can be implemented in hardware or in software functional modules. It should be noted that the module division in this application embodiment is illustrative and is only a logical functional division. In actual implementation, there may be other division methods.

[0165] Figure 6 shows a schematic diagram of the composition of the calling device 600 provided in an embodiment of this application. As shown in Figure 6, the calling device 600 includes: an acquisition unit 610 and a processing unit 620.

[0166] It should be noted that all relevant content of each step involved in the above method embodiments can be referenced from the functional description of the corresponding functional module, and will not be repeated here. The calling device 600 provided in this application embodiment is used to execute the method described above, and therefore can achieve the same effect as the method described above.

[0167] Figure 7 shows a schematic diagram of the composition of the calling device provided in an embodiment of this application. As shown in Figure 7, the calling device 700 includes a processor 710. The processor 710 is coupled to a memory 730, which is used to store instructions. When the calling device 700 is used to implement the method described above, the processor 710 is used to execute the instructions in the memory 730 to implement the function of the processing unit 520 described above.

[0168] Optionally, the calling device 700 also includes a memory 730.

[0169] Optionally, the calling device 700 further includes an interface circuit 720. The processor 710 and the interface circuit 720 are coupled to each other. It is understood that the interface circuit 720 can be a transceiver or an input / output interface. When the calling device 700 is used to implement the method described above, the processor 710 executes instructions to implement the function of the processing unit 620, and the interface circuit 720 implements the function of the acquisition unit 610.

[0170] This application also provides an electronic device, including a processor, a memory, an application program, and a computer program. The aforementioned devices can be connected via one or more communication buses. The one or more computer programs are stored in the memory and configured to be executed by the one or more processors. The one or more computer programs include instructions that can be used to cause the electronic device to perform the steps in the above method embodiments.

[0171] For example, the processor may specifically be the processor 110 shown in FIG1, and the memory may specifically be the internal memory 120 shown in FIG1 and / or the external memory connected to the electronic device.

[0172] Figure 8 illustrates a computer device 800 provided in an embodiment of this application. As shown, the computer device 800 includes at least one processor 810 and a transceiver 820. The processor 810 is coupled to a memory 830 and is used to execute instructions stored in the memory to control the transceiver 820 to transmit and / or receive signals.

[0173] Optionally, the computer device 800 also includes a memory 830 for storing instructions.

[0174] In some embodiments, the processor 810 and the memory 830 can be combined into a single processing device, with the processor 810 executing program code stored in the memory 830 to implement the aforementioned functions. In specific implementations, the memory 830 can be integrated into the processor 810 or independent of the processor 810.

[0175] In some embodiments, transceiver 820 may include a receiver and a transmitter.

[0176] The transceiver 820 may further include an antenna, and the number of antennas may be one or more. The transceiver 820 may be a communication interface or an interface circuit.

[0177] When the computer device 800 is a chip, the chip includes a transceiver module and a processing module. The transceiver module can be an input / output circuit or a communication interface; the processing module can be a processor, microprocessor, or integrated circuit integrated on the chip.

[0178] This application also provides a chip, which includes a processor and a communication interface. The communication interface is used to receive signals and transmit the signals to the processor. The processor processes the signals so that the calling method or parsing method described in any of the possible implementations above is executed.

[0179] This embodiment also provides a computer-readable storage medium storing computer instructions. When the computer instructions are executed on an electronic device, the electronic device performs the aforementioned method steps to implement the calling method or parsing method in the above embodiment.

[0180] This embodiment also provides a computer program product that, when run on a computer, causes the computer to perform the aforementioned related steps to implement the calling method or parsing method in the above embodiment.

[0181] In addition, embodiments of this application also provide an apparatus, which may specifically be a chip, component or module. The apparatus may include a connected processor and a memory; wherein the memory is used to store computer execution instructions, and when the apparatus is running, the processor may execute the computer execution instructions stored in the memory to cause the chip to execute the calling method or parsing method in the above method embodiments.

[0182] This application also provides a system that includes any of the devices provided in the above embodiments.

[0183] The explanations and beneficial effects of the relevant contents in any of the devices provided above can be found in the corresponding method embodiments provided above, and will not be repeated here.

[0184] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementation should not be considered beyond the scope of this application.

[0185] Those skilled in the art will understand that, for the sake of convenience and brevity, the specific working processes of the systems, devices, and units described above can be referred to the corresponding processes in the foregoing method embodiments, and will not be repeated here.

[0186] In the several embodiments provided in this application, it should be understood that the disclosed systems, apparatuses, and methods can be implemented in other ways. For example, the apparatus embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between apparatuses or units may be electrical, mechanical, or other forms.

[0187] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0188] In addition, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0189] If the aforementioned functions are implemented as software functional units and sold or used as independent products, they can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, or a portion of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0190] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application. Therefore, the scope of protection of this application should be determined by the scope of the claims.

Claims

1. A calling method, characterized by, The method includes: Based on the first source code file, the acquisition information of one or more node application programming interface (NAPI) objects is determined. The first source code file includes a first code statement, which is used to instruct the invocation of the information of the one or more NAPI objects in the second source code file. Generate a machine code file based on the first source code file and the collected information of one or more NAPI objects; Running the machine code file yields information about one or more NAPI objects in the second source code file.

2. The method of claim 1, wherein, The step of determining the collection information of one or more node application programming interface (NAPI) objects based on the first source code file includes: Compile the first source code file to obtain the hidden class of the first object; The hidden class of the one or more NAPI objects is determined based on the hidden class of the first object; Obtain the collection information of the hidden classes of the one or more NAPI objects.

3. The method of claim 2, wherein, The acquisition of information about the hidden classes of the one or more NAPI objects includes: Add the hidden class of the one or more NAPI objects to the first data set; Obtain the collection information of the hidden classes of one or more NAPI objects in the first data set.

4. The method according to any one of claims 1 to 3, characterized in that, The step of generating a machine code file based on the first source code file and the collected information of the one or more NAPI objects includes: Based on the collected information of the one or more NAPI objects, a migration tree of the one or more NAPI objects is determined. The migration tree of the one or more NAPI objects includes at least one node, and the at least one node corresponds to the hidden class of the one or more NAPI objects. The migration tree of the one or more NAPI objects is stored in the first memory; The machine code file is generated based on the first source code file and the migration tree of the one or more NAPI objects.

5. The method of claim 4, wherein, The process of running the machine code file includes: At runtime, the fast path is determined by calling the first memory location; The machine code file is run via the fast path.

6. The method according to any one of claims 1 to 5, characterized in that, The information of the one or more NAPI objects includes at least one of the following: The properties of the one or more NAPI objects, and the methods of the one or more NAPI objects.

7. The method according to any one of claims 1 to 6, characterized in that, The first source code file is an Ark TypeScript code file.

8. The method according to any one of claims 1 to 7, characterized in that, The information collected from one or more NAPI objects includes at least one of the following: type information, number of loops, and branch weight.

9. An electronic device, comprising: include: One or more processors; One or more memory units; The one or more memories store one or more computer programs, the one or more computer programs including instructions that, when executed by the one or more processors, cause the electronic device to perform the method as described in any one of claims 1 to 8.

10. A computer device, comprising: It includes a processor and a memory, the memory being used to store program instructions, and the processor being used to invoke the program instructions to perform the method of any one of claims 1 to 7.

11. A calling device, characterized in that A module for implementing the method of any of claims 1 to 8.

12. A computer-readable storage medium, characterized in that, A computer program stored on a computer readable medium, which when executed by a computer, causes the method of any of claims 1 to 8 to be implemented.

13. A computer program product, characterised in that, A computer program which, when executed by a processor, implements the method of any of claims 1 to 8.