Overview of regorusjs
mainregorusjs is the WebAssembly (WASM) compilation of Regorus, a fast and lightweight Rego interpreter written in Rust. It is designed to be a rigorous enforcer of well-defined Rego semantics within WASM environments.repository·main·Indexed 43 days ago
https://github.com/microsoft/regorusA high-performance, lightweight Rego (OPA policy language) interpreter written in Rust. Designed for rigorous enforcement of Rego semantics, it supports both standard and no_std environments, including Confidential Computing. It includes C# bindings for executing policies via the Regorus Virtual Machine (RVM) API, support for Azure RBAC conditions, and the ability to compile and evaluate native Azure Policy JSON rule definitions.
regorusjs is the WebAssembly (WASM) compilation of Regorus, a fast and lightweight Rego interpreter written in Rust. It is designed to be a rigorous enforcer of well-defined Rego semantics within WASM environments.Regorus is a fast, lightweight, and rigorous Rego interpreter written in Rust. It is designed to be cross-platform, no_std compatible, and highly extensible.
Key features include:
v1 and is mostly compliant with OPA release v1.2.0.add_extension.mimalloc (pronounced "me-malloc") is a high-performance, general-purpose allocator designed for low-latency and large-scale services. Key design features include:
free operations.mimalloc is a general-purpose memory allocator designed to perform well across a wide range of workloads. In benchmark testing, it has been shown to outperform other leading allocators like jemalloc, tcmalloc, Hoard, and the default glibc allocator, while maintaining a similar memory footprint.
Key performance characteristics include:
LeanN theorem prover benchmark) due to better allocation locality.larsonN and mstressN benchmarks).xmalloc-testN) by using non-contended sharded thread free lists.The Rego Virtual Machine (RVM) instruction set consists of opcodes emitted by the compiler and executed by the RegoVM. Instructions are categorized by their functionality, such as arithmetic, loops, or host interaction.
rX), literals (litY), parameter indices (pZ), and immediate values.InstructionData. Instructions reference this metadata via an index (pN).Continue, Return, Break, or Suspend.The memory budget tracks additional live bytes during the RVM execution window.
CString allocation.string allocation (these occur after the C FFI execution window has closed).Secure mode is a build configuration enabled via -DMI_SECURE=ON in CMake. It provides several mitigations against memory-based exploits:
The benchmark evaluates performance using four distinct combinations of engine and input strategies to distinguish between engine instantiation overhead and data parsing overhead:
The instruction dispatcher (dispatch.rs) uses the InstructionOutcome enum to control flow:
Continue: Normal execution; the instruction pointer (pc) is incremented.Return(Value): Unwinds the current rule or function frame and propagates the Value upward.Break: Used by specific constructs (like RuleReturn or DestructuringSuccess) to exit to the owning frame without returning a specific value.Suspend { reason }: Used exclusively in Suspendable mode to pause execution.The Suspendable mode allows the VM to pause execution and yield control back to the host.
Workflow:
Suspendable mode. The VM uses run_stackless_from to manage an execution_stack of ExecutionFrame objects.HostAwait, a breakpoint, or a step. The SuspendReason is recorded, and the last result snapshot is stored.resume(resume_value) to provide the value needed to continue execution.execution_stack is empty, the VM transitions to ExecutionState::Completed { result }.Based on engine evaluation benchmarks, developers should be aware of the following performance characteristics:
mimalloc as the default allocator to improve multi-threaded scaling and reduce contention, throughput generally degrades as thread counts increase due to inherent contention.Regorus uses a cooperative time-limit check approach rather than a background watchdog thread or a cancellation token model.
Instead of spawning background threads (which would impact no_std compatibility and predictability), Regorus performs periodic checks during the evaluation process. This 'cooperative' approach amortizes the cost of clock reads and avoids the overhead of thread synchronization or async runtime scheduling.
While cancellation tokens are a common pattern, Regorus prioritizes time-based budgets for the following reasons: