Share E-Book
Scan to open this page

Scan with your phone to open this page

Author: Rick Battagline

Rating No ratings yet

A thorough, practice-based introduction to WebAssembly. Learn how to create high-performing, lightning-fast websites and applications. WebAssembly is the fast, compact, portable technology that optimizes the performance of resource-intensive web applications and programs. The Art of WebAssembly is designed to give web developers a solid understanding of how it works, when to use it (and when not to), and how to develop and deploy WebAssembly apps. First you’ll learn how to optimize and compile low-level code, debug and evaluate WebAssembly, and represent WebAssembly in the human-readable WebAssembly Text (WAT) format. Once you have the basics down, you’ll build a browser-based collision detection program, work with browser rendering technologies to create graphics and animations, and see how WebAssembly interacts with other web languages. You’ll also learn how to: • Embed WebAssembly applications in web browsers and Node.js • Use browser debuggers to evaluate your WebAssembly code • Format variables, loops, functions, strings, data structures, and conditional logic in WAT • Manipulate memory • Build a program that generates graphical objects and detects when they collide • Evaluate the output of a WebAssembly compiler The Art of WebAssembly will help you make sense of this powerful technology to boost the performance of your web applications. Author Bio Rick Battagline is a game developer and author of Hands-On Game Development with WebAssembly (Packt Publishing, 2019). In 2006 he founded BattleLine Games LLC, an independent game studio focused on web games. Since then, he has written hundreds of games developed in various web technologies including WebAssembly, HTML5, WebGL, JavaScript, TypeScript, ActionScript, and PHP. He’s a member of the WebAssembly Community Group, and the AssemblyScript Community Group. Reviews "This book is a clear and step-by-step approach to WebAssembly. Rick Battagl

AI Reading Assistant

Whole-book reading guide from stratified index samples; jump to passages in the text

AI guide
【One-Line Pitch】 A hands-on guide to WebAssembly for web developers who want to understand what happens under the hood—from WAT syntax and linear memory to canvas graphics and performance tuning—and who prefer building real projects over reading theory. Best for developers with some JavaScript and low-level curiosity, especially those working on games, graphics, or compute-heavy web apps. 【Book Arc】 - **Opening (~0%–15%)**: Frames why WebAssembly exists—performance and throughput limits of JavaScript, when to use Wasm and when not to—and sets up the toolchain (Node.js, npm, wat-wasm) used throughout the book. - **Early (~15%–35%)**: Teaches WebAssembly Text (WAT) fundamentals: stack-machine execution, S-expression vs. linear syntax, locals, arithmetic, and control flow such as if/else and loops. - **Middle (~35%–55%)**: Moves into functions, tables, indirect calls, bit manipulation, strings, and linear memory, including how data crosses the JavaScript/Wasm boundary and the cost of external calls. - **Late (~55%–80%)**: Applies the fundamentals to browser work—web applications, the canvas, graphics and animation, and a collision-detection program—then covers optimization and debugging with browser tools. - **Ending (~80%–100%)**: Introduces AssemblyScript as a TypeScript-like path to compiling WebAssembly, followed by final thoughts on where the technology fits. 【Key Takeaways】 - **WebAssembly is not a JavaScript replacement** (Early): It excels at computationally intensive tasks—games, WebVR, 3D math, crypto—and is not a drop-in substitute for frameworks like React or Vue. - **Performance gains are not automatic** (Early): Porting code without understanding the low-level model can yield disappointing results; optimization flags and profiling matter. - **WAT is a readable window into Wasm** (Early–Middle): Stack-based execution, S-expression and linear syntax, locals, and control flow are all learnable and make compiled output interpretable. - **Control flow has its own rules** (Middle): Loops do not iterate on their own—they need explicit branches—and booleans are represented as i32 values, with nonzero treated as true. - **Memory and data exchange are the hard part** (Middle): Linear memory, strings, and data structures require manual handling, and only certain types can cross into JavaScript; 64-bit integers are not yet passable. - **External calls carry overhead** (Middle): Calling JavaScript from Wasm inside tight loops adds measurable cost, so boundary crossings should be minimized in hot paths. - **The browser is a first-class target** (Late): Canvas rendering, animation, and collision detection show how Wasm integrates with existing web rendering technologies. - **AssemblyScript lowers the barrier** (Ending): A TypeScript-like language compiles to small, efficient Wasm, offering an alternative to systems languages for web-focused developers. 【Reading Tips】 - Read the WAT chapters (roughly 15%–35%) slowly and type out the examples; the stack model only clicks through practice. - Skim the Node.js and tool installation sections if you already have a working environment, but do not skip the importObject and instantiation examples—they are the bridge to every later project. - Treat the canvas and collision-detection chapters as the payoff: they consolidate memory, functions, and rendering into one working application. - Use the debugging and optimization chapters as reference material to revisit after you have your own Wasm code to profile. - If you come from a JavaScript background, pay extra attention to the data-type boundary rules; they are the most common source of confusion. 【Coverage Limits】 This guide is based on stratified excerpts covering the front matter, table of contents, and selected early-to-middle chapters; later chapters on canvas, optimization, debugging, and AssemblyScript are summarized from the table of contents and brief mentions rather than detailed content. Specific code listings, benchmarks, and chapter-level arguments beyond those excerpts are not covered.
Excerpt 1
bly Community Group, and the AssemblyScript Community Group. Reviews "This book is a clear and step-by-step approach to WebAssembly. Rick Battagl T H E A R T...
View in text
Excerpt 2
ipt or a framework, such as Angular, React, or Vue. If you want to work with WebAssembly right now, you should have a specific com- putationally intensive pr...
View in text
Excerpt 3
ect); 2 ({helloworld: hello_world} = obj.instance.exports); 3 hello_world(); Listing 2-10: Instantiating the WebAssembly module in an asynchronous IIFE The f...
View in text
Excerpt 4
t floating-point numbers. At the time of this writing, you can’t pass 64-bit integers to a JavaScript function. The BigInt WebAssembly proposal will change t...
View in text
Excerpt 5
t from decimal to hex manually, because I’ll assume you’re either familiar with how to do it or have access to a calculator; most calcula- tor apps offer a p...
View in text
Excerpt 6
ning of this module imports a $print_string 1 function and one page of linear memory 2 from JavaScript. Next, we define a data 3 ele- ment with an array of c...
View in text
Excerpt 7
Script file for a new example app named data_structures.js. In this app, we’ll create data structures that represent circles in memory. Later, we’ll perform...
View in text
Excerpt 8
f the memory buffer 6 let bytes = new Uint8Array(memory.buffer, 1024, len); // convert the bytes taken from linear memory into a // JavaScript string and use...
View in text
Tags
AI categories
Web TechnologyProgramming LanguageSoftware
ISBN: 1718501455
Publisher: No Starch Press
Publish Year: 2021
Language: English
Pages: 304
File Format: PDF
File Size: 11.0 MB
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

Generating text preview…