我构建了一个 C++ 运行时,其中包含不可变对象且没有全局解释器锁 (GIL)。
1 分•作者: gamarino•17 天前
在过去的几个月里,我一直在重新思考动态语言运行时应该如何与现代硬件交互。 结果是 ProtoCore 及其第一个主要实现 ProtoJS。
大多数动态运行时(Python、Ruby,甚至 JS 引擎)通过全局解释器锁(GIL)或复杂的内存屏障来处理并发,因为跨线程管理可变状态是出了名的困难。
使用 ProtoCore,我采取了一条不同的道路,基于三个支柱:
默认不可变性:所有核心数据结构都是不可变的。 我们使用结构共享来实现内存效率,而不是锁定。 这从根本上消除了对象级别的数据竞争。
硬件感知内存模型:对象是缓存行对齐的(64 字节单元),以防止错误共享并优化缓存局部性。
标记指针:我们使用 56 位嵌入式有效载荷来表示 SmallIntegers,这意味着大多数数值运算不需要堆分配。
为了验证该架构,我构建了 ProtoJS。 它使用 QuickJS 进行解析,但用 ProtoCore 原语替换了整个运行时。 这允许真正的 worker 线程执行(“Deferred”),其中不可变对象在线程之间共享,无需复制或与 GIL 相关的争用。
当前状态:
ProtoCore:100% 的测试通过率(50/50 个测试),并且今天完成了全面的技术审计。
ProtoJS:第一阶段完成,展示了真正的并行执行和低于 1 毫秒的 GC 暂停。
我是一名电子工程师(现在是大学教授),我想看看应用底层硬件原理是否可以解决高级并发“混乱”。
我很想听听您对这种在系统编程中采用的不可变优先方法的权衡的看法。
ProtoCore(引擎):https://github.com/numaes/protoCore ProtoJS(JS 运行时):https://github.com/gamarino/protoJS
查看原文
I’ve spent the last few months rethinking how a dynamic language runtime should interact with modern hardware. The result is ProtoCore and its first major implementation, ProtoJS.<p>Most dynamic runtimes (Python, Ruby, and even JS engines) handle concurrency through Global Interpreter Locks (GIL) or complex memory barriers because managing mutable state across threads is notoriously difficult.<p>With ProtoCore, I took a different path based on three pillars:<p>Immutability by Default: All core data structures are immutable. Instead of locking, we use structural sharing for memory efficiency. This inherently eliminates data races at the object level.<p>Hardware-Aware Memory Model: Objects are cache-line aligned (64-byte cells) to prevent false sharing and optimize cache locality.<p>Tagged Pointers: We use a 56-bit embedded payload for SmallIntegers, meaning zero heap allocation for most numeric operations.<p>To prove the architecture, I built ProtoJS. It uses QuickJS for parsing but replaces the entire runtime with ProtoCore primitives. This allows for real worker thread execution ("Deferred") where immutable objects are shared across threads without copying or GIL-related contention.<p>Current Status:<p>ProtoCore: 100% test pass rate (50/50 tests) and a comprehensive technical audit completed today.<p>ProtoJS: Phase 1 complete, demonstrating real parallel execution and sub-1ms GC pauses.<p>I’m an Electronic Engineer by training (now a university professor), and I wanted to see if applying low-level hardware principles could fix the high-level concurrency "mess."<p>I’d love to hear your thoughts on the trade-offs of this immutable-first approach in systems programming.<p>ProtoCore (The engine): https://github.com/numaes/protoCore ProtoJS (The JS runtime): https://github.com/gamarino/protoJS