Skip to content

Batched compilation for multi-component builds (Madrona/Geant4 pattern) #74

@avrabe

Description

@avrabe

Context

Madrona Engine compiles ECS systems into GPU megakernels, achieving 11-33x speedups by batching independent simulations. CERN Geant4 shares read-only data (geometry, physics tables) across worker threads via TLS, avoiding redundant allocation.

Problem

When optimizing many WASM components (common with Component Model), each optimization is independent but shares the same ISLE rules, instruction tables, and verification context. Currently there is no shared-data optimization for multi-component builds.

Proposal

Batch independent component optimizations:

Shared read-only data (allocate once)

  • ISLE optimization rules and pattern tables
  • Z3 solver context (shared for independent queries)
  • Verification rule sets

Per-component thread-local data

  • IR state and working memory
  • Optimization pass temporary storage
  • Statistics and counters

Implementation sketch

let shared = Arc::new(SharedOptContext {
    isle_rules: load_isle_rules(),
    z3_context: z3::Context::new(),
});

components.par_iter().map(|component| {
    let local = ThreadLocalState::new();
    optimize_component(component, &shared, &mut local)
}).collect()

Benefits

  • Amortize rule loading across N components
  • Naturally parallel — each component is independent
  • Memory efficient — shared data is read-only, not duplicated

Connects to

References

Priority

Medium — high value for Component Model workloads.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions