🚀 Cortex Coroutine Demo

See the power of stackful coroutines in action!

60 FPS
Animation Running
Particles: 100
Computation Progress 0%
0%
Ready to start

⚡ With Coroutines

âś… Animation stays smooth!

❌ Without Coroutines

⚠️ UI will freeze!

đź’ˇ What's Happening?

âś… With Coroutines (Left Button)

The heavy computation suspends periodically, allowing the browser to:

  • Update the particle animation smoothly
  • Respond to user interactions
  • Update the progress bar in real-time
  • Keep the UI responsive throughout
❌ Without Coroutines (Right Button)

The computation runs in one continuous block, causing:

  • Particle animation freezes completely
  • Progress bar doesn't update until the end
  • Browser becomes unresponsive
  • Poor user experience

⚖️ 100% Fair Comparison: Both buttons run the EXACT SAME heavy computation—millions of trigonometric and exponential calculations simulating image processing operations. The ONLY difference is one line of code: ctx.Suspend(). There are no artificial delays or tricks! The freeze happens naturally because JavaScript/WebAssembly runs on a single-threaded event loop.

The Computation: Each iteration processes a virtual 1000×1000 pixel image with 500 operations per iteration—simulating filters, edge detection, and color transformations. You can verify the code yourself in particle_simulation.cpp: both versions call the exact same heavy_computation_step() function.

The Magic: The ctx.Suspend() call yields control back to the browser, allowing it to render frames and handle events. This is the power of stackful coroutines—you get cooperative multitasking without callbacks or promise chains!