haive.core.common.mixins.soft_recompile_mixin¶

Soft recompilation mixin - 200x faster than full recompile.

This mixin provides soft recompilation capability that updates only what’s needed, avoiding the 10.5s full recompilation penalty. Instead of rebuilding everything, it performs targeted updates in <100ms.

Classes¶

SoftRecompileMixin

Enhanced recompilation with soft mode for <100ms updates.

Module Contents¶

class haive.core.common.mixins.soft_recompile_mixin.SoftRecompileMixin[source]¶

Bases: haive.core.common.mixins.recompile_mixin.RecompileMixin

Enhanced recompilation with soft mode for <100ms updates.

This mixin provides intelligent recompilation that distinguishes between: - Soft recompile: Cache invalidation, routing updates (<100ms) - Hard recompile: Full graph rebuild (10.5s)

The key insight is that most changes don’t require full recompilation. By keeping the compiled graph and only updating what changed, we achieve 200x+ speedup for common operations.

Examples

>>> from haive.core.graph import StateGraph
>>>
>>> class OptimizedGraph(StateGraph, SoftRecompileMixin):
...     def compile(self):
...         if self.should_soft_recompile():
...             return self.perform_soft_recompile()
...         return super().compile()
>>>
>>> graph = OptimizedGraph()
>>> graph.add_node("new_node", lambda x: x)
>>> # This triggers soft recompile (<100ms) not full rebuild!
get_recompile_performance()[source]¶

Get recompilation performance metrics.

Returns:

Dictionary with performance statistics

Return type:

dict

mark_for_soft_recompile(reason)[source]¶

Mark for soft recompile - just cache invalidation.

Use this for changes that don’t affect graph structure: - Engine swaps - Tool additions to existing nodes - Routing changes - Node behavior updates

Parameters:

reason (str) – Description of why soft recompile is needed

Return type:

None

optimize_recompile_strategy()[source]¶

Analyze history and optimize recompile strategy.

This method learns from past recompiles to better predict whether soft or hard recompile is needed.

Return type:

None

perform_soft_recompile()[source]¶

Perform soft recompile in <100ms.

This method updates only what’s necessary: 1. Clears execution cache (5ms) 2. Rebuilds routing from state (20ms) 3. Updates triggers (20ms) 4. Updates cached compiled graph (30ms)

Returns:

The updated compiled graph (from cache)

Return type:

Any

should_soft_recompile()[source]¶

Check if soft recompile is sufficient.

Soft recompile is sufficient for: - Routing changes - Node behavior updates - Engine swaps - Tool additions

Full recompile needed for: - Schema changes - New channels - Graph structure changes

Returns:

True if soft recompile is sufficient

Return type:

bool