Skip to content

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Goruntime Kernel

license

Native Go WebAssembly Engine for GoRuntime Studio β€” high-fidelity simulation of Go runtime internals (GMP scheduler, channels, memory allocator, GC) compiled to WebAssembly and bridged to Svelte 5 via a zero-copy binary event protocol.


🎯 Purpose

goruntime-kernel is the computational core of GoRuntime Studio. It replaces the legacy TypeScript-based simulation engine with a native Go runtime compiled to WebAssembly, delivering:

  • 100% semantic fidelity β€” real Go code for hchan, sudog, G/M/P scheduling, and memory management
  • 60 FPS performance β€” zero-allocation binary event streaming via SharedArrayBuffer RingBuffer
  • Deterministic time-travel debugging β€” memory snapshots for stepping forward and backward through execution

πŸ—οΈ Architecture Overview

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  SVELTE 5 STUDIO UI                                                         β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚ Header.svelte   │───▢│ timeline.store.svelte.ts│───▢│CanvasView.slt β”‚    β”‚
β”‚  β”‚ Controls & Step β”‚    β”‚ State, History & Issues β”‚    β”‚ 2D Graph Nodesβ”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚           β”‚                        β–²                           β–²            β”‚
β”‚           β”‚ Dispatch Command       β”‚ Update Reactive Nodes     β”‚            β”‚
β”‚           β–Ό                        β”‚                           β”‚            β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”            β”‚
β”‚  β”‚ sync.bridge.ts β€” Binary Event Decoder & State Sync          β”‚            β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜            β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                    β”‚ Invoke Exported Functions
                                    β–Ό
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚  GO WASM ENGINE SANDBOX                                                     β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚ Wasm Control API (cmd/wasm/main.go)                                 β”‚    β”‚
β”‚  β”‚ stepSend, stepReceive, spawnGoroutine, createSnapshot, restoreSnap  β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚           β”‚                        β”‚                        β”‚               β”‚
β”‚           β–Ό 1. Trigger Execution   β–Ό 2. Save/Restore        β–Ό 3. Channel Opsβ”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚ GO ENGINE CORE (pkg/)                                               β”‚    β”‚
β”‚  β”‚ β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚    β”‚
β”‚  β”‚ β”‚ pkg/gmp     β”‚  β”‚ pkg/memory  β”‚  β”‚ pkg/channelsβ”‚  β”‚ pkg/snapshot β”‚ β”‚    β”‚
β”‚  β”‚ β”‚ Scheduler   β”‚  β”‚ Virtual Mem β”‚  β”‚ hchan/sudog β”‚  β”‚ Serializationβ”‚ β”‚    β”‚
β”‚  β”‚ β”‚ G, M, P     β”‚  β”‚ MHeap/MCacheβ”‚  β”‚ Wait Queues β”‚  β”‚ Time-Travel  β”‚ β”‚    β”‚
β”‚  β”‚ β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜ β”‚    β”‚
β”‚  β”‚           β”‚                        β”‚                        β”‚       β”‚    β”‚
β”‚  β”‚           β–Ό 3. Emit State Changes  β–Ό 4. Emit Events         β–Ό       β”‚    β”‚
β”‚  β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚    β”‚
β”‚  β”‚  β”‚ pkg/eventstream β€” 16-byte Binary Event Streamer             β”‚    β”‚    β”‚
β”‚  β”‚  β”‚ Fixed packets: G-M-P, Sudog, GC, Memory Alloc               β”‚    β”‚    β”‚
β”‚  β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β”‚                                    β”‚ 4. Push Binary Events                  β”‚
β”‚                                    β–Ό                                        β”‚
β”‚  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”‚
β”‚  β”‚ SharedArrayBuffer β€” Atomic RingBuffer Event Queue                   β”‚    β”‚
β”‚  β”‚ Zero-copy, lock-free, 60 FPS                                        β”‚    β”‚
β”‚  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“¦ Binary Event Protocol

All communication between the Go Wasm kernel and the Svelte 5 UI occurs through a 16-byte fixed-size binary packet written into a SharedArrayBuffer RingBuffer.

16-Byte Packet Layout

Offset Size Field DataView Type Description
0–1 2 B EventOp uint16 Operation code (spawn, park, chan send, mem alloc, etc.)
2–5 4 B EntityID uint32 Primary entity ID (Goroutine G, Channel hchan, etc.)
6–9 4 B TargetID uint32 Secondary / target ID (Processor P, sudog, address)
10–13 4 B ValueState uint32 Value, state, stack size, GC color, flags
14–15 2 B Sequence uint16 Monotonically increasing timeline step counter

EventOp Codes

Code Name Semantics
0x0001 EV_G_SPAWN New goroutine G created (Gidle β†’ Grunnable)
0x0002 EV_G_SCHEDULE Goroutine assigned to Processor P (Grunnable β†’ Grunning)
0x0003 EV_G_PARK Goroutine parked / blocked (Grunning β†’ Gwaiting)
0x0004 EV_G_UNPARK Goroutine unblocked (Gwaiting β†’ Grunnable)
0x0005 EV_G_DIE Goroutine execution completed (Grunning β†’ Gdead)
0x0010 EV_CHAN_SEND Successful send into hchan
0x0011 EV_CHAN_RECV Successful receive from hchan
0x0012 EV_CHAN_BLOCK Blocking on channel, sudog enqueued
0x0013 EV_CHAN_UNBLOCK sudog removed from wait queue, G unblocked
0x0020 EV_MEM_ALLOC Heap allocation via MCache / MSpan
0x0021 EV_STACK_GROW Stack expanded, copystack executed
0x0022 EV_GC_MARK Object marked during tri-color GC phase

RingBuffer Header (first 16 bytes of SharedArrayBuffer)

Offset Size Field Description
0–3 4 B HeadIndex Next write position (updated by Go Wasm)
4–7 4 B TailIndex Last read position (updated by TypeScript)
8–11 4 B Capacity Max number of events in buffer (e.g. 4096)
12–15 4 B DroppedEvents Counter of lost events on overflow

πŸš€ Quick Start

Prerequisites

Build the Wasm Engine

# Clone the repository
git clone https://github.com/DenysSkobalo/goruntime-kernel.git
cd goruntime-kernel

# Compile Go engine to WebAssembly
make build-wasm
# β†’ dist/engine.wasm

Run Quality Checks

# Full pre-flight check (format, lint, test, build)
make check

# Individual targets
make test      # Run Go unit tests
make bench     # Run benchmarks
make lint      # Run golangci-lint
make fmt       # Format Go source files
make clean     # Remove build artifacts

Integrate with GoRuntime Studio

Copy the generated artifact into the Studio frontend:

cp dist/engine.wasm ../goruntime-studio/public/

The Svelte 5 bridge (sync.bridge.ts) will automatically load the Wasm module and begin polling the SharedArrayBuffer RingBuffer at 60 FPS via requestAnimationFrame.


πŸ“ Project Structure

engine/
β”œβ”€β”€ cmd/wasm/main.go          # Wasm entrypoint, syscall/js bindings
β”œβ”€β”€ pkg/
β”‚   β”œβ”€β”€ eventstream/            # Binary Event Encoder & SharedArrayBuffer RingBuffer
β”‚   β”œβ”€β”€ gmp/                    # Scheduler Engine (G, M, P queues, Work-Stealing)
β”‚   β”œβ”€β”€ channels/               # Channel Logic (hchan, sudog, WaitQ)
β”‚   β”œβ”€β”€ memory/                 # Virtual Memory Layout (MHeap, MCache, copystack, GC)
β”‚   └── snapshot/               # Memory Snapshot & Serialization Engine
β”œβ”€β”€ go.mod
β”œβ”€β”€ go.sum
β”œβ”€β”€ Makefile                    # Build, test, lint, format automation
β”œβ”€β”€ .golangci.yml               # Linter configuration
β”œβ”€β”€ package.json                # Node tooling (husky, commitlint, lint-staged)
└── .github/workflows/ci.yml    # GitHub Actions CI pipeline

πŸ“„ Documentation

Document Purpose
DEVELOPMENT.md Deep-dive engineering spec: RingBuffer algorithms, GMP scheduler, channels, memory, snapshots
CONTRIBUTING.md Contribution guidelines: branching model, GoDoc standards, Conventional Commits, PR checklist
SECURITY.md Security policy and vulnerability disclosure
ADR-001 Architectural Decision Record: migration from TS to Go Wasm
TES-001 Technical Engine Specification: binary protocol, component APIs, migration plan

🀝 Contributing

We welcome contributions! Please read CONTRIBUTING.md for our branching model, code standards, and PR process.

All PRs must target the develop branch and pass make check.


πŸ“œ License

MIT License Β© 2026 Denys Skobalo

About

No description, website, or topics provided.

Resources

Code of conduct

Contributing

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages