WO2022099459A1 - Webassembly loading method and apparatus, and storage medium - Google Patents

Webassembly loading method and apparatus, and storage medium Download PDF

Info

Publication number
WO2022099459A1
WO2022099459A1 PCT/CN2020/127814 CN2020127814W WO2022099459A1 WO 2022099459 A1 WO2022099459 A1 WO 2022099459A1 CN 2020127814 W CN2020127814 W CN 2020127814W WO 2022099459 A1 WO2022099459 A1 WO 2022099459A1
Authority
WO
WIPO (PCT)
Prior art keywords
content
file
wasm
string
build
Prior art date
Application number
PCT/CN2020/127814
Other languages
French (fr)
Chinese (zh)
Inventor
熊智
马健
温书豪
赖力鹏
Original Assignee
深圳晶泰科技有限公司
Priority date (The priority date 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 date listed.)
Filing date
Publication date
Application filed by 深圳晶泰科技有限公司 filed Critical 深圳晶泰科技有限公司
Priority to PCT/CN2020/127814 priority Critical patent/WO2022099459A1/en
Publication of WO2022099459A1 publication Critical patent/WO2022099459A1/en

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F9/00Arrangements for program control, e.g. control units
    • G06F9/06Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
    • G06F9/44Arrangements for executing specific programs
    • G06F9/445Program loading or initiating

Definitions

  • the invention belongs to the technical field of WebAssembly loading, and in particular relates to a WebAssembly loading method, device and storage medium.
  • WebAssembly can run code faster on web applications, which has the following characteristics: File loading - WebAssembly files are smaller in size, so downloads are faster.
  • Parsing - Decoding WebAssembly is faster than parsing JavaScript.
  • Re-optimization - WebAssembly code does not need to be re-optimized because the compiler has enough information to get the correct code on the first run.
  • Execution - Execution can be faster, with WebAssembly instructions closer to machine code.
  • Garbage collection - Currently WebAssembly does not directly support garbage collection, garbage collection is manually controlled, so it is more efficient than automatic garbage collection.
  • WebAssembly was officially incorporated into the W3C standard in December 2019, and its application in the front-end field has gradually become popular.
  • the mainstream application method in the industry is: compile the C++ source code into the wasm file and the middle-layer build.js file through the emscripten compiler; Layer build.js file; the build.js file completes the loading of wasm through network requests; in this way, WebAssembly is loaded in web applications.
  • the present invention provides a modularized WebAssembly construction process, including the following steps:
  • the emscripten compiler compiles the C++ source code into the wasm file and the middle layer build.js file;
  • A2 read the binary content of the wasm file, compress the content, and then convert it into a hexadecimal string
  • A3 read the content of build.js in the middle layer and merge it with the converted wasm string
  • A4 encapsulate, inject automatic decompression code in front of the merged string
  • the existing technology is used for compiling, and the compiling tool used is the "emscripten compiler”.
  • the function of the encapsulation code is the reverse process of A2: extract the compressed content from the hexadecimal, and then decompress it.
  • the content obtained after decompression is the original binary content of the wasm file, and the wasm binary
  • the content is assigned to the Module global variable.
  • the merging is to add the encapsulated code or string to the front of the build.js content or string, and then save it as a local file, that is, build the generated file, that is, step A5.
  • the present invention also provides a loading process of WebAssembly, including the following steps:
  • the automatic decompression code encapsulated at the time of construction will be automatically run, and the wasm content will be decompressed and instantiated to complete the loading process.
  • the parsing is automatically completed by the browser.
  • the browser will automatically parse and execute the content of the javascript file
  • the browser executes "build the generated file"
  • it first executes the code encapsulated in step A4: first extracts the compressed content from the hexadecimal string, and then decompresses the compressed content to obtain the wasm binary content , and assign it to the Module global variable.
  • This process completes the decompression and executes the "build generated file", the "intermediate layer build.js" code compiled and generated by emscripten will be executed, and the middle layer will determine whether the wasm binary content already exists in the Module global variable. If it does not exist, load the wasm binary content through the http network, and instantiate it after the loading is complete; if it exists, directly use the wasm binary content in the Module global variable for instantiation.
  • the instantiation method is provided by the web browser.
  • the intermediate layer code will directly use the binary content for instantiation. Complete the loading process.
  • the middle-tier code "build.js" can directly use the wasm binary content extracted from the package, and does not require additional HTTP network requests to load the wasm binary content. Therefore, the web application only needs to deploy the "build-generated (javascript) file” together.
  • the "build-generated (javascript) file” can also be built into the web single-page file together without deployment. wasm binary file, which realizes the decoupling of web application and wasm file.
  • the present invention also provides a WebAssembl loading device, comprising:
  • Compile module use emscripten compiler to compile C++ source code into wasm file and middle layer build.js file;
  • the first reading module read the binary content of the wasm file, compress the content, and then convert it into a hexadecimal string;
  • the second reading module read the content of build.js in the middle layer and merge it with the converted wasm string;
  • Processing module encapsulate, inject automatic decompression code in front of the merged string
  • Save module Save the encapsulated string content to a local file.
  • a loading device includes a memory, a processor, and a computer program stored on the memory and running on the processor, and the processor implements the loading method of the present invention when the processor executes the computer program.
  • the merged target file can be independently published and deployed as a module; during the parsing and loading process, the middle layer code "build.js" can be directly extracted from the package using
  • the wasm binary content does not require additional HTTP network requests to load the wasm binary content. Therefore, the web application only needs to deploy the "build-generated (javascript) file” together.
  • the "build-generated (javascript) file” can also be built into the web single-page file together without deployment. wasm binary file, which realizes the decoupling of web application and wasm file.
  • the present invention is compatible with the Web, Electron, and Node operating environments, and the combined modules are introduced in the same way.
  • “same method” refers to the method of loading the wasm binary.
  • the wasm binary content is loaded separately through the http network, and on the node side, the wasm binary content is obtained by reading a local file. Therefore, it is necessary to deploy the wasm binary file in different ways for different operating environments, that is, deploy the wasm file to the web server in the web/electron environment, and deploy the wasm file to the corresponding file directory in the node environment.
  • Figure 1 shows the loading process of the prior art.
  • FIG. 2 shows the loading process of the prior art.
  • Figure 3 illustrates the construction of the method.
  • Figure 4 is a loading process in the method of the present invention.
  • Figure 3 illustrates the construction of the method.
  • First use the emscripten compiler to compile the C++ source code into the wasm file and the middle-tier build.js file. Read the binary content of the wasm file, compress the content, and convert it to a hexadecimal string. Read the middle layer build.js content and merge it with the converted wasm string. Then encapsulate and inject automatic decompression code in front of the merged string. Save the encapsulated string content to a local file to complete the entire build process.
  • Figure 4 illustrates the loading process. After the built generated file is loaded into the web browser, it will be parsed and executed. During the execution process, the automatic decompression code encapsulated during construction will be automatically run, and the wasm content will be decompressed and instantiated to complete the loading process.
  • RDKit is a suite of open source chemical informatics software that supports the manipulation, modification and format conversion of molecules.
  • 2D images of a batch of chemical molecules need to be displayed on the human-computer interface.
  • the RDKit tool was used in the project to convert the raw data of chemical molecules into 2D image data for display on the human-computer interface.
  • the technical scheme described in the method is adopted, and the concrete steps are as follows:
  • the human-computer interaction software converts the chemical molecule data into 2D images through the instantiated rdkit, and displays them on the interface;
  • Crystal Database is a set of report visualization software.
  • the visual interface displays the reported molecular statistics charts and molecular 3D views to the user.
  • the software runs in the WEB browser environment.
  • the force algorithm library is used in the project to convert the raw data of chemical molecules into a 3D visual data structure.
  • the visualization software converts the chemical molecule data into 3D visualization data through the instantiated theforce, and displays it in 3D on the interface;
  • the XRD client is a set of software for the visualization of X-ray diffraction files (referred to as XRD files).
  • the xrdio third-party open source library is used in the project to convert the original data of different types of xrd files into a common data structure for easy display.
  • the technical solution described in the method is adopted, and the specific steps are as follows:
  • the visualization software converts the original data of different types of xrd files into a common data structure through the instantiated xrdio, and displays them in the overlapping view and parallel view;

Landscapes

  • Engineering & Computer Science (AREA)
  • Software Systems (AREA)
  • Theoretical Computer Science (AREA)
  • Physics & Mathematics (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Devices For Executing Special Programs (AREA)

Abstract

A WebAssembly loading method and apparatus, and a storage medium, comprising the following steps: A1: compiling a c++ source code into a wasm file and a middle-layer build.js file by using an emscripten compiler; A2: reading binary content of the wasm file, compressing the content, and converting the compressed content into a hexadecimal character string; A3: reading middle-layer build.js content, and merging same with a converted wasm character string; A4: performing encapsulation, and adding automatic decompression code in front of the merged character string; A5: storing encapsulated character string content to a local file, thereby completing the whole building process.

Description

一种WebAssembly加载方法、装置及存储介质A WebAssembly loading method, device and storage medium 技术领域technical field
本发明属于WebAssembly加载技术领域,尤其涉及一种WebAssembly加载方法、装置及存储介质。The invention belongs to the technical field of WebAssembly loading, and in particular relates to a WebAssembly loading method, device and storage medium.
背景技术Background technique
使用WebAssembly可以更快地在web应用上运行代码,其有如下特点:文件加载-WebAssembly文件体积更小,所以下载速度更快。Using WebAssembly can run code faster on web applications, which has the following characteristics: File loading - WebAssembly files are smaller in size, so downloads are faster.
解析-解码WebAssembly比解析JavaScript要快。Parsing - Decoding WebAssembly is faster than parsing JavaScript.
编译和优化-编译和优化所需的时间较少,因为在将文件推送到服务器之前已经进行了更多优化,JavaScript需要为动态类型多次编译代码。Compilation and optimization - Less time is required for compilation and optimization because more optimizations are already done before the file is pushed to the server, JavaScript needs to compile the code multiple times for dynamic types.
重新优化-WebAssembly代码不需要重新优化,因为编译器有足够的信息可以在第一次运行时获得正确的代码。Re-optimization - WebAssembly code does not need to be re-optimized because the compiler has enough information to get the correct code on the first run.
执行-执行可以更快,WebAssembly指令更接近机器码。Execution - Execution can be faster, with WebAssembly instructions closer to machine code.
垃圾回收-目前WebAssembly不直接支持垃圾回收,垃圾回收都是手动控制的,所以比自动垃圾回收效率更高。Garbage collection - Currently WebAssembly does not directly support garbage collection, garbage collection is manually controlled, so it is more efficient than automatic garbage collection.
WebAssembly在2019年12月正式纳入W3C标准,在前端领域的应用逐渐普及,业界主流的应用方法为:通过emscripten编译器将c++源码编译到wasm文件和中间层build.js文件;Web应用中引入中间层build.js文件;build.js文件内部通过网络请求完成wasm的加载;以此实现web应用中加载WebAssembly。WebAssembly was officially incorporated into the W3C standard in December 2019, and its application in the front-end field has gradually become popular. The mainstream application method in the industry is: compile the C++ source code into the wasm file and the middle-layer build.js file through the emscripten compiler; Layer build.js file; the build.js file completes the loading of wasm through network requests; in this way, WebAssembly is loaded in web applications.
已有技术的加载过程如图1和图2所示,以上方法存在的不足:对前端模块化兼容性不好,不能将wasm文件与web应用完全解耦,对于单页面web应用(SPA),需要将wasm文件单独拆出,与静态文件部署到同级目录下。操作繁琐,且通过网络单独异步请求wasm文件的速度受网络环境影响较大,不利于开发体验和用户体验。The loading process of the prior art is shown in Figure 1 and Figure 2. The shortcomings of the above methods: the compatibility of the front-end modularization is not good, and the wasm file cannot be completely decoupled from the web application. For a single-page web application (SPA), You need to separate the wasm file and deploy it to the same directory as the static file. The operation is cumbersome, and the speed of asynchronously requesting the wasm file through the network is greatly affected by the network environment, which is not conducive to the development experience and user experience.
发明内容SUMMARY OF THE INVENTION
为了解决以上技术问题,本发明提供了一种模块化的WebAssembly的构建过程,包括如下几个步骤:In order to solve the above technical problems, the present invention provides a modularized WebAssembly construction process, including the following steps:
A1,emscripten编译器将c++源码编译到wasm文件和中间层build.js文件;A1, the emscripten compiler compiles the C++ source code into the wasm file and the middle layer build.js file;
A2,读取wasm文件二进制内容,压缩内容,再转换为十六进制字符串;A2, read the binary content of the wasm file, compress the content, and then convert it into a hexadecimal string;
A3,读取中间层build.js内容,与转换后的wasm字符串合并;A3, read the content of build.js in the middle layer and merge it with the converted wasm string;
A4,进行封装,在合并的字符串前面注入自动解压代码;A4, encapsulate, inject automatic decompression code in front of the merged string;
A5,将封装后的字符串内容保存到本地文件,完成整个构建过程。A5, save the encapsulated string content to a local file to complete the entire construction process.
其中,使用的现有技术进行编译的,使用的编译工具就是“emscripten编译器”。Among them, the existing technology is used for compiling, and the compiling tool used is the "emscripten compiler".
优选的,所述步骤A4中,封装代码的作用就是A2的反向过程:从十六进制提取出压缩内容,再解压,解压后得到的内容即为wasm文件原始的二进制内容,将wasm二进制内容赋值给Module全局变量。Preferably, in the step A4, the function of the encapsulation code is the reverse process of A2: extract the compressed content from the hexadecimal, and then decompress it. The content obtained after decompression is the original binary content of the wasm file, and the wasm binary The content is assigned to the Module global variable.
优选的,所述步骤A4中,合并就是将封装的代码或字符串添加到build.js内容或字符串前面,然后保存为本地文件,也就是构建生成的文件,即步骤A5。Preferably, in the step A4, the merging is to add the encapsulated code or string to the front of the build.js content or string, and then save it as a local file, that is, build the generated file, that is, step A5.
相应的,本发明还提供了一种WebAssembly的加载过程,包括如下步骤:Correspondingly, the present invention also provides a loading process of WebAssembly, including the following steps:
B1,构建的生成文件被加载到web浏览器后,会进行解析执行;B1, after the built generated file is loaded into the web browser, it will be parsed and executed;
B2,执行过程中会自动运行构建时封装的自动解压代码,进行wasm内容的解压和实例化,完成加载过程。B2, during the execution process, the automatic decompression code encapsulated at the time of construction will be automatically run, and the wasm content will be decompressed and instantiated to complete the loading process.
优选的,所述步骤B1中,解析是浏览器自动完成的,当“构建生成的javascript文件”被加载到浏览器后,浏览器会自动解析并执行该javascript文件的内容Preferably, in the step B1, the parsing is automatically completed by the browser. After the "constructed javascript file" is loaded into the browser, the browser will automatically parse and execute the content of the javascript file
优选的,所述浏览器执行“构建生成的文件”时,首先会执行步骤A4中封装的代码:先从十六进制字符串中提取出压缩内容,然后将压缩内容解压,得到wasm二进制内容,并赋值给Module全局变量。此过程完成解压,执行完“构建生成的文件”后,会执行emscripten编译生成的“中间层build.js”代码,该中间层会判断Module全局变量中是否已经存在wasm二进制内容。如果不存在,则通过http网络加载wasm二进制内容,加载完成之后再进行实例化;如果存在,则直接使用Module全局变量中的wasm二进制内容进行实例化。实例化的方法是WEB浏览器自带的。Preferably, when the browser executes "build the generated file", it first executes the code encapsulated in step A4: first extracts the compressed content from the hexadecimal string, and then decompresses the compressed content to obtain the wasm binary content , and assign it to the Module global variable. This process completes the decompression and executes the "build generated file", the "intermediate layer build.js" code compiled and generated by emscripten will be executed, and the middle layer will determine whether the wasm binary content already exists in the Module global variable. If it does not exist, load the wasm binary content through the http network, and instantiate it after the loading is complete; if it exists, directly use the wasm binary content in the Module global variable for instantiation. The instantiation method is provided by the web browser.
由于所述步骤A4中,已经将wasm二进制内容存入到Module全局变量,所以中间层代码会直接使用该二进制内容进行实例化。完成加载过程。在解析和加载过程中,中间层代码“build.js”可以直接使用从封装中提取的wasm二进制内容,不需要额外通过http网络请求去加载wasm二进制内容。所以web应用只需要将“构建生成的(javascript)文件”部署到 一起即可,对于单页面WEB应用还可以将“构建生成的(javascript)文件”一起构建到web单页面文件中,不需要部署wasm二进制文件,这样实现了web应用与wasm文件的解耦。Since the wasm binary content has been stored in the Module global variable in the step A4, the intermediate layer code will directly use the binary content for instantiation. Complete the loading process. During the parsing and loading process, the middle-tier code "build.js" can directly use the wasm binary content extracted from the package, and does not require additional HTTP network requests to load the wasm binary content. Therefore, the web application only needs to deploy the "build-generated (javascript) file" together. For a single-page web application, the "build-generated (javascript) file" can also be built into the web single-page file together without deployment. wasm binary file, which realizes the decoupling of web application and wasm file.
本发明还提供一种WebAssembl加载装置,包括:The present invention also provides a WebAssembl loading device, comprising:
编译模块:采用emscripten编译器将c++源码编译到wasm文件和中间层build.js文件;Compile module: use emscripten compiler to compile C++ source code into wasm file and middle layer build.js file;
第一读取模块:读取wasm文件二进制内容,压缩内容,再转换为十六进制字符串;The first reading module: read the binary content of the wasm file, compress the content, and then convert it into a hexadecimal string;
第二读取模块:读取中间层build.js内容,与转换后的wasm字符串合并;The second reading module: read the content of build.js in the middle layer and merge it with the converted wasm string;
处理模块:进行封装,在合并的字符串前面注入自动解压代码;Processing module: encapsulate, inject automatic decompression code in front of the merged string;
保存模块:将封装后的字符串内容保存到本地文件。Save module: Save the encapsulated string content to a local file.
一种存储介质,其上存储有计算机程序,所述计算机程序被处理器执行时实现本发明所述的加载方法。A storage medium on which a computer program is stored, and when the computer program is executed by a processor, implements the loading method of the present invention.
一种加载装置,包括存储器、处理器及存储在所述存储器上并可在处理器上运行的计算机程序,所述处理器执行所述计算机程序时实现本发明所述的加载方法。A loading device includes a memory, a processor, and a computer program stored on the memory and running on the processor, and the processor implements the loading method of the present invention when the processor executes the computer program.
本发明带来了如下有益效果:The present invention brings following beneficial effects:
1.通过将wasm文件与构建的目标文件的合并,可以将合并后的目标文件作为模块独立发布与部署;在解析和加载过程中,中间层代码“build.js”可以直接使用从封装中提取的wasm二进制内容,不需要额外通过http网络请求去加载wasm二进制内容。所以web应用只需要将“构建生成的(javascript)文件”部署到一起即可,对于单页面WEB应用还可以将“构建生成的(javascript)文件”一起构建到web单页面文件中,不需要部署wasm二进制文件,这样实现了web应用与wasm文件的解耦。1. By merging the wasm file and the built target file, the merged target file can be independently published and deployed as a module; during the parsing and loading process, the middle layer code "build.js" can be directly extracted from the package using The wasm binary content does not require additional HTTP network requests to load the wasm binary content. Therefore, the web application only needs to deploy the "build-generated (javascript) file" together. For a single-page web application, the "build-generated (javascript) file" can also be built into the web single-page file together without deployment. wasm binary file, which realizes the decoupling of web application and wasm file.
2.去除了单独网络请求wasm文件的过程,提升了加载速度。2. The process of requesting wasm files from a separate network is removed, which improves the loading speed.
3.本发明兼容Web端、Electron端、Node端运行环境,均以相同方式引入合并后的模块。此处“相同方法”指的是加载wasm二进制文件的方法。对于已有技术:在web/electron端是通过http网络单独加载wasm二进制内容的,在node端是通过读取本地文件来获取wasm二进制内容的。所以需要针对不同的运行环境以不同的方式部署wasm二进制文件,即:在web/electron环境下将wasm文件部署到web服务器,在node环境下将wasm文件部署到对应的文件目录下。3. The present invention is compatible with the Web, Electron, and Node operating environments, and the combined modules are introduced in the same way. Here "same method" refers to the method of loading the wasm binary. For the existing technology: on the web/electron side, the wasm binary content is loaded separately through the http network, and on the node side, the wasm binary content is obtained by reading a local file. Therefore, it is necessary to deploy the wasm binary file in different ways for different operating environments, that is, deploy the wasm file to the web server in the web/electron environment, and deploy the wasm file to the corresponding file directory in the node environment.
4.对于本发明的方法:由于wasm二进制文件已经封装到“构建生成的文件”中,而构建生成的文件可以直接被其他js调用或者合并到其他js文件,不需要针对不同环境做不同的部署。4. For the method of the present invention: Since the wasm binary file has been encapsulated into the "build-generated file", and the build-generated file can be directly called by other js or merged into other js files, there is no need to do different deployments for different environments .
附图说明Description of drawings
图1是已有技术的加载过程。Figure 1 shows the loading process of the prior art.
图2是已有技术的加载过程。Figure 2 shows the loading process of the prior art.
图3说明了该方法的构建过程。Figure 3 illustrates the construction of the method.
图4是本发明的方法中的加载过程。Figure 4 is a loading process in the method of the present invention.
具体实施方式Detailed ways
下面结合附图,对本发明的较优的实施例作进一步的详细说明:Below in conjunction with the accompanying drawings, the preferred embodiments of the present invention are described in further detail:
图3说明了该方法的构建过程。首先,使用emscripten编译器将c++源码编译到wasm文件和中间层build.js文件。读取wasm文件二进制内容,压缩内容,再转换为十六进制字符串。读取中间层build.js内容,与转换后的wasm字符串合并。再进行封装,在合并的字符串前面注入自动解压代码。将封装后的字符串内容保存到本地文件,完成整个构建过程。Figure 3 illustrates the construction of the method. First, use the emscripten compiler to compile the C++ source code into the wasm file and the middle-tier build.js file. Read the binary content of the wasm file, compress the content, and convert it to a hexadecimal string. Read the middle layer build.js content and merge it with the converted wasm string. Then encapsulate and inject automatic decompression code in front of the merged string. Save the encapsulated string content to a local file to complete the entire build process.
图4说明了加载过程。构建的生成文件被加载到web浏览器后,会进行解析执行,执行过程中会自动运行构建时封装的自动解压代码,进行wasm内容的解压和实例化,完成加载过程。Figure 4 illustrates the loading process. After the built generated file is loaded into the web browser, it will be parsed and executed. During the execution process, the automatic decompression code encapsulated during construction will be automatically run, and the wasm content will be decompressed and instantiated to complete the loading process.
实施例1Example 1
RDKit是一套开源的化学信息软件,支持分子的操作、修改和格式转换。在XFEP和通用力场项目中,需要将一批化学分子的2D图像展示到人机交互界面上。项目中使用了RDKit工具,将化学分子的原始数据转换为2D图像数据,以便在人机交互界面进行展示。实施过程中,采用了该方法所述的技术方案,具体步骤如下:RDKit is a suite of open source chemical informatics software that supports the manipulation, modification and format conversion of molecules. In the XFEP and Universal Force Field projects, 2D images of a batch of chemical molecules need to be displayed on the human-computer interface. The RDKit tool was used in the project to convert the raw data of chemical molecules into 2D image data for display on the human-computer interface. In the implementation process, the technical scheme described in the method is adopted, and the concrete steps are as follows:
1.使用emscripten编译器将RDKit的c++源码编译到rdkit.wasm文件和中间层build.js文件;1. Use the emscripten compiler to compile the c++ source code of RDKit into the rdkit.wasm file and the middle layer build.js file;
2.读取rdkit.wasm文件二进制内容,压缩内容,再转换为十六进制字符串;2. Read the binary content of the rdkit.wasm file, compress the content, and then convert it to a hexadecimal string;
3.读取中间层build.js内容,与转换后的wasm字符串合并;3. Read the content of build.js in the middle layer and merge it with the converted wasm string;
4.进行封装,在合并的字符串前面注入自动解压代码;4. Encapsulate and inject automatic decompression code in front of the merged string;
5.将封装后的字符串内容保存为本地文件rdkit.js,完成整个构建过程;5. Save the encapsulated string content as a local file rdkit.js to complete the entire construction process;
6.将构建生产的文件(rdkit.js)与人机交互界面软件代码(前端代码)一起部署到生产环境(用户个人电脑);6. Deploy the production file (rdkit.js) together with the human-computer interface software code (front-end code) to the production environment (user PC);
7.当用户打开人机交互软件时,rdkit.js被加载到软件中并自动执行;7. When the user opens the human-computer interaction software, rdkit.js is loaded into the software and executed automatically;
8.执行rdkit.js后,rdkit.wasm内容被解压和提取出来,并进行实例化;8. After executing rdkit.js, the content of rdkit.wasm is decompressed and extracted, and instantiated;
9.人机交互软件通过实例化的rdkit来将化学分子数据转换为2D图像,并在界面上进行展示;9. The human-computer interaction software converts the chemical molecule data into 2D images through the instantiated rdkit, and displays them on the interface;
10.以上是从构建wasm到加载使用的过程。10. The above is the process from building wasm to loading and using it.
实施例2Example 2
晶体数据库是一套报告可视化软件,可视化界面向用户展示报告的分子统计图表和分子3D视图,软件运行在WEB浏览器环境。项目中使用了theforce算法库,将化学分子的原始数据转换为3D可视化数据结构。实施过程中,采用了该方法所述的技术方案,具体步骤如下:Crystal Database is a set of report visualization software. The visual interface displays the reported molecular statistics charts and molecular 3D views to the user. The software runs in the WEB browser environment. The force algorithm library is used in the project to convert the raw data of chemical molecules into a 3D visual data structure. In the implementation process, the technical solution described in the method is adopted, and the specific steps are as follows:
1.使用emscripten编译器将theforce的c++源码编译到theforce.wasm文件和中间层build.js文件;1. Use the emscripten compiler to compile theforce's C++ source code into theforce.wasm file and the middle layer build.js file;
2.读取theforce.wasm文件二进制内容,压缩内容,再转换为十六进制字符串;2. Read the binary content of theforce.wasm file, compress the content, and then convert it into a hexadecimal string;
3.读取中间层build.js内容,与转换后的wasm字符串合并;3. Read the content of build.js in the middle layer and merge it with the converted wasm string;
4.进行封装,在合并的字符串前面注入自动解压代码;4. Encapsulate and inject automatic decompression code in front of the merged string;
5.将封装后的字符串内容保存为本地文件theforce.js,完成整个构建过程;5. Save the encapsulated string content as a local file theforce.js to complete the entire construction process;
6.将构建生产的文件(thefroce.js)与可视化界面软件代码(前端代码)一起部署到生产环境(WEB服务器);6. Deploy the production file (thefroce.js) together with the visual interface software code (front-end code) to the production environment (WEB server);
7.当用户通过浏览器访问晶体数据库网站时,可视化界面软件和 thefroce.js被加载到浏览器并自动执行;7. When the user accesses the crystal database website through the browser, the visual interface software and thefroce.js are loaded into the browser and executed automatically;
8.执行theforce.js后,theforce.wasm内容被解压和提取出来,并进行实例化;8. After executing theforce.js, the content of theforce.wasm is decompressed and extracted, and instantiated;
9.可视化软件通过实例化的theforce来将化学分子数据转换为3D可视化数据,并在界面上进行3D展示;9. The visualization software converts the chemical molecule data into 3D visualization data through the instantiated theforce, and displays it in 3D on the interface;
10.以上是从构建wasm到加载使用的过程。10. The above is the process from building wasm to loading and using it.
实施例3:Example 3:
XRD客户端是一套X射线衍射文件(简称XRD文件)可视化的软件,可视化界面向用户展示XRD文件的重叠视图和平行视图,软件运行在用户本地电脑。项目中使用了xrdio第三方开源库,将不同类型的xrd文件的原始数据转换为通用的数据结构,方便展示。实施过程中,采用了该方法所述的技术方案,具体步骤如下:The XRD client is a set of software for the visualization of X-ray diffraction files (referred to as XRD files). The xrdio third-party open source library is used in the project to convert the original data of different types of xrd files into a common data structure for easy display. In the implementation process, the technical solution described in the method is adopted, and the specific steps are as follows:
1.使用emscripten编译器将xrdio的c++源码编译到xrdio.wasm文件和中间层build.js文件;1. Use the emscripten compiler to compile the C++ source code of xrdio into the xrdio.wasm file and the middle layer build.js file;
2.读取xrdio.wasm文件二进制内容,压缩内容,再转换为十六进制字符串;2. Read the binary content of the xrdio.wasm file, compress the content, and then convert it to a hexadecimal string;
3.读取中间层build.js内容,与转换后的wasm字符串合并;3. Read the content of build.js in the middle layer and merge it with the converted wasm string;
4.进行封装,在合并的字符串前面注入自动解压代码;4. Encapsulate and inject automatic decompression code in front of the merged string;
5.将封装后的字符串内容保存为本地文件xrdio.js,完成整个构建过程;5. Save the encapsulated string content as a local file xrdio.js to complete the entire construction process;
6.将构建生产的文件(xrdio.js)与可视化界面软件代码(前端代码)一起部署到生产环境(用户本地电脑);6. Deploy the production file (xrdio.js) together with the visual interface software code (front-end code) to the production environment (user's local computer);
7.当用户打开XRD客户端软件时,可视化界面软件和xrdio.js被加载到客户端并自动执行;7. When the user opens the XRD client software, the visual interface software and xrdio.js are loaded into the client and executed automatically;
8.执行xrdio.js后,xrdio.wasm内容被解压和提取出来,并进行实例化;8. After executing xrdio.js, the content of xrdio.wasm is decompressed and extracted, and instantiated;
9.可视化软件通过实例化的xrdio来将不同类型的xrd文件的原始数据转换为通用的数据结构,并在重叠视图和平行视图展示;9. The visualization software converts the original data of different types of xrd files into a common data structure through the instantiated xrdio, and displays them in the overlapping view and parallel view;
10.以上是从构建wasm到加载使用的过程。10. The above is the process from building wasm to loading and using it.
以上内容是结合具体的优选实施方式对本发明所作的进一步详细说明,不能认定本发明的具体实施只局限于这些说明。对于本发明所属技术领域的普通技术人员来说,在不脱离本发明构思的前提下,还可以做出若干简单推演或替换,都应当视为属于本发明的保护范围。The above content is a further detailed description of the present invention in combination with specific preferred embodiments, and it cannot be considered that the specific implementation of the present invention is limited to these descriptions. For those of ordinary skill in the technical field of the present invention, without departing from the concept of the present invention, some simple deductions or substitutions can be made, which should be regarded as belonging to the protection scope of the present invention.

Claims (10)

  1. 一种WebAssembly的构建过程,其特征在于,包括如下几个步骤:A construction process of WebAssembly, characterized in that it includes the following steps:
    A1:采用emscripten编译器将c++源码编译到wasm文件和中间层build.js文件;A1: Use the emscripten compiler to compile the C++ source code into the wasm file and the middle layer build.js file;
    A2,读取wasm文件二进制内容,压缩内容,再转换为十六进制字符串;A2, read the binary content of the wasm file, compress the content, and then convert it into a hexadecimal string;
    A3,读取中间层build.js内容,与转换后的wasm字符串合并;A3, read the content of build.js in the middle layer and merge it with the converted wasm string;
    A4,进行封装,在合并的字符串前面注入自动解压代码;A4, encapsulate, inject automatic decompression code in front of the merged string;
    A5,将封装后的字符串内容保存到本地文件,完成整个构建过程。A5, save the encapsulated string content to a local file to complete the entire construction process.
  2. 如权利要求1所述的构建过程,其特征在于,所述步骤A4中,封装代码的作用就是A2的反向过程:从十六进制提取出压缩内容,再解压,解压后得到的内容即为wasm文件原始的二进制内容,将wasm二进制内容赋值给Module全局变量。The construction process according to claim 1, wherein, in the step A4, the function of the encapsulation code is the reverse process of A2: extract the compressed content from the hexadecimal, and then decompress it, and the content obtained after decompression is For the original binary content of the wasm file, assign the wasm binary content to the Module global variable.
  3. 如权利要求1所述的构建过程,其特征在于,所述步骤A4中,合并就是将封装的代码或字符串添加至build.js内容或字符串前面。The construction process according to claim 1, wherein, in the step A4, merging is to add the packaged code or string to the front of the build.js content or string.
  4. 一种如权利要求1所述的WebAssembly的加载过程,其特征在于,包括如下步骤:A loading process of WebAssembly as claimed in claim 1, is characterized in that, comprises the steps:
    B1,构建的生成文件被加载到web浏览器后,会进行解析执行;B1, after the built generated file is loaded into the web browser, it will be parsed and executed;
    B2,执行过程中会自动运行构建时封装的自动解压代码,进行wasm内容的解压和实例化。B2, the automatic decompression code encapsulated at build time will be automatically run during the execution process to decompress and instantiate the wasm content.
  5. 如权利要求4所述的加载过程,其特征在于,所述步骤B1中,所述解析是浏览器自动完成的,当“构建生成的javascript文件”被加载到浏览器后,浏览器会自动解析并执行该javascript文件的内容。The loading process according to claim 4, wherein in the step B1, the parsing is automatically completed by the browser, and the browser will automatically parse after the "constructed javascript file" is loaded into the browser and execute the content of that javascript file.
  6. 如权利要求4所述的加载过程,其特征在于,所述浏览器执行“构建生成的文件”时,包括如下几个步骤:The loading process according to claim 4, wherein, when the browser executes "build the generated file", the following steps are included:
    执行步骤A4中封装的代码:先从十六进制字符串中提取出压缩内容;Execute the code encapsulated in step A4: first extract the compressed content from the hexadecimal string;
    将待压缩内容解压,得到wasm二进制内容,并赋值给Module全局变量。Decompress the content to be compressed, get the wasm binary content, and assign it to the Module global variable.
  7. 如权利要求4所述的方法,其特征在于,此过程完成解压,执行完“构建生成的文件”后,会执行emscripten编译生成的中间层代码,所述中间层会判断Module全局变量中是否已经存在wasm二进制内容;若不存在,则通过http网络加载wasm二进制内容,加载完成之后再进行实例化;若存在,则直接使用Module全局变量中的wasm二进制内容进行实例化。The method according to claim 4, characterized in that, after the process is decompressed, and after executing "build the generated file", the middle layer code compiled and generated by emscripten will be executed, and the middle layer will judge whether the module global variable has been The wasm binary content exists; if it does not exist, the wasm binary content is loaded through the http network, and then instantiated after the loading is completed; if it exists, the wasm binary content in the Module global variable is directly used for instantiation.
  8. 一种WebAssembl加载装置,其特征在于,包括:A WebAssembl loading device, comprising:
    编译模块:采用emscripten编译器将c++源码编译到wasm文件和中间层build.js文件;Compile module: use emscripten compiler to compile C++ source code into wasm file and middle layer build.js file;
    第一读取模块:读取wasm文件二进制内容,压缩内容,再转换为十六进制字符串;The first reading module: read the binary content of the wasm file, compress the content, and then convert it into a hexadecimal string;
    第二读取模块:读取中间层build.js内容,与转换后的wasm字符串合并;处理模块:进行封装,在合并的字符串前面注入自动解压代码;The second reading module: reads the content of build.js in the middle layer and merges it with the converted wasm string; processing module: encapsulates and injects automatic decompression code in front of the merged string;
    保存模块:将封装后的字符串内容保存到本地文件。Save module: Save the encapsulated string content to a local file.
  9. 一种存储介质,其上存储有计算机程序,其特征在于,所述计算机程序被处理器执行时实现如权利要求4所述的加载方法。A storage medium on which a computer program is stored, characterized in that, when the computer program is executed by a processor, the loading method according to claim 4 is implemented.
  10. 一种加载装置,包括存储器、处理器及存储在所述存储器上并可在处理器上运行的计算机程序,其特征在于,所述处理器执行所述计算机程序时实现如权利要求4所述的加载方法。A loading device, comprising a memory, a processor and a computer program stored on the memory and running on the processor, wherein the processor implements the computer program according to claim 4 when the processor executes the computer program Load method.
PCT/CN2020/127814 2020-11-10 2020-11-10 Webassembly loading method and apparatus, and storage medium WO2022099459A1 (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
PCT/CN2020/127814 WO2022099459A1 (en) 2020-11-10 2020-11-10 Webassembly loading method and apparatus, and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
PCT/CN2020/127814 WO2022099459A1 (en) 2020-11-10 2020-11-10 Webassembly loading method and apparatus, and storage medium

Publications (1)

Publication Number Publication Date
WO2022099459A1 true WO2022099459A1 (en) 2022-05-19

Family

ID=81601841

Family Applications (1)

Application Number Title Priority Date Filing Date
PCT/CN2020/127814 WO2022099459A1 (en) 2020-11-10 2020-11-10 Webassembly loading method and apparatus, and storage medium

Country Status (1)

Country Link
WO (1) WO2022099459A1 (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116166907A (en) * 2023-04-23 2023-05-26 联动优势电子商务有限公司 Method and device for developing Web application by using WebAsssembly and service page compiling technology

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170346804A1 (en) * 2015-06-02 2017-11-30 ALTR Solutions, Inc. Credential-free user login to remotely executed applications
CN109445773A (en) * 2018-09-27 2019-03-08 深圳点猫科技有限公司 A kind of language based on programming promotes the method and electronic equipment of browser performance
CN110198479A (en) * 2019-05-24 2019-09-03 浪潮软件集团有限公司 A kind of browser audio/video decoding playback method based on webassembly
CN111459463A (en) * 2019-01-21 2020-07-28 中科星图股份有限公司 Algorithm module generation method and linear symbol drawing method

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US20170346804A1 (en) * 2015-06-02 2017-11-30 ALTR Solutions, Inc. Credential-free user login to remotely executed applications
CN109445773A (en) * 2018-09-27 2019-03-08 深圳点猫科技有限公司 A kind of language based on programming promotes the method and electronic equipment of browser performance
CN111459463A (en) * 2019-01-21 2020-07-28 中科星图股份有限公司 Algorithm module generation method and linear symbol drawing method
CN110198479A (en) * 2019-05-24 2019-09-03 浪潮软件集团有限公司 A kind of browser audio/video decoding playback method based on webassembly

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116166907A (en) * 2023-04-23 2023-05-26 联动优势电子商务有限公司 Method and device for developing Web application by using WebAsssembly and service page compiling technology
CN116166907B (en) * 2023-04-23 2023-09-26 联动优势电子商务有限公司 Method and device for developing Web application by using WebAsssembly and service page compiling technology

Similar Documents

Publication Publication Date Title
US7707547B2 (en) System and method for creating target byte code
US8850416B1 (en) System and method for creating target byte code
US9753697B2 (en) High performance PHP
US10372796B2 (en) Methods and systems for the provisioning and execution of a mobile software application
CN110020307B (en) Drawing method and device for client end view
US7120897B2 (en) User control objects for providing server-side code generation from a user-defined dynamic web page content file
US7426734B2 (en) Facilitating presentation functionality through a programming interface media namespace
JP5225399B2 (en) Systems and methods for desktop application migration
US9992268B2 (en) Framework for thin-server web applications
US7630997B2 (en) Systems and methods for efficiently compressing and decompressing markup language
US6732108B2 (en) Class file archives with reduced data volume
US8572554B2 (en) Method and system for integrating Java and JavaScript technologies
CN112905179A (en) Mobile terminal H5 page generation method and device, electronic equipment and storage medium
CN112269602B (en) WebAssemble loading method, device and storage medium
CN102289774A (en) Graphical message processing and test system and method in financial transaction processing system
CN111723314B (en) Webpage display method and device, electronic equipment and computer readable storage medium
WO2022099459A1 (en) Webassembly loading method and apparatus, and storage medium
CN116431155A (en) Front-end application construction method, medium, device and computing equipment
US9727397B2 (en) Container-less JSP template
JP2010267092A (en) Information processor and information processing method
Rasmussen et al. Bridging the language gap in scientific computing: the Chasm approach
Engelen A framework for service-oriented computing with C and C++ Web service components
CN113568622A (en) Method and device for converting codes and electronic equipment
Horey A programming framework for integrating web-based spatiotemporal sensor data with MapReduce capabilities
Lin et al. A style for integrating MS‐Windows software applications to client–server systems using Java technology

Legal Events

Date Code Title Description
121 Ep: the epo has been informed by wipo that ep was designated in this application

Ref document number: 20961018

Country of ref document: EP

Kind code of ref document: A1

NENP Non-entry into the national phase

Ref country code: DE

32PN Ep: public notification in the ep bulletin as address of the adressee cannot be established

Free format text: NOTING OF LOSS OF RIGHTS PURSUANT TO RULE 112(1) EPC (EPO FORM 1205A DATED 260923)

122 Ep: pct application non-entry in european phase

Ref document number: 20961018

Country of ref document: EP

Kind code of ref document: A1