Wasm-R3: Record-Reduce-Replay for Realistic and Standalone WebAssembly Benchmarks
엔지니어링 플라스틱 · (23) 컴파운드
기본 정보
- 저자
- DOI
- 10.1145/3689787
- 저널
- Proceedings of the ACM on Programming Languages
- 발행년도
- 2024
- 발행기관
- Association for Computing Machinery
- 피인용수
- 5
- 라이선스
- cc-by
- 논문 유형
- –
- 언어
- –
- 원문 페이지
- https://doi.org/10.1145/3689787
- 토픽
- Advancements in Photolithography Techniques
- OpenAlex ID
- W4403223320
평가 내용
- 관련도
- 사업분야
- 엔지니어링 플라스틱 · (23) 컴파운드
- 부 분야
- –
- R&D 측면
- –
- 확신도
- –
- 근거 용어
- –
- 판단 근거
- 임베딩 유사도 기반 평가로 '엔지니어링 플라스틱 > 컴파운드' 분야에 선정된 논문입니다.
- R&D 활용 포인트
- –
- 평가 입력
- –
초록
본문 114,519자
본문 펼치기
섹션 본문 102문단 · 67,484자
(제목 없음)
1WebAssembly (Wasm for short) brings a new, powerful capability to the web as well as Edge, IoT, and embedded systems.Wasm is a portable, compact binary code format with high performance and robust sandboxing properties.As Wasm applications grow in size and importance, the complex performance characteristics of diverse Wasm engines demand robust, representative benchmarks for proper tuning.Stopgap benchmark suites, such as PolyBenchC and libsodium, continue to be used in the literature, though they are known to be unrepresentative.Porting of more complex suites remains difficult because Wasm lacks many system APIs and extracting real-world Wasm benchmarks from the web is difficult due to complex host interactions.To address this challenge, we introduce Wasm-R3, the first record and replay technique for Wasm.Wasm-R3 transparently injects instrumentation into Wasm modules to record an execution trace from inside the module, then reduces the execution trace via several optimizations, and finally produces a replay module that is executable standalone without any host environment-on any engine.The benchmarks created by our approach are (i) realistic, because the approach records real-world web applications, (ii) faithful to the original execution, because the replay benchmark includes the unmodified original code, only adding emulation of host interactions, and (iii) standalone, because the replay benchmarks run on any engine.Applying Wasm-R3 to web-based Wasm applications in the wild demonstrates the correctness of our approach as well as the effectiveness of our optimizations, which reduce the recorded traces by 99.53% and the size of the replay benchmark by 9.98%.We release the resulting benchmark suite of 27 applications, called Wasm-R3-Bench, to the community, to inspire a new generation of realistic and standalone Wasm benchmarks.CCS Concepts: • Software and its engineering → Software maintenance tools.
Introduction
2WebAssembly (Wasm) is a portable, low-level code format designed for compact representation and efficient sandboxed execution.It is primarily used as a compilation target for various source languages, including C/C++, Rust, and Kotlin, enabling new classes of software to be run in the browser.Its low-level instructions closely map to hardware instructions, achieving near-native performance with straightforward compilation techniques.Wasm augments the web platform, promising to speed up specific components of broader applications [27], as Wasm code often runs faster than JavaScript for numeric and memory-intensive tasks.
3The complexity and diversity of Wasm engines demand robust, representative benchmarks for proper tuning.On the web, Wasm code is loaded dynamically from URLs or can be dynamically generated.Thus, code processing time, interpretation overhead, and JIT compilation to native code contribute to the overall application run time.To deliver fast startup time and high peak performance, all of today's web browsers employ multi-tier Wasm engines.For example, V8 and SpiderMonkey, the engines used in Chrome and Firefox respectively, use two compiler tiers [1, 10], while JavaScriptCore in Safari uses an interpreter and two compiler tiers.Non-web Wasm engines often also use multiple tiers, such as the Wizard Research Engine [52] which employs a new in-place interpreter design and a baseline compiler [53].Multi-tier engines have complex performance characteristics and their tiering heuristics need to be tuned on realistic applications to ensure both startup speed and peak performance are maximized.Tuning these systems requires large, complex workloads that are representative of real-world applications.In the past, unrepresentative benchmarks, such as SunSpider for JavaScript [46], have misdirected engineering effort.In one instance, bad benchmarks led engineers into believing that their performance optimization resulted in a 13× improvement, when a representative benchmark showed only a 3× improvement [45].
4Unfortunately, creating a sufficiently large set of representative Wasm workloads is challenging.One possible approach might be to port existing native applications to Wasm.However, the lack of standardized system APIs has made porting or recompiling large native applications difficult, as efforts like WASI [14] still lack basic facilities, such as signals, sockets, permissions, shared memory, and device APIs.Moreover, beyond the three major web engines, there are now several non-web production Wasm engines, which support disparate APIs or only subsets of WASI, making it difficult to have complex benchmarks with non-trivial system interaction.This deficiency in Wasm benchmarks compels researchers to either write their own benchmarks or use commonly used standard benchmark suites with few dependencies, such as PolyBenchC [44] and libsodium [17], which have already been shown to be unrepresentative of real-world applications [30].Another approach might be to extract benchmarks from real-world web applications.However, Wasm-based web applications consist not only of Wasm modules, but also of a host environment that runs JavaScript code, interacts with the network, and interacts with the user.These properties make the web host environment difficult to emulate, which poses a problem for creating benchmark suites from representative web applications.
5Outside of the Wasm context, creating good benchmarks is a long-standing challenge in many areas of systems.Efforts span virtual machines, operating systems, architecture, vision, and machine learning [7,12,26,34,41].Key considerations are the size and runtime of benchmarks, ease of Fig. 1.Excerpt from the abstract syntax of a simplified form of Wasm [32].
6We show in experiments that nearly all benchmarks produced with Wasm-R3 spend the majority of their execution time in the original functions, not in replay code.
7Our evaluation applies Wasm-R3 to real-world web-based Wasm applications, demonstrating that the approach is effective in creating 27 realistic and standalone benchmarks.We show that our optimizations effectively reduce the size of the recorded trace (by 99.53%, on average) and the size of the replay benchmark (by 9.98%, on average).The generated replay code accounts only for 0.20% of the total execution time, and hence, the extracted benchmarks accurately represent the original application.We release the benchmark suite created by Wasm-R3 during our evaluation, called Wasm-R3-Bench, to the community, and envision them to serve as a new standard for realistic and standalone Wasm benchmarks.
8In summary, this paper contributes the following:
9• We introduce the first record and replay technique for Wasm.It does not require support from or modification of the Wasm host environment, hardware, operating system, language runtime, or source compiler.• We demonstrate the technique via a system which records execution traces of web applications in any browser and produces replay benchmarks that execute without any host environmenton any engine.• We present optimization techniques that reduce trace size and improve replay performance.
10For several applications, these optimizations are vital to making our approach feasible at all, avoiding out-of-memory errors and excessive slowdowns that make benchmarks unrepresentative of the original application's performance.• We demonstrate that Wasm-R3 is effective in real-world scenarios by using the approach to create benchmarks from 27 real-world web applications.• We make Wasm-R3, associated tools, and the created benchmarks available as open source https://github.com/sola-st/wasm-r3.
Background
11In this section, we provide necessary information to describe Wasm-R3. Figure 1 under one or more names, allowing them to be accessed externally.Apart from these entities, modules can include initialization data for tables and memories.
12One concept that plays a key role in Wasm-R3 is embedding of Wasm modules into a host environment.Host environments load Wasm modules, resolve imports and exports between modules, and provide host functions as imports to Wasm functions.Host functions can access state outside modules and perform I/O.While the web was the main motivation for Wasm initially, it was designed to be embedded in multiple environments [27].Thus, although the web and JavaScript embedding was the primary one at launch, WASI [14] has emerged as a set of standard system APIs in non-web use cases.In principle, unlimited embedders are possible due to the environmentagnostic design of Wasm.After an embedder loads, verifies, and processes Wasm code, it provides bindings to a module's imports and creates the module's storage.The result is an instance, a runtime representation that contains the state of the module.A Wasm instance interacts with host environments by calling imported host functions and being called by exported Wasm functions.
13Consideration of host functions introduces another important aspect of Wasm for Wasm-R3: nondeterminism.Since its inception, one of Wasm's explicit goals [27] has been to provide deterministic semantics across different hardware.However, there are three exceptions: NaN payloads, resource exhaustion, and host functions.Some Wasm instructions output non-deterministic NaN bit patterns in the presence of non-canonical input NaNs, as hardware may behave differently and canonicalizing all NaNs is deemed too expensive.Resources like memory obviously vary from host to host and computer to computer, so deep recursion or memory.growmight fail at different points, and of course a host function can perform I/O or even arbitrary updates to a Wasm instance's exported state.In this work, we focus on nondeterminism arising from the interaction with host functions.
Overview
14Figure 2 gives an overview of Wasm-R3.Given a Wasm-based web application, Wasm-R3 executes the application, possibly with user input, and produces a benchmark that replays that execution without any user input.Wasm-R3 consists of three phases: record, reduce, and replay.
15The record phase can be considered the frontend of Wasm-R3.It takes a Wasm web application as an input and produces a trace as a result.We assume that the application consists of Wasm modules and host code, e.g., in JavaScript.As the first step, Wasm-R3 intercepts the Wasm modules before they are loaded into the application and instruments the modules with recording logic.Our instrumentation tracks all function calls and returns as well as all loads and stores to mutable state.Then, the instrumented Wasm web application is run within the record runtime.While the user interacts with the web application, each instrumented Wasm module records its own execution trace.Note that if the input Wasm web application loads multiple Wasm modules, then the record phase produces one trace for each module.
16For complex applications, the traces can grow prohibitively large.Thus, for efficiency, the reduce phase filters out unnecessary events from the output trace of the record phase.Specifically, it applies the shadow memory optimization and call stack optimization on the trace.By applying these optimizations, we only keep the parts of traces that are directly related to the nondeterminism that occured during execution.Eventually, the reduce phase yields optimized traces as outputs.
17The replay phase is the backend of Wasm-R3.It takes the original, uninstrumented Wasm module and the corresponding optimized trace as inputs and produces a self-contained, executable replay benchmark.The replay phase does not modify the original module's functions.Instead, it simply merges them with generated replay functions to complete the executable replay benchmark.It first translates the input trace to an intermediate representation, the replay IR.Then, it applies replay IR optimizations to reduce the size of the IR and ultimately the generated code, ensuring that the resulting binaries satisfy the size restrictions commonly imposed by engines.Finally, it generates the replay benchmark from the optimized replay IR.As we discuss in Section 3.4.4,our replay binary generator supports three different output formats.This approach allows replay benchmarks to be executed in diverse environments, including web browsers and standalone Wasm runtimes.
18The next sections dive into the details of the record phase (Section 3.2), trace reduction techniques (Section 3.3), and the replay phase (Section 3.4).
Record Phase
19The record phase is responsible for recording the necessary information into a trace for reconstructing the benchmark that deterministically replays the Wasm web application's behavior.As described earlier, non-determinism gets introduced to Wasm applications by functions imported from the host environment.The record phase thus needs to capture information about function calls across the boundary between the host environment and the target Wasm module.This includes side effects to the Wasm module's mutable state, e.g., the memory section of the Wasm module, caused by host functions.
20The following describes the format of traces (Section 3.2.1)and how these traces are recorded via instrumentation (Section 3.2.2).
Trace
21Structure.We define a trace data format that stores all necessary information about host function execution and their side effects.By defining traces, we effectively decouple the record phase and replay phase and relay any required data by the fixed format of traces.
22Listing 3 provides type definitions of the trace structure.A Trace is a linear sequence of events.Events correspond to units of behavior that happen during the Wasm app execution and that possibly involve interaction with host code.There are six types of possible trace events: FuncEntry, FuncReturn, Call, CallReturn, Load, and Store.The funcidx field in events corresponds to the function index of the Wasm function.ValType corresponds to Wasm's four primitive types.A FuncEntry event corresponds to the start of the function body.This event represents the entrance to a Wasm-side function, with params storing the arguments given to the function call.Conversely, a FuncReturn event corresponds to the end of the function body.This event represents the exit from a Wasm-side function, with values storing the return values of the function.events are produced by calling and returning from functions imported by a Wasm module.Both events store the function index of the callee function, with the CallReturn event additionally storing the returned values.A Load event corresponds to Wasm load instructions.It stores the memory index in the memidx field, the address in the address field, and the loaded value in the value field.Similarly, a Store event stores the memory index, address and stored value of Wasm store instructions.
23In practice, we encode the trace in two formats: a textual format and a binary format.The textual format is a JSON-like representation of the trace, where each trace event is encoded as an object, and the whole trace is encoded as a list of such objects.For instance, a Load event may be represented as Load { memidx: I32(0), address: I32(1000), value: I16(300) }.We use the textual format for human-reading purposes, such as debugging.In the binary format, each entry starts with a byte indicating the entry type, so the byte length of the entry is known.We use the binary format in our implementation to reduce memory usage and for efficient parsing of traces.
Instrumentation.
24We use an instrumentation-based approach to record interactions between the Wasm module and the host environment and to store them into traces.To this end, we add instructions to the Wasm binaries to capture runtime information, such as operand stack values.Using instrumentation allows us to record traces from arbitrary Wasm-based web applications, without changing the web browser implementation or depending on features specific to certain platforms or libraries.
25An important property of our instrumentation is that it should not change the original Wasm module's semantics.Instead, the instrumented Wasm module serves as a drop-in replacement for the original Wasm module during recording, with the only behavioral change being the recording of a trace.To preserve the Wasm module's semantics during instrumentation, our instrumentation strategy uses special recorder functions, which take runtime information as input parameters, records the event into the trace, and return.We define recorder functions for each trace event.For instance, the recorder function for a load instruction gets memidx, address, value as input arguments and records the corresponding Load event.Our instrumentation copies the runtime information on the stack, calls the imported recorder function, and then returns to the original execution flow.By Wasm's function call semantics, calling the recorder function will consume only the copied values from the stack and will not divert the original control flow.
Reduce Phase
26The execution of a Wasm web application can produce millions of host interaction events.A naïve approach would quickly run out of time and memory before a replay binary is generated.An essential component to make Wasm-R3 practical is to reduce the size of traces by filtering out events that contain redundant or unnecessary information.We call this process trace reduction.A key insight is that we only need to keep trace events related to non-determinism.For instance, many of the Store events can be deterministically replayed by the original Wasm module itself.Thus, we can conclude that Store events are not necessary to replay host-side non-determinism.
27In this section, we describe two trace reduction techniques: shadow memory optimization (Section 3.3.1),which filters out redundant Store and Load events, and call stack optimization (Section 3.3.2),which filters out unnecessary Call and CallReturn events.
Shadow Memory Optimization.
28Most of the Store and Load events in traces are not related to non-determinism and can thus be removed.It is not necessary to record all Wasm stores for accurate replay, as the original code performs the exact same sequence of stores as long as the current state of the program is the same.Thus, it is only necessary to keep stores related to non-deterministic behavior, i.e., stores that come from the host.Unfortunately, we cannot directly hook into host-side stores (e.g., when JavaScript writes into WebAssembly memory), since we only instrument the application's Wasm code.However, Load events on the Wasm side can observe when values in linear memory diverge from what was last recorded, which means they were modified by the host.
29Inspired by memory optimization techniques in prior work [43,50], we apply the shadow optimization technique to remove unnecessary Store and Load events and keep only Load events that observes the host-side side effect.The technique maintains a data structure called shadow memory, which keeps track of the written values to the original Wasm module's linear memory.By comparing the loaded value of a Load event and the value stored in the shadow memory, we can determine if the Load event observes the host-side side effect or not, and discard the unnecessary events.
30Figure 4 illustrates how the shadow memory optimization works.For each step of a Wasm module's execution, we illustrate the corresponding trace event, the state of the module's actual memory, and the state of the shadow memory.For presentation brevity, we omit the irrelevant fields in the trace events.In the actual memory states, we represent the parts that are read or written as gray cells.In the shadow memory states, we represent the parts that are modified or compared with the loaded values as gray cells.
31Proc.ACM Program.Lang., Vol. 8, No. OOPSLA2, Article 347.Publication date: October 2024.
32Wasm-R3: Record-Reduce-Replay for Realistic and Standalone WebAssembly Benchmarks 347:9
Call Kind
33Initialize with EXT We first initialize the shadow memory to contain the same values as the original Wasm module, by following the Wasm module's data section definition.The first trace event is a Store of a singlebyte value 0x01 to address 1002.The shadow memory optimization applies the same write to the shadow memory and discards the event.Then, as a result of the call of an imported function in the second and third events, the content at address 1003 is mutated.The fourth event is a Load of value 0xAA from address 1000.The optimization first compares the loaded value with the value at the same address in the shadow memory.Because the values are equal, the optimization discards the Load event.Similarly, the optimization discards the fifth event.The sixth event is a Load of value 0xBB from address 1003.The optimization compares the loaded value and the shadow memory value.Here, the values are different, i.e., the value has been mutated as a side effect of interacting with the host.Our optimization updates the shadow memory value as the loaded value and keeps the Load event.As a result of shadow memory optimization, only the second, third, and sixth trace events are remaining, whereas the other, unnecessary Store and Load events are discarded.
Call Stack
34Optimization.While we record every trace event related to function execution, a significant portion of them are unrelated to non-determinism.During the execution of a Wasm module, there are three possible kinds of function calls: export calls, import calls, and internal calls.Export calls are function calls from the host-side code to functions exported by the Wasm module.Import calls are function calls from the Wasm module to functions imported from the host environment.Internal calls are function calls from a function in the Wasm module to another internal function.Among these three kinds of calls, we do not need to keep track of internal calls as those can be deterministically replayed by the original Wasm code.Thus, we can safely remove FuncEntry, FuncReturn, Call, and CallReturn events produced by internal calls.In addition, we can remove FuncReturn events produced by returning from export calls.This is because the same return values can be deterministically replayed by the functions defined in the original Wasm module.
35We apply call stack optimization to remove trace events produced by internal calls.To distinguish if an event was produced by an internal call or not, we track function calls in our own call kind stack.The call kind stack stores INT and EXT objects, which correspond to Wasm-internal contexts and host-side code contexts, respectively.Similar to conventional function call stacks, our call kind stack keeps track of calling contexts of trace events.By observing the stack top element and the next trace event, we can determine if the event was produced by an internal call and discard it.
36Figure 5 illustrates our call stack optimization process.In this example, we assume that the function at index 0 is the only function imported from the host environment, and any other functions are internal functions of the original Wasm module.We represent trace events by omitting unnecesary fields and only annotating the kind of an event and the funcidx field as a number.The call kind stack column represents the state of the call kind stack at each step.Gray-colored cells represent objects pushed in the current step, and gray-hatched cells represent objects popped in the current step.The call kind column represents the kind of the function call produced by the corresponding trace event and whether the function is being called or returning.The rightmost column shows which action the call stack optimization performs at each step.The underlined actions are always performed regardless of the event's funcidx or the call kind stack top content.Note that we omitted Store or Load events from the trace for simplicity.
37The call stack optimization rules are as follows.We first initialize the call kind stack with a single EXT object.This represents the outermost host execution context, e.g., JavaScript code which might call into exported Wasm functions.Then, we iterate over trace events.On a FuncEntry event, we first observe the stack top.If the top is EXT, then the event was produced by an export call; we keep the event.If the top is INT, then the event was produced by an internal call; we discard the event.Finally, we always push INT on the stack.On a Call event, we first check the funcidx field.If the index corresponds to an imported function, then the event was produced by an import call; we push EXT on the stack and keep the event.If the index corresponds to an internal function, then the event was produced by an internal call; we discard the event.On FuncReturn event, we first pop an object from call kind stack and discard the event.On a CallReturn event, we first check the funcidx field.If the index corresponds to an imported function, then the event was produced by returning from an import call; we pop an object from the stack and keep the event.If the index corresponds to an internal function, then the event was produced by returning from an internal call; we discard the event.
38As illustrated in Figure 5, the call stack optimization discards all events produced by internal calls.In addition, it discards all FuncReturn events produced by returning from export calls.In the example, this filters out 6 out of 10 events.The effect on real-world traces is evaluated in Section 5.
Replay Phase
39In the replay phase, Wasm-R3 gets an input trace and generates an excutable, standalone replay benchmark.In this process, Wasm-R3 uses a replay intermediate representation, or replay IR.We describe the definition of the replay IR in Section 3.4.1.By first generating a replay IR (Section 3.4.2) from a trace, we can apply the replay IR optimizations (Section 3.4.3) to reduce the size of the replay IR.Finally, Wasm-R3 translates this replay IR into one of three different output formats (Section 3.4.4)and generates a replay binary (Section 3.4.5).
Replay IR.
40Replay IR is a format designed to represent behaviors of replay functions.Replay functions are functions that implement the replay mechanism by replaying the return values and side-effects of host-side functions recorded during the record phase.The goal of the replay phase is to generate a replay function for each function imported from the original Wasm module.We utilize the replay IR as a general format that describes the behaviors of replay functions without depending on specific output formats.Thus, introducing the replay IR effectively divides the problem of generating replay binaries for multiple output formats into three problems: 1) translating a trace into a replay IR, 2) optimizing the replay IR, and 3) translating the replay IR to each output format.
41We present the definition of the replay IR in Figure 6.An Action corresponds to a single instruction in the host: ExportCall or MutateMem.An ExportCall represents a function call from the host to an exported Wasm function.A MutateMem represents a host-side effect of mutating the Wasm module's 3.4.2From Trace to Replay IR.We present the algorithm to translate a trace into a replay IR in Figure 7.The algorithm gets an input trace and returns a Replay and a Function.The Replay value corresponds to the map from the imported function indices to the replay functions.The Function value corresponds to the entry function to the Wasm module; as it does not correspond to a function index of the original Wasm module, we return it separately from the Replay value.
42We use five variables in the algorithm: GLOBAL_CONTEXT, ENTRY_FUNC, last_context, context_stack, and replay.The variable ENTRY_FUNC denotes the entry Function.Because the entry function is executed exactly once, it has only one Context, which is the variable GLOBAL_CONTEXT.The variable last_context is a reference to a context; it points to the latest context that new MutateMem actions should be appended to.The variable context_stack is a stack of references to contexts.We maintain context_stack to keep track of the current host-side function call and push actions into correct contexts.We initialize last_context and context_stack with GLOBAL_CONTEXT as the entry function is the first function executed in the whole Wasm web application execution.Finally, the variable replay stores the Replay object which will be returned.We assume that each Function object inside the replay is properly initialized with an empty sequence when we access it.
43The goal of the algorithm is to fill the Functions in the replay with Contexts and fill the Contexts, including GLOBAL_CONTEXT, with Actions, so that the return values correctly mirror the host-side behaviors recorded in the input trace.To correctly mirror the input trace, 1) a correct Action must be created for each event and 2) the created Action must be inserted to a correct Context.To do this, the algorithm uses case analysis on each event and properly updates last_context and context_stack.For a FuncEntry event, it creates an ExportCall action and pushes it to the Context of the current function.We find the Context of the current function by referring to the top of context_stack in this case.For a Call event, it creates a new Context object, namely new_context, for this import call.This new Context object is appended to the Function at the event.funcidxindex of replay.Then, it pushes the reference to new_context onto context_stack and updates last_context.For a CallReturn event, the current function call is returned, so it pops from context_stack.Then, by updating last_context to the popped Context object, when we append MutateMem objects to last_context, it correctly mirrors the fact that the side effect observed by the Wasm-side execution is caused by the most recently returned host-side execution.Lastly, for a Load event, it creates a new MutateMem action reflecting the side effect on the memory.Then, to insert this action into the correct position, it inspects the last element of last_context.In most of the cases, it appends the new MutateMem at the last position of last_context.However, if the last action on the last_context is an ExportCall action, this means that the mutation happened before the corresponding export call and the side effect was later observed.Thus, it inserts the new MutateMem action right before the ExportCall action.
443.4.3Replay IR Optimizations.We apply optimizations on replay IRs to reduce their size.Before we generate an output replay benchmark, we reduce the replay IR size so that the size of the replay binary is also reduced.By reducing the size of the replay binary, we address three practical issues.
45• First, we produce valid replay binaries that are accepted by web browser engines.Production web engines impose a common restriction on the size of functions inside the Wasm binary 1 .By naïvely translating Function objects in a replay IR into Wasm functions, the size of replay functions may exceed the function size limit.To solve this issue, we employ replay IR optimizations to reduce the number of instructions of each replay function and produce smaller Wasm replay functions.• Second, we shorten the compilation time of the replay binaries, which correlates with the runtime performance of the replay benchmark.A previous study [52] has found out that the compilation time of Wasm modules significantly impacts the performance evaluation of a Wasm engine.Since our replay IR optimization techniques reduce the overall size of the replay binary, we can reduce the impact of compilation time on the performance evaluation of Wasm engines.• Third, we reduce the execution time of the replay benchmarks by reducing the number of instructions in the final replay function bodies.We achieve this effect by merging mulitple instructions into a single instruction while preserving the function behavior.
46We describe our two replay IR optimization techniques: memory write merge and function split.
47Memory Write Merge Optimization.By inspecting replay IRs, we found that Wasm often involves writing data to consecutive bytes in the Wasm linear memory.Inspired by the memory.initinstruction, which executes bulk writes on multiple bytes, we design the memory write merge optimization that merges multiple MutateMem actions on consecutive addresses in a single action.To represent the bulk write, we introduce a new action BulkMutateMem.The BulkMutateMem action has the same syntax as MutateMem, except that the val field is a number type with no size limit.In theory, the memory write merge optimization can merge an unlimited number of MutateMem actions into a single BulkMutateMem action.We translate the BulkMutateMem action into the memory.initWasm instruction.Figure 8 illustrates an example of applying the memory write merge optimization.The left-side figure is a part of the replay IR before applying the optimization.It is a sequence of eight MutateMem actions on consecutive bytes.The optimization merges the eight seperate writes in eight MutateMem actions into a single, 8-byte value in the BulkMutateMem action.
48Function Split Optimization.As mentioned earlier, production web browser engines impose a common restriction on the size of a single Wasm function.We observed that some Function objects in replay IR exceed that maximum size limit.These Function objects represent functions frequently called in the Wasm web application execution.For instance, we observed a utility function that performs a conversion of float64 values to integers corresponding to millions of actions.
49To prevent our output replay binaries from being invalid, we employ function split optimizations on such large Function objects.In the function split optimization, we outline some parts of a Function object into other Function objects and replace them with calls to the new Function objects.By setting an appropriate threshold of the Function object size, we maintain each Function object size below the maximum Wasm function size limit imposed by the web engines.
Output Formats.
50The replay benchmarks generated by Wasm-R3 in the replay phase consist of three parts.First, the original Wasm module of the application.Second, the replay code, which replicates the behavior of the host environment during the record phase.Third, the setup and instantiation code, which links the first two parts together.The setup and instantiation code fulfills the imports of the original Wasm module with functions from the replay code and starts the replay benchmark.The last two parts are generated from the replay IR.
51While the original application code is always in Wasm, we can make different choices for the replay code and the setup and instantiation code.If the replay code is in JavaScript, the setup and instantiation code should also be in JavaScript (option "JS").When the replay code is in Wasm, we can either statically link the replay code with the original Wasm module into a single, self-contained binary (option "self-contained Wasm"), or generate JavaScript setup and instantiation code that loads the replay code and the original Wams module separately (option "dynamic linking").In the dynamic linking option, the actual linking between the original Wasm module and the replay code happens during the instantiation at runtime.
52All three output formats are sensible choices.A self-contained Wasm replay is the easiest option for downstream consumers of the benchmark, as it can be executed in any Wasm engine, including Wasm standalone runtimes that do not have a JavaScript host environment.We also expect a selfcontained Wasm is the most performant way for replay because it does not involve function calls across the Wasm module and JavaScript host environments.Hence, we choose the self-contained Wasm format by default and use it for evaluation in Section 5.However, when the replay code is kept in a separate Wasm module or in JavaScript, this can be useful to benchmark cross-language or multi-module interactions.In Wasm-R3, we provide options to select from three output formats, so users can generate replay benchmarks according to their use cases.
3.4.5
53From Replay IR to Output Formats.Once we have a replay IR, the generation of an executable, standalone replay benchmark is carried out in a straightforward, single-pass manner.For each Function in the replay IR, we generate a replay function according to the output mode.For JavaScript, this would be a JavaScript function, and for Wasm, this would be a Wasm function.We then define a global counter variable for each function to keep track of the current Context.The body of the generated function consists of a switch statement in the respective language that maps different counter values to different sequences of instructions, followed by a part that increments the counter for each invocation.Each sequence of instructions that are translated from a Context is a series of simple line-by-line translations of Actions in the replay IR to their corresponding instructions in the langauge.For example, MutateMems are translated to their corresponding store instructions.
Implementation
54In this section, we describe notable implementation details of Wasm-R3.Implementation Summary.The implementation of Wasm-R3 amounts to roughly 2,200 lines of TypeScript and 2,200 lines of Rust, divided into the frontend (the record and reduce phases) and the backend (the replay phase).The code is released under the MIT License and is publicly available at https://github.com/sola-st/wasm-r3. Wasm-R3 utilizes two third-party libraries: Wasabi [32], an instrumentation framework for Wasm, which we use to inject calls to recorder functions and to store corresponding trace events, and Binaryen [21], a compiler toolchain and infrastructure, which we use to optimize replay binaries.
55Proxy.Rather than intrusively modify web browsers (or Wasm engines in the web browsers), we employ a proxy to intercept Wasm and JavaScript code.Modern web browsers expose the capability to intercept and modify network requests and responses.For instance, Chromium provides the DevTools Protocol [23] for this purpose.The proxy component leverages this capability to intercept JavaScript files and patch 2 the function definitions of Wasm module instantiation APIs: WebAssembly.Instance, WebAssembly.instantiate,and WebAssembly.instantiateStreaming.The new instantiation functions intercept the Wasm binary before instantiation and inject instrumentation before forwarding them to the underlying Wasm engine.We utilize the Playwright library [40] to implement the proxy across all major web browsers.This proxy approach allows Wasm-R3 to instrument every Wasm module on-the-fly without modifying the browser implementation.
56Mutable State in Wasm.In Wasm, there are three kinds of mutable states in instances: globals, tables, and memories.Globals are mutable or immutable, single-value storage that can be imported and exported from Wasm modules.Tables store opaque references to host objects and Wasm functions.Since the call_indirect instruction indirects through a table, mutable tables can be used to implement dynamic linking via indirect calls.Like Wasm linear memory, globals and tables can be modified by the host environment if exported from an instance.Thus, in order to replay all nondeterminism from the host, we also need to record mutation of globals and tables.Although not described in detail here, Wasm-R3 also records and replays global and table mutations by instrumenting global.getand table.getinstructions, respectively.Similarly, it also employs shadow memory optimizations for globals and tables to distinguish mutations from the host environment and the module itself.
57Simultaneous Record and Reduce.In our implementation of Wasm-R3, the reduce phase is partially overlapped with the recording phase; the reduce phase filters out most redundant trace events even before they are stored in a trace.This is done primarily by the shadow memory optimization and the call stack optimization algorithms, which are applied online in the recorder functions.For example, a load instruction simply reads both the shadow and real memories and suppresses generating a load event if the two values are the same, which implies that the program either writes the value or has already observed a host-written value.Similarly, the call stack optimization algorithm is included directly in the recorder function.Filtering events requires more checks, but is less expensive than generating events and then later filtering them out, which naturally saves space but also reduces the overall recording overhead.
Evaluation
58We evaluate Wasm-R3 by addressing the following four research questions.techniques reduce the size of replay binaries?How do the optimizations impact the performance characteristics of the replay benchmarks?
Experimental Setup
59We collect URLs of real-world Wasm web applications, which we define to be interactive webpages that load at least one Wasm module, to serve as our evaluation targets.To find such applications, we use two websites as starting points: Made with WebAssembly [55], which is an open-source website that showcases projects created with Wasm, and Awesome-Wasm [20], an open-source repository that lists Wasm-related webpages.We gathered URLs for Wasm web applications from these webpages by first manually crawling them and their subpages and filter out inaccessible websites, e.g.404 or that require authentication, non-interactive webpages, and pages where the relevant Wasm APIs, e.g.WebAssembly.Instance, WebAssembly.instantiateor WebAssembly.instantiateStreaming,are not used in any script.
60For repeatability, we use test scripts that automatically interact with each website using the Playwright library [40] by mimicking common use cases.Each script executes multiple user actions, such as clicking a button or typing text into an input form.For websites that use multiple Wasm modules, we write multiple test scripts, each focusing on a different module.These scripts run against live sites, which of course evolve over time and automation breaks.In fact, the difficulties of reliably and reproducibly automating the execution of Wasm web applications is a key motivation of Wasm-R3, which ultimately produces completely self-contained Wasm benchmarks.
61While writing test automation scripts, we exclude some applications from our evaluation targets that have one or more of the following problems:
62(1) Throw errors even when used without Wasm-R3.
63(2) Require external files or privileged information.For example, we remove a GameBoy emulator
64[8] because it requires a GameBoy ROM file that we could not supply.(3) Take unreasonably long time to download required data from the network.This affects several video game ports, such as Arxwasm [15] and D3wasm [16].(4) Though statically appear to use Wasm, don't dynamically load any Wasm modules.For example, we exclude Wasmboy [19] because we could not automate it to load Wasm.( 5) Require automation scripts that would interact with the HTML canvas element.As the Playwright library does not provide APIs to recognize images inside a canvas element, we cannot perform any meaningful interactions with such applications beyond randomly clicking inside the canvas.(6) Exhibit flakiness in the automation scripts without any meaningful errors.For example, we exclude the application a tic-tac-toe game [37], because it sometimes fails to load the game.
65As a result, we compiled 43 URLs to Wasm web applications.Table 2 summarizes our evaluation targets.Our evaluation targets are composed of 9 programming language applications, 8 Wasm benchmarks, 6 video games, 4 graphics applications, 3 media applications, 2 mathematical computation applications, 2 simulator applications, and 1 ML(machine learning) application.We claim these represent real-world Wasm web applications as we gathered them from well-known, open-source compilations of Wasm web applications and include applications from various domains.
66We evaluate the benchmarks created with Wasm-R3 on three web browser engines (Spider-Monkey [3] version 125.0b7,V8 [4] version 12.5.149,and JavaScriptCore [2] version 277039) and three standalone Wasm engines (Wizard [51] version 24.1998,Wasmtime [6] version 19.0.1, and Wasmer [5] version 4.2).We use the standalone-Wasm output format of the benchmarks for the entire evaluation (Section 3.4.4),as they can be executed across both web browser engines and standalone Wasm engines.To run a standalone-Wasm benchmark in a browser, we use a simple JavaScript wrapper that loads the replay benchmark and calls its entry function.
67Our experiments are conducted on a machine running Ubuntu 22.04.1, equipped with an Intel Core i9-13900k CPU and 192GB of DRAM.With the Intel Core i9-13900k, we disable E-cores and use only P-cores, and set the Linux CPU frequency governor to performance mode for consistent results.We use Chromium 123.0.6312.4 as the browser for the proxy component in the record phase.For the experiments in RQ2 and RQ4, we repeat each measurement ten times for each target.
RQ1. Applicability
68We evaluate the applicability of Wasm-R3 in two ways.First, we evaluate its ability to produce accurate benchmarks from various real-world Wasm web applications, which we call the accuracy Due to the complexity of the web and limitations of the libraries that Wasm-R3 uses, the approach fails to produce accurate benchmarks for the remaining 16 applications.We categorize the failures into three groups:
69• Implementation limitations (5 cases).Some failures are due to the known limitations of our implementation.For image-convolute, the trace contains over a million calls to a single host function.The current function split optimization works only inside a single context in the replay IR, which prevents the application of the optimization in this case; playnox fails for the same reason.We believe this would be resolved with a more advanced function split optimization that works across multiple contexts.For timestretch, hnset-bench, and wheel, our proxy logic does not seem to work the use cases of the applications.• Dependency limitations (4 cases).Some failures are caused by the limitations of the libraries that Wasm-R3 uses.Wasabi fails to instrument fractals and lichess, because they use the SIMD proposal, and livesplit, because it uses the threads proposal, which are not yet supported by Wasabi.Binaryen fails on waforth because the library does not support block-type parameters.3 • Unknown problems (7 cases).For the remaining 7 applications, we could not determine the cause of the failure.We are currently investigating their cause.
Portability Experiment.
70The following experiment evaluates to what extent the replay benchmarks generated by Wasm-R3 execute successfully across different Wasm engines.We run the portability experiment with all 27 accurate replay benchmarks, trying to run them on three web browser engines and three Wasm standalone engines (Section 5.1).When running the portability experiment with web browser engines, we experiment with different optimization tiers of each engine.We count the experiment as successful if the replay benchmark runs successfully on all optimization tiers of the engine.Likewise, as the Wizard and Wasmer engines also provide different optimization tiers, we also experiment with them.All replay benchmarks successfully run across all execution tiers of the three web browser engines and three Wasm standalone engines.In summary, our experiments show that Wasm-R3 is applicable in various usage scenarios.In particular, we produce a suite of 27 replay benchmarks from real-world Wasm web applications, and these benchmarks run successfully on various Wasm engines.
RQ2. Performance
71We evaluate the performance of Wasm-R3 from two perspectives.First, we assess the amount of overhead introduced during the recording phase (Section 5.3.1).Keeping the overhead low is crucial to minimize disruption to user interactions during the recording phase.Second, we examine the performance characteristics of the replay benchmarks by measuring the time spent in code of the original Wasm module and in code added by Wasm-R3 to enable replay (Section 5.3.2).For a replay binary to be useful for evaluating the performance of Wasm engines, the majority of time should be spent in the original Wasm code.
Record Overhead Experiment.
72The following experiment evaluates the overhead of Wasm-R3's record phase.We measure the total CPU cycles spent by the Chromium renderer process of the target application using the Linux perf tool.Among the 27 replay binaries in Wasm-R3-Bench, we exclude parqet in this experiment as our record overhead measurement infrastructure does not support its use of the WebGL library.To compute the recording overhead, we compare the performance of the application when running with an uninstrumented and an instrumented Wasm module.As in RQ1, we use our UI-level test scripts to simulate user interactions.Because the test scripts are at the UI level, there is a risk of having slightly different workloads in different runs.To mitigate this risk, and also to account for the inherent noise of performance measurements, we repeat each measurement across ten runs and compute the arithmetic mean of the spent CPU cycles. 4Then, we compute the ratio of the arithmetic mean of the CPU cycles spent by the instrumented application to the arithmetic mean of the CPU cycles spent by the uninstrumented application.
73Figure 9 shows the overhead introduced by the record phase of Wasm-R3.We measured the CPU cycles spent executing JavaScript and Wasm code with and without instrumentation.While the overhead varies across applications, the slowdown is generally modest, with a median of approximately 3.79×, a geometric mean of 3.40×, and all but one application exhibiting less than 8.18× overhead.In practice, this overhead is acceptable; applications are still interactive and users can record realistic usage scenarios with Wasm-R3.
Replay Characteristics
74Experiment.We now evaluate the performance characteristics of the replay benchmarks created by Wasm-R3.Wasm-R3 repackages the functions of the original Wasm module with replay functions, creating a standalone executable.While any Wasm workload can serve as a benchmark, the overall goal is to capture the performance characteristics of the original Wasm code.A key metric is then the proportion of the work spent in the original functions versus the replay functions.To answer this question, we first measure the CPU cycles per function using the fprofile monitor of Wizard.Then, we distinguish whether the function belongs to the original Wasm module or the replay functions.Summing the CPU cycles spent in each group, we can calculate the total cycles spent in the original Wasm module and the replay functions.We repeat the experiment ten times to get the arithmetic mean value of the CPU cycles to reduce variance in the measurements.
75Figure 10 displays the results of this experiment.The upper portions of the bars in light gray color represent the percentage of the cycles spent in the functions from the original Wasm module, while the lower portions in red color represent the percentage of the cycles spent in replay functions.Ideally, a benchmark would spend 100% of the cycles in the original Wasm code and 0% in replay.For the benchmarks we gathered, we find the geometric mean of the cycles spent in the replay binary to be 0.20%.Half of the benchmarks spend less than 1.53%, all but one less than 24%, and the maximum cycles spent in the replay part is 39%.The proportion varies according to the frequency and nature of the application's interactions with the host.Yet, recall that our technique only requires the replay return values and observed side-effects (e.g.memory modifications) from host calls.Side-effects from the host that are never observed by the application, as well as host functions that only read application memory, do not generate trace events.This leads to the somewhat counter-intuitive result that applications that produce a lot of data for the host (e.g.rendering frames for a game) actually do not generate many trace events; they generate (relatively small) trace events when the user interacts with the game.Thus, in summary, our results show that the modules in Wasm-R3-Bench mostly exercise the behavior of the original, real-world applications, making these executions suitable for evaluating the performance of Wasm engines.
RQ3. Effectiveness of Trace Reduction
76We evaluate how effective Wasm-R3's trace reduction techniques (Section 3.3) are in reducing the size of the recorded traces.We record traces with four variants of the approach: 1) without any trace reductions, 2) only with the shadow memory optimization, 3) only with the call stack optimization, and 4) with both optimization techniques.The fourth variant corresponds to the full Wasm-R3 approach.We target all 27 modules in Wasm-R3-Bench, measure the size of the traces produced by the four variants, and report the differences in them.By "the size of a trace, " we here mean the number of trace events recorded by Wasm-R3.
77Table 3 shows the results.Both trace reduction techniques are effective in reducing the trace size.On average, the shadow memory optimization and the call stack optimization reduce traces to 27.20% and 38.17% of the original trace size, respectively.Together, the two optimizations reduce the traces to only 0.47% of the original size, i.e. a more than 200× reduction.In the development process, before optimization, Wasm-R3 initially failed to produce traces for most applications due to the lack of memory or timeouts.However, after applying our trace reduction techniques, Wasm-R3 filters out a large portion of trace events and succeeds to produce traces for real-world applications.Hence, we believe that our trace reduction techniques are essential to produce replay benchmarks from real-world Wasm web applications.
78From the table, three interesting cases emerge: multiplyDouble, multiplyInt, and fib.For multiplyDouble and multiplyInt, the optimizations do not remove any trace events.This is because multiplyDouble and multiplyInt do not perform any loads or calls during their execution, i.e., there is nothing for our techniques to optimize.Instead, all the events in the traces are FuncEntry events directly followed by FuncExit events.These functions use a loop internally within an exported function to repeat the multiplications.In contrast, the results for fib show that almost all trace events are filtered out, with only 24 out of 4.9 billion events remaining.This is because fib contains a recursive function that calls itself many times.Most of the events are Call events that get filtered out by the call stack optimization.
RQ4. Effectiveness of Replay Optimization
79In this section, we evaluate the effectiveness of replay optimization techniques introduced in Section 3.4.3.We first conduct a simple comparison of the replay binary size of replay benchmarks 1) without any replay optimizations, 2) only with the memory write merge optimization, 3) only with the function split optimization, and 4) with both optimization techniques.We found that the function split optimization does not affect the binary size, while the memory write merge optimization reduces the replay binary size by 9.98%.Then, for the 27 replay benchmarks in Wasm-R3-Bench, we carried out an ablation study to evaluate the effectiveness of the two optimizations.We call this the replay optimization experiment.In the replay optimization experiment, we measure two kinds of times: load and validation time and execution time.The load and validation time is the time spent loading, parsing, and validating the replay Wasm benchmark, while execution time represents time to execute the main (i.e.top-level replay) function.We measure these with the --metrics option of the Wizard engine, which reports load, validation, compilation, and execution time, and average over 10 runs.Table 4 reports the results of the replay optimization experiment.On average, applying both replay optimizations reduces the time spent in load and validation by about 6%.In detail, applying the function split optimization increases the load and validation time by about 5%.Considering that some replay benchmarks require the function split optimization to run, we think this is an acceptable increase.Applying only the memory write merge optimization decreases the load time about 9%.Individually, mandelbrot seems to enjoy the greatest benefit, with the load and validation time reduced to just 7.33% of the original time.rtexpacker, jqkungfu, and riconpacker are other beneficiaries, with the load and validation time reduced to 78.43%, 79.93%, and 87.78% of the original load and validation time, respectively.On average, applying both replay optimizations decreases the execution time to 98.40%.We believe that although the replay optimizations do not significantly affect the execution time, it gives a slight performance improvement.We are currently investigating the reasons behind.
80Note that funky-kart, despite successfully completing the experiment, is excluded from the table.This is because its replay benchmarks without replay optimizations exceeded the maximum size limit for function bodies imposed by the production Wasm engines, which prevented them from running on any engines.Thus, we discuss the performance characteristics of funky-kart here.While the function split optimization makes the replay benchmark executable, it does not affect its binary size.Applying the memory write merge optimization on top of the function split optimization reduces the load and validate time to 7.80% and the execution time to 86.31% compared to the replay benchmark with only the function split optimization applied.Thus, alongside mandelbrot, funky-kart is another example where the memory write merge optimization significantly reduces the load time and validation time of the replay benchmark, with an added benefit of reducing the execution time.
81In summary, we show that the replay optimization techniques play a crucial role in reducing the load time and validation time of performance outliers in Wasm-R3-Bench, while having a modest effect on the execution time.
Limitations
82Currently, our Wasabi-based instrumentation supports Wasm version 2.0, with the exception of the SIMD proposal.This limitation can be easily overcome by using a more up-to-date instrumentation library.Among the proposals in phase 4, which are planned to be standardized soon, the multimemory proposal is already supported by Wasm-R3.We also believe our approach can support Wasm GC with some help from the host environment.Our technique relies on making shadow copies of all mutable state and detecting modifications by comparing the shared state with the shadow state which necessitates host support, Wasm funcref and externref do not have native Wasm comparison operators.The most challenging proposal to support would be threads, which remains an open research question, as deterministic replay of racy programs lacks satisfactory and robust solutions.
Related work
83Record and replay is a mature area of research that has been explored in various contexts, including architectural support for record and replay [56], operating system-level record and replay [18,24], and language runtime-level record and replay [49].Typically, such systems require intrusive modification to the respective CPU design, kernel, libraries, or language runtime to record events, but can also be done by bytecode rewriting [29].In any case, potentially non-deterministic operations and side-effects must be identified and recorded as events.Enumerating these operations can represent significant manual work.Our approach has a different requirement in that we aim to run Wasm-R3 on any architecture, operating system, or language runtime without modification.This requirement led us to using bytecode-level instrumentation.
84Among previous instrumentation of this kind in the literature, Wasm-R3 is most similar to JSBench [45], a record and replay technique for the automated construction of JavaScript benchmarks.The major difference between JSBench and Wasm-R3 stems from the design differences in the languages they target: JavaScript and Wasm, respectively.In Wasm, instances and their host environment are cleanly separated by the import/export boundary.Thus, efficiently tracking non-determinism caused by the host environment boils down to making shadow copies of the shared mutable states and comparing them.In contrast, nearly any JavaScript operator could have unbounded side-effects.For instance, JSBench notes that a JavaScript for...in loop can be a potential source of non-determinism.This leads the authors of JSBench to describe their catalogue of non-determinism in JavaScript applications as "necessarily incomplete."We believe that the simplicity of Wasm-R3's record phase, in comparison to JSBench, is not a drawback but an advantage, demonstrating Wasm's suitability as a target for automatic benchmark generation for the web.
85Jalangi [50] is another record and replay framework for JavaScript, designed for heavy-weight dynamic analysis.While Jalangi facilitates record and replay across different environments (e.g., recording on a mobile environment and replaying on a desktop environment), it operates within the confines of JavaScript engines, which accept the same inputs and produce identical outputs.This means that, despite the convenience offered by Jalangi's record and replay functionality, it does not enable something fundamentally impossible; it is possible to have the same execution in different environments by simply running the same JavaScript code.In contrast, Wasm-R3 enables the capability to replay a Wasm instance interacting with JavaScript code in non-web Wasm engines, which is impossible without Wasm-R3.Moreover, the basic technique of Wasm-R3 could allow recording in non-web Wasm engines and replaying in web Wasm engines.Another important difference is that, unlike Wasm-R3, Jalangi applies code instrumentation in both the record and replay phases to implement the replay of the recorded trace.Although this eliminates the need to precisely determine at which point in the host code an interaction occurred, which Wasm-R3 meets, it has the disadvantage of mixing up the original code and replay code.We instead aim to preserve the original binary and its exact instruction-by-instruction behavior and only replace calls to the host with replays.Lastly, Jalangi explicitly states that they did not make any effort to optimize their implementation.In contrast, we applied numerous optimizations to the trace to enable Wasm-R3 to scale to real-world applications, and to the replay IR, to ensure the resulting replay is representative of the recorded execution.
86Other record and replay frameworks for JavaScript include Mugshot [39] and WebRR [36].Mugshot [39] records browser events and shares our goal of recording on unmodified browsers.Unlike Wasm-R3, Mugshot is tightly coupled with the web browser implementations and adopts different strategies depending on the browser.In contrast, Wasm-R3 exploits the host-agnostic nature of Wasm to record the execution of Wasm applications across all browsers.WebRR [36] proposes a record and replay technique that enhances the robustness of fragile end-to-end tests.Their primary focus is on avoiding test failures that occur without a bug or misbehavior in the application under test.In contrast, benchmarks generated from Wasm-R3 do not suffer from any kind of fragility that plagues end-to-end tests.We refer to a comprehensive survey for a more detailed discussion of dynamic analysis for JavaScript [9].
87Beyond record and replay, a lot of research has gone into Wasm.Hilbig et al. [28] proposed benchmarks of real-world binaries.Unlike the benchmarks created with Wasm-R3, their benchmarks are not executable, making them unusable for performance benchmarking.Several general-purpose techniques to dynamically analyze Wasm have been proposed, e.g., based on source-to-source instrumentation [32] or via dynamic instrumentation inside a Wasm engine [54].Other work supports reverse engineering by inferring types [33] and the purpose of functions [48] in Wasm binaries, studies security issues in Wasm [31], and shows how to use Wasm for obfuscation [47].Our work contributes to the field by providing the first record and replay technique for Wasm and a benchmark suite of executable Wasm binaries.
Conclusion
88We present Wasm-R3, the first record and replay framework for Wasm.The approach works with no modifications to the source compiler, virtual machine, host environment, operating system, or hardware.During arbitrary execution of a Wasm module within a host environment, Wasm-R3 records all interactions with the host environment, detecting updates to shared mutable memory via a shadow memory.The resulting trace is optimized to produce a precise replay binary that reproduces the original program's behavior by replaying all interactions with the host.Wasm-R3 is broadly applicable to numerous real-world Wasm applications, and the replay files it generates can be run across both web and non-web Wasm engines.Several optimizations applied at both recording and replay make infeasibly long traces tractable and reduce the overhead of trace replay for more faithful execution characteristics.We have made Wasm-R3 available as open source and hope it will be beneficial to Wasm application developers to create repeatable replays of specific executions for benchmarking and other purposes.In particular, we hope the technique can unlock a new era of Wasm benchmarking that better represents real-world use cases by routinely generating replays from real applications in their respective host environments.
Data-Availability Statement
89The artifact is available on Zenodo at [11].It includes Wasm-R3 and the Wasm-R3-Bench benchmark suite.
Fig. 3 .
90Fig. 3. Type definitions of the trace structure.
Fig. 4 .
91Fig. 4. Example of the shadow memory optimization.
Fig. 5 .
92Fig. 5. Example of the call stack optimization.
Fig. 6 .
93Fig. 6.Type definitions of the replay IR.
Fig. 7 .
94Fig. 7. Trace to replay IR translation algorithm.
95Replay IR after the optimization.
Fig. 8 .
96Fig. 8. Memory write merge optimization example.
•
97RQ1. Applicability: To what extent does Wasm-R3 apply to real-world web applications and different Wasm engines?• RQ2.Performance: How much overhead does Wasm-R3's record phase introduce?What are the performance characteristic of the replay benchmarks?• RQ3.Effectiveness of trace reduction: To what extent do our trace reduction techniques reduce the size of the recorded traces?• RQ4.Effectiveness of replay optimization: By how much do our replay optimization
Fig. 9 .
98Fig. 9. Relative increase in CPU cycles spent by the Chromium renderer process over uninstrumented application (2.0 = twice as many cycles, 1.0 = same).
99shows an excerpt of a simplified abstract syntax of Wasm.A Wasm module denotes a single binary file and consists of functions, global variables, an optional start function, and one table and memory.A function takes parameters, declares local variables, executes body instructions, and returns a sequence of results.A global variable stores a single value and can be accessed from all functions and can be either
100mutable or immutable.A start function is automatically executed when the module is loaded.A table maps function indices to opaque references to either extern (host) objects or Wasm functions.Tables can be used for indirect function calls via the call_indirect instruction.A memory represents a contiguous, byte-addressable, page-sized mutable array of memory.All of these entities can either be imported from a host execution environment, specifying a module and name pair, or exported JS Fig.2.Overview of the Wasm-R3 main phases and components.
Table 3 .
101Trace reduction experiment results.
Table 4 .
102Replay optimization experiment results.
참고문헌 25건
- Jalangi: a selective record-replay and dynamic analysis framework for JavaScript 2013 10.1145/2491411.2491447
- Versatile yet lightweight record-and-replay for Android 2015 10.1145/2814270.2814320
- An analysis of the dynamic behavior of JavaScript programs 2010 10.1145/1806596.1806598
- Automated construction of JavaScript benchmarks 2011 10.1145/2048066.2048119
- The DaCapo benchmarks 2006 10.1145/1167473.1167488
- 2017 USENIX Annual Technical Conference (USENIX ATC'17) 2017
- A Survey of Dynamic Analysis and Test Generation for JavaScript ACM Computing Surveys · Association for Computing Machinery · 2017 10.1145/3106739
- Wasabi 2019 10.1145/3297858.3304068
- RANDR: Record and Replay for Android Applications via Targeted Runtime Instrumentation 2019 10.1109/ase.2019.00022
- WebRR: self-replay enhanced robust record/replay for web application testing 2020 10.1145/3368089.3417069
- Sledge 2020 10.1145/3423211.3425680
- An Empirical Study of Real-World WebAssembly Binaries 2021 10.1145/3442381.3450138
- MiBench: A free, commercially representative embedded benchmark suite 2005 10.1109/wwc.2001.990739
- Bringing the web up to speed with WebAssembly ACM SIGPLAN Notices · Association for Computing Machinery · 2017 10.1145/3140587.3062363
- A "flight data recorder" for enabling full-system multiprocessor deterministic replay ACM SIGARCH Computer Architecture News · ACM SIGARCH · 2003 10.1145/871656.859633
- Valgrind ACM SIGPLAN Notices · Association for Computing Machinery · 2007 10.1145/1273442.1250746
- SPEC Benchmarks Springer eBooks · Springer Nature · 2011 10.1007/978-0-387-09766-4_370
- Finding the Dwarf: Recovering Precise Types from WebAssembly Binaries 2022 10.1145/3519939.3523449
- Bringing webassembly to resource-constrained iot devices for seamless device-cloud integration 2022 10.1145/3498361.3538922
- Wobfuscator: Obfuscating JavaScript Malware via Opportunistic Translation to WebAssembly 2022 IEEE Symposium on Security and Privacy (SP) · 2022 10.1109/sp46214.2022.9833626
- A fast in-place interpreter for WebAssembly Proceedings of the ACM on Programming Languages · Association for Computing Machinery · 2022 10.1145/3563311
- Automated WebAssembly Function Purpose Identification With Semantics-Aware Analysis Proceedings of the ACM Web Conference 2022 · 2023 10.1145/3543507.3583235
- Whose Baseline Compiler is it Anyway? 2024 10.1109/cgo57630.2024.10444855
- mlbench: Machine Learning Benchmark Problems 1999 10.32614/cran.package.mlbench
- doehyunbaek/wasm-r3: v0.1.0 Zenodo (CERN European Organization for Nuclear Research) · European Organization for Nuclear Research · 2024 10.5281/zenodo.13382344