Skip to content

vol2: createUnit() hot path — replace sourceToSlot Map iteration with compact array iteration #6728

@mdproctor

Description

@mdproctor

Context

ReteCompiledEngine.createUnit() currently iterates sourceToSlot.entrySet() to subscribe DataStore adapters. This is on the hot path (called per unit instance creation) and uses map iteration, boxing, and identity hash map overhead.

Required design

At compile() time, assign each DataSource accessor a compact integer slot index (0..N-1). Store results as parallel arrays:

  • Object[] accessors — one accessor per slot
  • ContextRouterAdapter[] adapters — one adapter per slot (populated lazily on first createUnit())

createUnit() then iterates:

for (int i = 0; i < slotCount; i++) {
    Object ds = ((Function1<CTX, DataSource<?>>) accessors[i]).apply(ctx);
    // ...subscribe adapter[i]...
}

Slot assignments must be dense (no gaps). Vol1 recycled arrays with compact slot assignment for the same reason. IdentityHashMap-based sourceToSlot stays for build-time use only.

Note

All vol2 evaluation is single-threaded (command-loop model) — no concurrent data structures needed.

Refs #6724

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    Status
    📋 Backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions