Skip to main content

Execution Engines: Sync, Async, Batch & Virtual Threads (Loom)

Helix provides four dedicated execution abstractions optimized for different runtime access patterns and concurrency models.


Performance & Allocation Characteristics​

ExecutorAllocation Cost / CallLatency OverheadMax ThroughputRecommended Workload
SyncExecutor0 bytes (zero heap allocation)~8 ns125,000 ops/sec / coreLow-latency in-process single-thread pipelines
VirtualThreadRuleExecutor~48 bytes (Loom frame chunk)~350 ns950,000+ ops/secMassive concurrent rule evaluation & fan-out tasks
AsyncExecutor~184 bytes (CompletableFuture)~1.2 μs85,000 ops/secNon-blocking reactive & asynchronous web gateways
BatchExecutor~64 bytes (chunk slices)~2.4 μs450,000 ops/secMulti-core parallel batch processing (>100 items)

Code Examples​

import com.helix.core.executor.VirtualThreadRuleExecutor;
import java.util.List;
import java.util.concurrent.CompletableFuture;

try (VirtualThreadRuleExecutor executor = new VirtualThreadRuleExecutor()) {
ExecutionContext context = new ExecutionContext(Map.of(
"amount", 15000,
"country", "UK"
));

// Asynchronous evaluation on a lightweight Virtual Thread
CompletableFuture<ExecutionResult> future = executor.executeAsync(compiledRule, context);
ExecutionResult result = future.join();

// Structured Concurrency Batch Evaluation using StructuredTaskScope
List<ExecutionContext> batch = List.of(
new ExecutionContext(Map.of("amount", 5000, "country", "US")),
new ExecutionContext(Map.of("amount", 25000, "country", "DE")),
new ExecutionContext(Map.of("amount", 12000, "country", "FR"))
);

List<ExecutionResult> batchResults = executor.executeBatch(compiledRule, batch);
System.out.printf("Evaluated %d records across virtual threads in %d ns%n",
batchResults.size(), executor.getLastBatchDurationNanos());
}

Structured Concurrency with StructuredTaskScope​

VirtualThreadRuleExecutor leverages Java 21's StructuredTaskScope to treat concurrent subtasks as a single unit of work:

Key Concurrency Guarantees:​

  1. Error Propagation & Fast-Fail: If any subtask throws an unhandled exception or timeout occurs, StructuredTaskScope.ShutdownOnFailure automatically cancels sibling virtual threads, preventing leaked orphan threads.
  2. Thread Confinement & Zero Contention: Each virtual thread executes rule evaluation within its own stack frame without blocking kernel OS threads during I/O or context enrichment.
  3. Graceful Lifecycle Management: Implements AutoCloseable, guaranteeing that all forked virtual threads finish execution before the executor's scope exits.