Skip to content

Governance-as-operator performance optimizations: batch transitions and rule caching #46

@Soushi888

Description

@Soushi888

Summary

Implement performance optimizations for the governance-as-operator pattern: batch state transition processing and governance rule caching to minimize cross-zome call overhead.

Context

Cross-zome calls in Holochain add latency. When multiple state transitions need evaluation (e.g., bulk transfers, process chains), the overhead can become significant. This issue addresses optimization after the core pattern is functional.

Technical Implementation

1. Batch State Transitions

#[hdk_extern]
pub fn batch_state_transitions(
    requests: Vec<GovernanceTransitionRequest>,
) -> ExternResult<Vec<GovernanceTransitionResult>> {
    // Group requests by resource specification
    // Load governance rules once per group
    // Process all requests in each group
}

Benefits:

  • Single rule loading for multiple transitions on same resource type
  • Reduced cross-zome call count
  • Atomic processing of related transitions

2. Governance Rule Caching

pub struct LazyRuleEvaluator {
    cached_rules: LruCache<ActionHash, Vec<GovernanceRule>>,
}

Cache governance rules per resource specification to avoid repeated DHT lookups within the same evaluation context.

3. Permission Caching

Cache agent permission lookups within a batch or session to avoid repeated role queries.

4. Process Chain Optimization

For multi-step processes (e.g., Use → Modify → Transfer), optimize the chain of governance evaluations to share context between steps.

Acceptance Criteria

  • batch_state_transitions function processes multiple requests efficiently
  • Rule caching reduces DHT lookups for repeated specification queries
  • Permission caching works within batch processing
  • Process chain optimization shares context between related transitions
  • Performance benchmarks show measurable improvement over individual calls
  • No correctness regression — cached results match uncached results

Dependencies

Priority Note

This is P3-medium — implement after the core governance-as-operator pattern is functional and tested. Optimize based on measured performance, not speculation.

Definition of Done

  • Batch processing implemented
  • Caching implemented with appropriate invalidation
  • Performance benchmarks documented
  • All existing tests still pass
  • Code review completed

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3-mediumMedium priority - should be completed when possiblephase-2-governancePhase 2 - Enhanced governance & process integration (current)zome-governanceGovernance zome - validation, economic events, commitments

    Type

    No type

    Projects

    Status

    No status

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions