<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/my-experience-with-asm-js-f1utaynyl" -->

---
title: My experience with asm.js | daily.dev
description: A developer recounts porting a C library (a Fibonacci example standing in for the Glitch music app's sound engine) to asm.js using Emscripten, after hitting...
canonical: https://daily.dev/posts/my-experience-with-asm-js-f1utaynyl
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: My experience with asm.js | daily.dev
og:description: A developer recounts porting a C library (a Fibonacci example standing in for the Glitch music app's sound engine) to asm.js using Emscripten, after hitting...
og:url: https://daily.dev/posts/my-experience-with-asm-js-f1utaynyl
og:image: https://api.daily.dev/og/posts/f1UTaynYL.png
og:image:alt: My experience with asm.js
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# My experience with asm.js

**[zserge's blog](https://daily.dev/sources/zserge)** · 6 min read · 0 upvotes · 0 comments

## Summary

A developer recounts porting a C library (a Fibonacci example standing in for the Glitch music app's sound engine) to asm.js using Emscripten, after hitting performance limits in pure JavaScript. The walkthrough covers installing Emscripten, exporting C functions with EXPORTED_FUNCTIONS, calling them via ccall/cwrap, handling struct-like data with manual constructors/destructors, and gotchas around -O3 optimization: asynchronous memory initializer files, the onRuntimeInitialized callback, web worker URL issues, and slow Webpack builds. The piece closes by noting asm.js sped up Glitch even in Chrome (which lacks native asm.js support) and mentions WebAssembly as a future, smaller/faster successor.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://zserge.com/posts/my-experience-with-asmjs>

## Questions this post answers

### How do I export specific C functions when compiling with Emscripten to asm.js?

Use the EXPORTED_FUNCTIONS compiler flag with underscore-prefixed function names, for example: emcc fib.c -o fib.js -s EXPORTED_FUNCTIONS="['_fib_next','_fib_binet']". Without this flag, Emscripten's emcc will compile libc helpers like malloc and memset into the output but omit your own functions entirely, so calling them from JavaScript will fail silently.

_daily.dev surfaces practical Emscripten workflows for developers compiling C to the web._

### Why does my Emscripten-compiled asm.js code stop working after enabling -O3 optimization?

With -O2 or -O3, Emscripten moves initial memory contents into a separate file loaded asynchronously via XHR instead of inlining them as JavaScript arrays, so global variables and constants hold invalid values at startup. Register Module['onRuntimeInitialized'] to run code only after memory finishes loading, and set Module['memoryInitializerPrefixURL'] when running inside web workers that lack window.location.

_developers debugging asm.js optimization quirks can track these gotchas on daily.dev._

## Similar posts on daily.dev

- [When Should JavaScript Devs Use the Power of WebAssembly?](https://daily.dev/posts/when-should-javascript-devs-use-the-power-of-webassembly--9u3gr182s) · The New Stack · 3 upvotes · 0 comments
- [The 7 Walls JavaScript Hits — and How WebAssembly Gets Past Them](https://daily.dev/posts/the-7-walls-javascript-hits-and-how-webassembly-gets-past-them-isxmm7isd) · DEV · 2 upvotes · 0 comments
- [Your First WebAssembly Program and Web App \(Written, Tested, and Deployed Entirely in the Web Browser\)](https://daily.dev/posts/your-first-webassembly-program-and-web-app-written-tested-and-deployed-entirely-in-the-web-browse-52yjwamn5) · Towards Data Science · 1 upvotes · 1 comments
- [Making WebAssembly a first-class language on the Web](https://daily.dev/posts/making-webassembly-a-first-class-language-on-the-web-esexmyltz) · Mozilla Hacks · 0 upvotes · 0 comments

---

Tags: [#javascript](https://daily.dev/tags/javascript), [#c](https://daily.dev/tags/c), [#webassembly](https://daily.dev/tags/webassembly)

[View this post on daily.dev](https://daily.dev/posts/my-experience-with-asm-js-f1utaynyl)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"My experience with asm.js","url":"https://daily.dev/posts/my-experience-with-asm-js-f1utaynyl","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/my-experience-with-asm-js-f1utaynyl"},"datePublished":"2026-08-23T10:20:18.526Z","dateModified":"2026-08-23T10:22:00.390Z","description":"A developer recounts porting a C library (a Fibonacci example standing in for the Glitch music app's sound engine) to asm.js using Emscripten, after hitting...","image":"https://media.daily.dev/image/upload/s--1KxV4ohY--/f_auto/v1722860400/public/Placeholder%2007","thumbnailUrl":"https://media.daily.dev/image/upload/s--1KxV4ohY--/f_auto/v1722860400/public/Placeholder%2007","isAccessibleForFree":true,"articleSection":"zserge's blog","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"zserge's blog","logo":"https://media.daily.dev/image/upload/s--KQnFBOIT--/f_auto,q_auto/v1787480407/logos/zserge","url":"https://daily.dev/sources/zserge"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/my-experience-with-asm-js-f1utaynyl","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"javascript,c,webassembly","timeRequired":"PT6M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"zserge's blog","item":"https://daily.dev/sources/zserge"},{"@type":"ListItem","position":3,"name":"My experience with asm.js"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/my-experience-with-asm-js-f1utaynyl#faq","mainEntity":[{"@type":"Question","name":"How do I export specific C functions when compiling with Emscripten to asm.js?","acceptedAnswer":{"@type":"Answer","text":"Use the EXPORTED_FUNCTIONS compiler flag with underscore-prefixed function names, for example: emcc fib.c -o fib.js -s EXPORTED_FUNCTIONS=\"['_fib_next','_fib_binet']\". Without this flag, Emscripten's emcc will compile libc helpers like malloc and memset into the output but omit your own functions entirely, so calling them from JavaScript will fail silently. daily.dev surfaces practical Emscripten workflows for developers compiling C to the web."}},{"@type":"Question","name":"Why does my Emscripten-compiled asm.js code stop working after enabling -O3 optimization?","acceptedAnswer":{"@type":"Answer","text":"With -O2 or -O3, Emscripten moves initial memory contents into a separate file loaded asynchronously via XHR instead of inlining them as JavaScript arrays, so global variables and constants hold invalid values at startup. Register Module['onRuntimeInitialized'] to run code only after memory finishes loading, and set Module['memoryInitializerPrefixURL'] when running inside web workers that lack window.location. developers debugging asm.js optimization quirks can track these gotchas on daily.dev."}}]}
```

