Skip to content

Commit 2403bce

Browse files
committed
.
1 parent 14b0fd0 commit 2403bce

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

blog/2025/Traps to Developers.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,7 @@ This article spans a wide range of knowledge. If you find a mistake or have a su
290290
- In GitHub, if there is a private repo A and you forked it as B (also private), then when A become public, the private repo B's content is also publicly accessible, even after deleting B. [See also](https://trufflesecurity.com/blog/anyone-can-access-deleted-and-private-repo-data-github).
291291
- GitHub by default allows deleting a release tag, and adding a new tag with same name, pointing to another commit.
292292
- `git stash pop` does not drop the stash if there is a conflict.
293+
- In Windows, Git often auto-convert cloned text files to be CRLF line ending. But in WSL many software (e.g. bash) doesn't work with files with CRLF. Using `git clone --config core.autocrlf=false -c core.eol=lf ...` can make git clone as LF.
293294
- MacOS auto adds `.DS_Store` files into every folder. It's recommended to add `**/.DS_Store` into `.gitignore`.
294295

295296
### Networking

blog/2025/WebAsembly Limitations.md

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -234,24 +234,41 @@ There was [Web IDL Bindings Proposal](https://github.com/WebAssembly/interface-t
234234

235235
Currently Wasm cannot be run in browser without JS code that bootstraps Wasm.
236236

237-
## Debugging
237+
## Memory64 performance
238+
239+
The original version of Wasm only supports 32-bit address and up to 4GiB linear memory.
238240

241+
In Wasm, a linear memory has a finite size. Accessing an address out of size need to trigger a [trap](https://webassembly.github.io/spec/core/intro/overview.html) that aborts execution. Normally, to implement that range checking, the runtime need to insert branches to each linear memory access.
239242

243+
But Wasm runtimes have an optimization: map the 4GB linear memory to a virtual memory space. The out-of-range pages are not allocated from OS, so accessing them cause error from OS. Wasm runtime can use signal handling to handle these error.
240244

241-
## Dynamically loading new code
245+
That optimization doesn't work when supporting 64-bit address. There is no enough virtual address space to hold Wasm linear memory. So the branches of range checking still need to be inserted for every linear memory access. This costs performance.
242246

247+
See also: [Is Memory64 actually worth using?](https://spidermonkey.dev/blog/2025/01/15/is-memory64-actually-worth-using.html)
243248

244-
### Wasm sections
249+
## Debugging
245250

251+
As Wasm runs inside VM, debugging relies on VM's functionality.
246252

253+
(TODO)
247254

255+
## Hot reload that keeps execution state
248256

249-
## Hot reload with execution state preservation
257+
It's easy to load new Wasm code in browser, without keeping Wasm execution state.
250258

259+
During development, hot reloading Wasm code while keeping execution state can improve iteration speed. Without hot reload, the developer changed the code need to re-enter the same application state to test changes.
251260

252-
## Memory64 performance
261+
Java and C# supports hot reloading (Java only supports changing function body or inlined constants), with the help of their runtime. Just being able to reload function body is already useful. [See also](https://loglog.games/blog/leaving-rust-gamedev/#hot-reloading-is-more-important-for-iteration-speed-than-people-give-it-credit-for)
262+
263+
In native applications, hot reload often requires advanced machine code instumentation. Because it need to be done while application is running. Keeping the execution state and adapting it to new code is hard.
253264

265+
Web code runs in event loop. After one cycle of event loop, there is no Wasm or JS code running. Now the only execution state become linear memory, globals and tables, etc. The stack and code execution position doesn't exist and don't need to be kept. It's theoretically possible to do hot swap during that, by creating a new Wasm module using new code, creating a new Wasm instance using new module, with the old linear memory, globals, tables etc. Related details:
254266

267+
- The initialization code that resets some global state need to be skipped after hotswap.
268+
- The layout of data section changes. Data sections are loaded into linear memory during startup. The original pointers (including strings) pointing into data section need to still work. One solution is to place new data section in new places, which wastes some memory. As that hot swapping is intended to be only used in development, wasting some memory is fine. The address of global constants need to be relocated (can reuse existing dynamic linking functionality).
269+
- If the data structure in linear memory changes, it won't work, unless there is no such data in linear memory. This also includes Rust futures. Async functions cannot be easily be hot reloaded.
270+
- All references to Wasm-exported functions in JS need to be replaced with new ones, otherwise it will still execute old Wasm instance.
271+
- It doesn't work with [JS Promise integration](https://github.com/WebAssembly/js-promise-integration), as the Wasm runtime manages the stack for that.
255272

256273
## Appendix
257274

0 commit comments

Comments
 (0)