Published October 7, 2025 | Version v1
Conference paper Open

Optimizing WebAssembly Garbage Collection in Go: Performance Insights, Tuning Tips, and Batch Execution Strategies

  • 1. ROR icon Universidad Rovira i Virgili

Description

WebAssembly is gaining popularity these days as a portable intermediate binary format for programming languages. With a well-specified low-level virtual instruction set, low memory footprint and high-performance virtual machines, it has arisen as a lightweight alternative to containers. Even the tiniest container typically sits somewhere around tens of MBs and requires several hundred MBs of memory to run, which is infeasible in resource- constrained edge devices. Though WebAssembly has been battle- tested for memory unmanaged languages such as C++, there exists a systematic lack of investigation on managed languages such as Golang that utilize a garbage collector (GC). Taking TinyGo as a paradigmatic example, we study in this paper the implications of garbage collection for WebAssembly. We show that WebAssembly introduces some inefficiencies compared to native execution and share tips on how to raise its performance. Yet more compelling, we demonstrate that it is possible to dynamically adjust the GC by rewriting the WebAssembly binaries, and in this way, control the impact of garbage collection on the execution time by trading off extra memory. In edge contexts, this ability is essential to fine- tune the execution of a batch of WebAssembly jobs over the same physical device as shown here for the first time.

Files

Optimizing_WebAssembly_Garbage_Collection_in_Go.pdf

Files (760.7 kB)

Additional details

Funding

European Commission
CloudSkin - Adaptive virtualization for AI-enabled Cloud-edge Continuum 101092646
Universidad Rovira i Virgili
Programa de contractes predoctorals Martí-Franquès ESTÀNDARD
Ministerio de Ciencia, Innovación y Universidades
Spanish MICIU/AEI Grant ID2023-148202OB-C21

Dates

Accepted
2025-02-04
Author Notification

