CN116719609A - Performance optimization method of JavaScript engine - Google Patents
Performance optimization method of JavaScript engine Download PDFInfo
- Publication number
- CN116719609A CN116719609A CN202310778162.7A CN202310778162A CN116719609A CN 116719609 A CN116719609 A CN 116719609A CN 202310778162 A CN202310778162 A CN 202310778162A CN 116719609 A CN116719609 A CN 116719609A
- Authority
- CN
- China
- Prior art keywords
- script
- pcram
- common
- file
- scripts
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
- 238000000034 method Methods 0.000 title claims abstract description 36
- 238000005457 optimization Methods 0.000 title claims abstract description 10
- 238000013515 script Methods 0.000 claims abstract description 141
- 230000015654 memory Effects 0.000 claims abstract description 37
- 230000007246 mechanism Effects 0.000 description 7
- 230000008859 change Effects 0.000 description 5
- 230000008569 process Effects 0.000 description 5
- 238000010586 diagram Methods 0.000 description 3
- 230000009286 beneficial effect Effects 0.000 description 2
- 230000004044 response Effects 0.000 description 2
- 238000007619 statistical method Methods 0.000 description 2
- 238000004422 calculation algorithm Methods 0.000 description 1
- 238000004364 calculation method Methods 0.000 description 1
- 239000012634 fragment Substances 0.000 description 1
- 238000012986 modification Methods 0.000 description 1
- 230000004048 modification Effects 0.000 description 1
- 238000004064 recycling Methods 0.000 description 1
- 230000001360 synchronised effect Effects 0.000 description 1
Classifications
-
- Y—GENERAL TAGGING OF NEW TECHNOLOGICAL DEVELOPMENTS; GENERAL TAGGING OF CROSS-SECTIONAL TECHNOLOGIES SPANNING OVER SEVERAL SECTIONS OF THE IPC; TECHNICAL SUBJECTS COVERED BY FORMER USPC CROSS-REFERENCE ART COLLECTIONS [XRACs] AND DIGESTS
- Y02—TECHNOLOGIES OR APPLICATIONS FOR MITIGATION OR ADAPTATION AGAINST CLIMATE CHANGE
- Y02D—CLIMATE CHANGE MITIGATION TECHNOLOGIES IN INFORMATION AND COMMUNICATION TECHNOLOGIES [ICT], I.E. INFORMATION AND COMMUNICATION TECHNOLOGIES AIMING AT THE REDUCTION OF THEIR OWN ENERGY USE
- Y02D10/00—Energy efficient computing, e.g. low power processors, power management or thermal management
Abstract
The invention relates to a performance optimization method of a JavaScript engine, which comprises the steps of accessing PCRAM into embedded Internet of things terminal equipment, and storing a complete JavaScript file in an external memory; when a terminal application program runs, statistics is carried out on calling frequency information of JavaScript scripts, common scripts are determined, and the common scripts are stored in a PCRAM; when the script is executed, the processor judges whether the loaded script file is a common file, if so, the script file is read from the PCRAM, otherwise, the script file is read from an external memory. According to the method, the storage management of the JavaScript engine is optimized, the execution efficiency and the system performance of the JavaScript engine are improved, and the method is suitable for application scenes of embedded Internet of things terminal equipment.
Description
Technical Field
The invention relates to the field of nonvolatile memories and file management systems, in particular to a performance optimization method of a JavaScript engine.
Background
JavaScript (JS) can handle multiple tasks simultaneously and allow multiple devices to respond to the same event without explicit allocation or release of memory, has the potential to respond to event and asynchronous code execution, illustrates that the JS engine can cause efficient execution of scripts in internet of things (Internet of things, ioT) end applications, and is thus well suited for IoT solution development. With the increase of the use of JS in the internet of things terminal, the performance optimization of the embedded JS engine becomes more and more important, and due to the application requirement of the lightweight internet of things, a large number of JS scripts cannot be stored, so how to achieve the best comprehensive performance between the execution speed and the required storage space is a problem in the development process of the JS engine.
In the traditional JS engine execution process, the JS script is stored in an external memory under the limitation of the memory capacity of the terminal of the Internet of things, and a script file is required to be loaded and analyzed from the external memory each time the JS script is executed, so that additional expenditure is generated, and the response speed and the resource utilization rate of the system are influenced.
Disclosure of Invention
The invention aims to provide a performance optimization method of a JavaScript engine by introducing PCRAM storage into embedded Internet of things terminal equipment.
In order to achieve the above purpose, the invention adopts the following technical scheme:
a JavaScript engine performance optimization method includes:
accessing PCRAM into the terminal equipment of the embedded Internet of things, and storing a complete JavaScript file in an external memory;
when a terminal application program runs, counting calling frequency information of JavaScript scripts in a period of time, determining a common script, and storing the common script into a PCRAM;
when the script is executed, the processor judges whether the loaded script file is a common file, if so, the script file is read from the PCRAM, otherwise, the script file is read from an external memory.
As a preferred embodiment, the PCRAM data/address lines are connected to the processor data/address lines through latches.
As a preferred embodiment, the processor controls the read/write operations of the PCRAM through the EXMC while the script loader loads/stores the common script files.
As a preferable implementation mode, the JavaScript engine records the calling frequency information of the script in a period of time, and the processor determines the common script according to the calling frequency in the period of time.
As a preferred embodiment, when the script content in the external memory changes and the script is a common script in PCRAM, the corresponding common script in PCRAM is synchronously modified.
As a preferred implementation mode, the method further comprises continuously counting the calling frequency information of the JavaScript script, and when a new common script is generated, storing the new common script into the PCRAM.
As a preferred embodiment, the method further comprises: and sorting importance of the common scripts, and dynamically adjusting the storage sequence of script files in the PCRAM based on the importance of the common scripts. Preferably, the importance of the common script is determined according to the calling frequency in a period of time, and the higher the calling frequency in a period of time is, the higher the importance is. The script files are different in size, so that the script files stored in the PCRAM can be changed when the common scripts are changed, different scripts can be stored in the original script storage positions after updating, the problem that the allocated memory size is unsuitable can be generated at the moment, the common scripts are stored according to the importance ordering sequence, and the storage strategies are dynamically adjusted when the scripts are updated, so that the generation of storage information coverage or storage fragments can be avoided.
As a preferred embodiment, the method further comprises replacing the stored common script file based on a least recently used policy when PCRAM memory is insufficient.
As a preferred implementation mode, the method further comprises the steps of allocating corresponding memory space for script execution in PCRAM, and recycling the memory which is not used any more after the script execution is finished.
Compared with the prior art, the invention has the following beneficial effects:
1) The execution efficiency of the script is improved: the conventional JS script is preloaded into the high-speed PCRAM memory, so that repeated loading and analysis expenditure caused by loading the script file from the external memory during each execution are avoided, the time expenditure is reduced, the loading and execution processes of the script are accelerated, and the overall script execution efficiency is improved. PCRAM is a fast read-write, nonvolatile memory that maintains data integrity after the system is powered up again. And the conventional JS script file is loaded into the PCRAM, so that the loading and analyzing cost can be reduced, and the rapid access of the conventional script can be realized.
2) Dynamically managing common scripts: the method has the advantages that the calling frequency of the script in a period of time is analyzed through statistics, the change of the common script is monitored, the storage sequence of script files in the PCRAM cache is dynamically adjusted according to importance, the common script is ensured to be quickly accessed and occupy proper storage space, and therefore the execution efficiency of the script is further improved, and the memory management of the PCRAM is optimized.
3) The synchronicity of script loading and execution is realized: and the common script file is loaded into the PCRAM from the external memory in time through a dynamic updating mechanism, so that the synchronism of the common script file between the PCRAM and the external memory is maintained, the latest common script is ensured to be executed in time, and the stability and the flexibility of the system are improved.
4) The method is suitable for a system environment with limited resources: the optimization method is very beneficial to application scenes with higher performance requirements in the embedded system, and particularly under the environment of limited resources, the execution performance of the JS engine and the overall response capability of the system can be obviously improved.
Drawings
FIG. 1 is a diagram of an overall architecture according to an embodiment of the present invention.
FIG. 2 is a diagram showing steps for implementing the present invention.
Fig. 3 is a schematic diagram of hardware connection between PCRAM and an embedded internet of things terminal device.
Description of the embodiments
The technical scheme of the invention is further described below with reference to the attached drawings and the specific embodiments.
The performance optimization method of the JavaScript engine is suitable for the embedded Internet of things terminal equipment and is used for improving the execution efficiency of JavaScript scripts and optimizing memory management. The overall architecture is shown in fig. 1, the flow of the method is shown in fig. 2, and the method specifically comprises the following steps:
(1) PCRAM storage is introduced into the embedded Internet of things terminal equipment and is used as a storage area special for storing common JavaScript. The PCRAM has higher reading and writing speeds, has low reading power consumption and is nonvolatile, the loading and executing processes of the script can be accelerated, and the analysis and executing speed of the JavaScript script can not be influenced by the loading of the common script after the power is turned off and restarted.
As shown in FIG. 3, the processor in this embodiment employs a 32-bit chip of a RISC-V architecture of GD32 series. The 16-bit data/address lines of the GD32 chip are respectively connected to the data lines and the address lines of the PCRAM through two latches, and the PCRAM_ALE signal controls the latching of the multiplexing of the data/address buses. The other EXMC pins are directly connected with the corresponding pins of the PCRAM. When the script loader needs to load/store a common script file, the processor controls read/write operations of the PCRAM through the EXMC. The complete Javascript script file is stored in the external memory, and the common script in the external memory is selected to make calculation decisions through the processor, and is synchronized and updated with the common script of the PCRAM.
(2) In the JS engine, calling frequency information of the script in the last period of time is recorded, and the processor performs statistical analysis according to the information, identifies and determines a common script, and loads the common script into the PCRAM.
The PCRAM previously allocates a suitable memory space for script execution.
Specifically, the processor may determine the common script through a pre-designed threshold, and identify the script as the common script when the frequency of use of the script over a period of time exceeds the pre-designed threshold.
The threshold value determination can be combined with the comprehensive determination of PCRAM capacity, statistical analysis of the use frequency, script file size and other information, or the threshold value can be redetermined according to the script file with the lowest calling frequency in the PCRAM after the PCRAM capacity is exceeded.
Preferably, the processor sorts the commonly used scripts by importance after identifying the commonly used scripts. And after ordering the common scripts according to importance, storing script files in PCRAM according to the importance sequence.
An alternative implementation is to determine the importance of the common script by using the call frequency in a period of time, wherein the higher the call frequency is, the higher the importance is. The storage sequence of script files in the PCRAM cache is dynamically adjusted according to the importance, so that the common scripts can be ensured to be accessed quickly and occupy proper storage space.
(3) When the script is executed, the processor judges whether the loaded script file is a common file, if so, the script file is read from the PCRAM through the script loader, otherwise, the script file is read from the external memory. The script loader is responsible for acquiring the script file from the PCRAM and analyzing and executing the script file through the JS engine. Because PCRAM has a faster access speed and low power consumption for reading, the time and power consumption overhead can be reduced and the execution efficiency can be improved relative to loading script files from an external memory.
And after the script is executed, timely recovering the memory which is not used any more, and improving the memory utilization rate and the system performance.
The method of the invention comprises a dynamic update mechanism, namely: in the script execution process, the change of the common script is monitored in real time, wherein the change comprises the content change of the script file and the increase of the script file. When the content of the common script of the PCRAM changes or a new common script file needs to be added into the PCRAM, the dynamic updating mechanism detects the change and loads the corresponding script file into the PCRAM from the external memory, thereby ensuring the synchronism of the script file in the PCRAM and the external memory.
The method of the present invention also includes cache management of PCRAM. Specifically, the method comprises a cache updating mechanism and a cache replacing mechanism.
Cache update mechanism: when the storage area of the JavaScript script is not full, adding the JavaScript script into the PCRAM according to the calling frequency in the latest time period and sorting the importance of the JavaScript script;
cache replacement mechanism: when the storage area of the JavaScript script is full, a Least Recently Used (LRU) algorithm is adopted as a cache replacement strategy, so that the most commonly used script file is ensured to be reserved preferentially, and the script file is managed according to the cache strategy.
When the conventional script stored in the PCRAM changes or is replaced and the required storage space is not equal to the original conventional script, the conventional script needs to be ordered and mapped to the address according to the importance of the conventional script, and the appropriate storage space is allocated to the script in the PCRAM, and the unused storage space is timely recovered, so that the storage utilization rate of the PCRAM and the system performance are improved.
The above embodiments and drawings are only for illustrating the present invention and are not to be construed as limiting the invention; thus, while the invention has been described in detail with reference to the various embodiments described above, it will be understood by those skilled in the art that the invention may be modified or equivalents; all technical solutions and modifications thereof that do not depart from the spirit and scope of the present invention are intended to be included in the scope of the appended claims.
Claims (10)
1. The performance optimization method of the JavaScript engine is characterized by comprising the following steps of:
accessing PCRAM into the terminal equipment of the embedded Internet of things, and storing a complete JavaScript file in an external memory;
when a terminal application program runs, counting calling frequency information of JavaScript scripts in a period of time, determining a common script, and storing the common script into a PCRAM;
when the script is executed, the processor judges whether the loaded script file is a common file, if so, the script file is read from the PCRAM, otherwise, the script file is read from an external memory.
2. The method of claim 1, wherein the PCRAM data/address lines are coupled to the processor data/address lines through latches.
3. The method of claim 2, wherein the processor controls read/write operations of the PCRAM through an external memory controller (EXMC) when the script loader loads/stores the common script file.
4. The method of claim 1, wherein the JavaScript engine records call frequency information of the script over a period of time, and the processor determines the common script based on the call frequency over the period of time.
5. The method of claim 1, wherein when the script content in the external memory changes and the script is a regular script in PCRAM, then synchronously modifying the corresponding regular script in PCRAM.
6. The method of claim 1, further comprising continuously counting call frequency information of JavaScript scripts, and when generating new frequently used scripts, storing the newly added frequently used scripts in PCRAM.
7. The method of claim 4, further comprising ordering importance of the common scripts and dynamically adjusting the order of storage of script files in PCRAM based on the importance of the common scripts.
8. The method of claim 7, wherein the importance of the common script is determined by the frequency of calls over a period of time, the higher the importance.
9. The method of claim 1, further comprising replacing the stored common script file based on a least recently used policy when PCRAM memory space is insufficient.
10. The method of claim 1, further comprising allocating corresponding memory space for script execution in PCRAM and reclaiming unused memory after script execution is completed.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310778162.7A CN116719609A (en) | 2023-06-29 | 2023-06-29 | Performance optimization method of JavaScript engine |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN202310778162.7A CN116719609A (en) | 2023-06-29 | 2023-06-29 | Performance optimization method of JavaScript engine |
Publications (1)
Publication Number | Publication Date |
---|---|
CN116719609A true CN116719609A (en) | 2023-09-08 |
Family
ID=87864446
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN202310778162.7A Pending CN116719609A (en) | 2023-06-29 | 2023-06-29 | Performance optimization method of JavaScript engine |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN116719609A (en) |
-
2023
- 2023-06-29 CN CN202310778162.7A patent/CN116719609A/en active Pending
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US20200004692A1 (en) | Cache replacing method and apparatus, heterogeneous multi-core system and cache managing method | |
US9081702B2 (en) | Working set swapping using a sequentially ordered swap file | |
US6205519B1 (en) | Cache management for a multi-threaded processor | |
US7653799B2 (en) | Method and apparatus for managing memory for dynamic promotion of virtual memory page sizes | |
US7389506B1 (en) | Selecting processor configuration based on thread usage in a multiprocessor system | |
CN109471594B (en) | M L C flash memory read-write method | |
US10261918B2 (en) | Process running method and apparatus | |
CN113377291B (en) | Data processing method, device, equipment and medium of cache equipment | |
US9569381B2 (en) | Scheduler for memory | |
CN109508301A (en) | Terminal, using the processing method of data, data processing equipment and storage medium | |
CN110968269A (en) | SCM and SSD-based key value storage system and read-write request processing method | |
US8972629B2 (en) | Low-contention update buffer queuing for large systems | |
EP1605360B1 (en) | Cache coherency maintenance for DMA, task termination and synchronisation operations | |
CN108664577B (en) | File management method and system based on FLASH idle area | |
CN110059024B (en) | Memory space data caching method and device | |
US5678024A (en) | Method and system for dynamic performance resource management within a computer based system | |
CN108664217B (en) | Caching method and system for reducing jitter of writing performance of solid-state disk storage system | |
US20060236065A1 (en) | Method and system for variable dynamic memory management | |
CN111522659B (en) | Space use method and device | |
US8990537B2 (en) | System and method for robust and efficient free chain management | |
CN116719609A (en) | Performance optimization method of JavaScript engine | |
CN115576863A (en) | Data reading and writing method, storage device and storage medium | |
US11023374B2 (en) | Apparatus and method and computer program product for controlling data access | |
CN116048377A (en) | Data processing method of solid state disk and related equipment | |
CN108572924B (en) | Request processing method of 3D MLC flash memory device |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination |