, handles asynchronous I/O operations Core Libraries - Written in C/C++. JavaScript APIs - Thin wrappers around Core Libraries IO Operations are almost efficient as C/C++ performance
res: Response) => { const people: Person[] = req.body; if (!Array.isArray(people)) { return res.status(400).json({ message: 'Request body must be an array of persons.' }); } for (const person of people) { if ( typeof person.name !== 'string' || typeof person.age !== 'number' || typeof person.ID !== 'string' ) { return res.status(400).json({ message: 'Each person must have name (string), age (number), and ID (string).' }); } } try { const db = await connectToMongo(); const result = await db.collection('people').insertMany(people); res.status(201).json({ insertedCount: result.insertedCount, insertedIds: result.insertedIds }); } catch (error) { console.error('Insert failed:', error); res.status(500).json({ message: 'Failed to insert people.' }); } });
Low Amount Of Time Parsing JSON - CPU Exception - Large request body Transforming data structures - CPU Database Queries - IO Reading Files - IO Network Request - IO API calls - IO
• Direct Thread Access: CPU-intensive operations can run directly on threads without yielding. • Efficient Coordination: Go's channels and synchronization primitives are designed to coordinate concurrent work. • Memory Efficiency: Goroutines use minimal memory (a few KB each) compared to OS threads.
Loop • Event Loop is single-threaded. • V8 is optimized for I/O concurrency • Even with chunking, the interpreter overhead and JIT warm-up add cost. • Garbage collection pauses (especially with large ASTs or IR graphs) can introduce latency spikes. • The actual delay is governed by the browser/node event loop, and can vary. • High-load situations cause event loop lag → tasks don’t get timely execution.
Compiler ? • Verbose to manage. • Costly due to structured cloning (data copying). • Hard to coordinate shared state (e.g., symbol tables, IR graphs, caches).
worker has its own V8 instance • Data passed between threads needs to be serialized and deserialized. • Hard to coordinate shared state (symbol tables, IR graphs, caches).
Concurrency Model OS-level threads, manually created Lightweight coroutines, managed by Go runtime Startup Overhead High (new V8 instance, event loop) Tiny (~2KB per goroutine), near-zero startup cost Memory Sharing Structured cloning or SharedArrayBuffer Shared memory with channels or mutexes Execution Control Manual queueing and message passing Built-in scheduler with preemption
Code Complexity Async APIs + worker management = verbose Simple sync code with powerful concurrency primitives Performance Good for limited parallel tasks; costly to scale Excellent for high-volume, fine-grained concurrency Suitability for Compiler Feasible but harder to scale, debug, and optimize Ideal for parsing, analyzing, and transforming in parallel GC Behavior One V8 GC per thread (heavy) Unified, efficient GC tuned for concurrency
lightweight workloads, but not for heavy load computations that require real performance, parallelism, and control over execution flow. Compilers are just one example.