References

  • A. Haas et al., "Bringing the web up to speed with webassembly," SIGPLAN Not., vol. 52, no. 6, pp. 185–200, jun 2017. [Online]. Available: https://doi.org/10.1145/3140587.3062363
  • S. Hykes, "Wasm+wasi: An alternative to linux containers," 2021, accessed: January 17, 2024. [Online]. Available: https://twitter.com/solomonstre/status/1111004913222324225?lang=en
  • M. Goedtel et al., "Create webassembly system interface (wasi) node pools in azure kubernetes service (aks) to run your webassembly (wasm) workload (preview)," 2023, accessed: February 3, 2024. [Online]. Available: https://learn.microsoft.com/en-us/azure/aks/use-wasi-node-pools
  • "Kwasm – kubernetes operator for webassembly," 2023, accessed: February 5, 2024. [Online]. Available: https://kwasm.sh/
  • P. K. Gadepalli, S. McBride, G. Peach, L. Cherkasova, and G. Parmer, "Sledge: a serverless-first, light-weight wasm runtime for the edge," in 21st International Middleware Conference (Middleware'20), 2020, pp. 265–279. [Online]. Available: https://doi.org/10.1145/3423211.3425680
  • B. Li, W. Dong, and Y. Gao, "Wiprog: A webassembly-based approach to integrated iot programming," in IEEE Conference on Computer Communications (IEEE INFOCOM 2021), 2021, pp. 1–10.
  • P. Gackstatter, P. A. Frangoudis, and S. Dustdar, "Pushing serverless to the edge with webassembly runtimes," in 22nd IEEE International Symposium on Cluster, Cloud and Internet Computing (CCGrid'22), 2022, pp. 140–149.
  • J. Ménétrey, M. Pasin, P. Felber, and V. Schiavoni, "Webassembly as a common layer for the cloud-edge continuum," in 2nd Workshop on Flexible Resource and Application Management on the Edge (FRAME'22), 2022, pp. 3–8. [Online]. Available: https: //doi.org/10.1145/3526059.3533618
  • S. Shillaker and P. Pietzuch, "Faasm: Lightweight isolation for efficient stateful serverless computing," in 2020 USENIX Conference on Usenix Annual Technical Conference (USENIX ATC'20), USA, 2020.
  • D. Lehmann, J. Kinder, and M. Pradel, "Everything old is new again: Binary security of webassembly," in 29th USENIX Conference on Security Symposium (SEC'20), 2020.
  • A. Zakai, "A new way to bring garbage collected programming languages efficiently to WebAssembly," 11 2023. [Online]. Available: https://v8.dev/blog/wasm-gc-porting
  • Tinygo-Org, "wasm: switch to wasi_snapshot_preview1 by aykevl · Pull Request #1690 · tinygo-org/tinygo," 2021. [Online]. Available: https://github.com/tinygo-org/tinygo/pull/1690
  • ForgeRock, "Best practice for jvm tuning with g1 gc," 2024, accessed: May 22, 2024. [Online]. Available: https://backstage.forgerock.com/ knowledge/kb/article/a75965340
  • ——, "When to use lambda's os-only runtimes," 2024, accessed: August 2, 2024. [Online]. Available: https://docs.aws.amazon.com/ lambda/latest/dg/runtimes-provided.html
  • B. Alliance, "Wasmtime – a standalone runtime for webassembly," 2023. [Online]. Available: https://github.com/bytecodealliance/wasmtime
  • F. Denis, "Memory management in webassembly: guide for c and rust programmers," 2019. [Online]. Available: https://www.fastly.com/blog/ webassembly-memory-management-guide-for-c-rust-programmers
  • R. Wahbe, S. Lucco, T. E. Anderson, and S. L. Graham, "Efficient software-based fault isolation," SIGOPS Oper. Syst. Rev., vol. 27, no. 5, pp. 203–216, dec 1993. [Online]. Available: https://doi.org/10.1145/173668.168635
  • "The llvm compiler infrastructure," 2023. [Online]. Available: https: //github.com/llvm/llvm-project
  • "Wasi – the webassembly system interface," 2023. [Online]. Available: https://wasi.dev/
  • "wasi-libc," 2024. [Online]. Available: https://github.com/ WebAssembly/wasi-libc
  • "Benchmarks for programming languages and compilers, Which programming language or compiler is faster." [Online]. Available: https://programming-language-benchmarks.vercel.app/
  • R. Garner, S. M. Blackburn, and D. Frampton, "Effective prefetch for mark-sweep garbage collection," in 6th International Symposium on Memory Management (ISMM '07), 2007, pp. 43–54. [Online]. Available: https://doi.org/10.1145/1296907.1296915
  • H. Onozawa, T. Ugawa, and H. Iwasaki, "Fusuma: double-ended threaded compaction," in 2021 ACM SIGPLAN International Symposium on Memory Management (ISMM 2021), 2021, pp. 94–106. [Online]. Available: https://doi.org/10.1145/3459898.3463903
  • B. Alliance, "Cranelift code generator," 2023. [Online]. Available: https://github.com/bytecodealliance/wasmtime/tree/main/cranelift
  • H. Xu and F. Kjolstad, "Copy-and-patch compilation: a fast compilation algorithm for high-level languages and bytecode," Proc. ACM Program. Lang., vol. 5, no. OOPSLA, oct 2021. [Online]. Available: https://doi.org/10.1145/3485513
  • "Benchmarks for bigcache project," 2024, accessed: February 8, 2024. [Online]. Available: https://github.com/allegro/bigcache-bench
  • C. Bays, "A comparison of next-fit, first-fit, and best-fit," Commun. ACM, vol. 20, no. 3, pp. 191–192, Mar. 1977. [Online]. Available: https://doi.org/10.1145/359436.359453
  • R. Jones and R. Lins, Garbage collection: algorithms for automatic dynamic memory management, USA, 1996.
  • Abhinav and R. Nasre, "Fastcollect: offloading generational garbage collection to integrated gpus," in International Conference on Compilers, Architectures and Synthesis for Embedded Systems (CASES '16), 2016. [Online]. Available: https://doi.org/10.1145/2968455.2968520
  • N. Cohen and E. Petrank, "Data structure aware garbage collector," SIGPLAN Not., vol. 50, no. 11, pp. 28–40, Jun. 2015. [Online]. Available: https://doi.org/10.1145/2887746.2754176
  • S. Tavakolisomeh, M. Shimchenko, E. Österlund, R. Bruno, P. Ferreira, and T. Wrigstad, "Heap size adjustment with cpu control," in 20th ACM SIGPLAN International Conference on Managed Programming Languages and Runtimes (MPLR 2023), 2023, pp. 114–128. [Online]. Available: https://doi.org/10.1145/3617651.3622988
  • V. Jalaparti, P. Bodik, I. Menache, S. Rao, K. Makarychev, and M. Caesar, "Network-aware scheduling for data-parallel jobs: Plan when you can," in 2015 ACM Conference on Special Interest Group on Data Communication (SIGCOMM '15), New York, NY, USA, 2015, pp. 407–420. [Online]. Available: https://doi.org/10.1145/2785956.2787488
  • M. Kirisame, P. Shenoy, and P. Panchekha, "Optimal heap limits for reducing browser memory use," Proc. ACM Program. Lang., vol. 6, no. OOPSLA2, Oct. 2022. [Online]. Available: https: //doi.org/10.1145/3563323
  • X. Shang, Y. Zhang, F. Li, A. Sampath, and G. Baliga, "Tricks of the trade: Tuning jvm memory for large-scale services," 2020, accessed: September 11, 2024. [Online]. Available: https://eng.uber. com/jvm-tuning-garbage-collection/
  • T. Rust and W. W. Group, "Walrus," 2024, accessed: January 14, 2024. [Online]. Available: https://github.com/rustwasm/walrus
  • Google, "Google or-tools," 2024, accessed: July 17, 2024. [Online]. Available: https://developers.google.com/optimization/
  • T. Heo, "Control group, v2," 2015, accessed: June 18, 2024. [Online]. Available: https://www.kernel.org/doc/html/latest/ admin-guide/cgroup-v2.html
  • A. Jangda, B. Powers, E. D. Berger, and A. Guha, "Not so fast: Analyzing the performance of WebAssembly vs. native code," in 2019 USENIX Annual Technical Conference (USENIX ATC 19), Renton, WA, Jul. 2019, pp. 107–120. [Online]. Available: https://www.usenix.org/conference/atc19/presentation/jangda
  • Y. Zhang et al., "Characterizing and detecting webassembly runtime bugs," ACM Trans. Softw. Eng. Methodol., vol. 33, no. 2, Dec. 2023. [Online]. Available: https://doi.org/10.1145/3624743
  • Z. Liu, D. Xiao, Z. Li, S. Wang, and W. Meng, "Exploring missed optimizations in webassembly optimizers," in 32nd ACM SIGSOFT International Symposium on Software Testing and Analysis (ISSTA '23), 2023, pp. 436–448. [Online]. Available: https://doi.org/10.1145/ 3597926.3598068
  • T. Brecht, E. Arjomandi, C. Li, and H. Pham, "Controlling garbage collection and heap growth to reduce the execution time of java applications," in 16th ACM SIGPLAN Conference on Object-Oriented Programming, Systems, Languages, and Applications (OOPSLA '01), 2001, pp. 353–366. [Online]. Available: https: //doi.org/10.1145/504282.504308
  • D. R. White, J. Singer, J. M. Aitken, and R. E. Jones, "Control theory for principled heap sizing," in Proceedings of the 2013 International Symposium on Memory Management (ISMM '13), 2013, pp. 27–38. [Online]. Available: https://doi.org/10.1145/2491894.2466481
  • U. Degenbaev, J. Eisinger, M. Ernst, R. McIlroy, and H. Payer, "Idle time garbage collection scheduling," in 37th ACM SIGPLAN Conference on Programming Language Design and Implementation (PLDI '16), 2016, pp. 570–583. [Online]. Available: https://doi.org/10. 1145/2908080.2908106