WebAssembly Compiler Reflection Code Annotation Scanning
Find Innovative SolutionsGenerate Solutions
Solution Overview
Problem
Existing compilation methods for WebAssembly (Wasm) struggle with efficiently compiling code that includes reflection functionality, leading to larger compilation results and reduced performance due to unnecessary functions being compiled.
Innovation Solution
A method and compiler that scan reflection functionality code, use annotations to identify required classes and functions, and compile only those specified, thereby reducing the size of the compilation result and improving performance by implementing 'compilation on demand'.
Engineering Contradictions & Design Principles
Engineering Contradiction Analysis
1Reliability
If all functions in depended classes are compiled together, then the code is complete and can be executed, but the compilation result size increases and performance decreases
Solution Approach 1:
The patent extracts only the necessary functions from depended classes based on annotation information. The compiler scans reflection functionality code, obtains class and function information through annotations, and selectively compiles only those functions that are actually needed, rather than compiling all functions in all depended classes.
Solution Approach 2:
The patent segments the compilation process into two stages: first scanning and analyzing reflection functionality code to identify required classes and functions through annotations, then selectively compiling only the identified functions. This segmentation allows the compiler to process code in a more controlled, demand-driven manner.
2Reliability
If all functions in depended classes are compiled together, then the code is complete and can be executed, but the compiler complexity and workload increase
Solution Approach 1:
The patent performs preliminary scanning and analysis of reflection functionality code before compilation. The compiler first scans the code to identify which classes and functions are needed based on annotations, and only then proceeds to compile the selected functions. This preliminary action reduces the compiler's workload during the actual compilation process.
3Adaptability or versatility
If more code is loaded into linear memory, then the Wasm virtual machine has more functionality available, but the performance decreases
Solution Approach 1:
The patent extracts only the necessary code into the Wasm virtual machine's linear memory. By scanning annotations in the source code, the compiler identifies which classes and functions are actually needed and includes only those in the compilation result, rather than loading all possible code into memory.
Data Source
AI summary
Compiling code comprising reflection functionality is described. A computer-implemented method includes scanning, by a compiler, reflection functionality code starting from a program entry of the code, and obtaining, based on an annotation and as a used class, a class used in the reflection functionality code and a function used by the class. Code of the used class and the function used by the class are added, by the compiler to a list of code to be compiled, in a class upon which the code comprising reflection functionality depends, where the code of the used class and the function used by the class are obtained based on the annotation. The list of code to be compiled is compiled by the compiler to obtain WebAssembly bytecode. The computer-implemented method can be applied to a blockchain.


