Skip to content

[Track/Effect] CreateEffectForRequest clones Parameters up to 27× per request before finding the handler #64

@NikolaRHristov

Description

@NikolaRHristov

Problem

The Try! macro in CreateEffectForRequest::Fn calls Parameters.clone() unconditionally on every module invocation, even when that module does not handle the method. With 27 modules in the chain, a FileSystem.ReadFile call (the most frequent RPC in any session) clones Parameters 5 times before reaching its handler and discards all 5 clones. A $tree:register call clones it 14 times.

serde_json::Value clone is not free — it recursively copies the full JSON tree including heap-allocated strings and maps.

File: Source/Track/Effect/CreateEffectForRequest/mod.rs

Root Cause

macro_rules! Try {
    ($Module:ident) => {
        // Parameters.clone() called even when this module doesn't handle MethodName
        if let Some(Result) = $Module::CreateEffect::<R>(MethodName, Parameters.clone()) {
            return Result;
        }
    };
}

Fix

  1. Add a Matches(method: &str) -> bool function to each domain module (a simple match on &str returning bool — Rust compiles this to a jump table at zero cost).
  2. Refactor Try! to call Matches first, then pass owned Parameters only to the matched module's CreateEffect.
  3. Reorder the Try! chain to reflect actual call frequency: FileSystem → Configuration → TreeView → Commands → Terminal → rest.
macro_rules! Try {
    ($Module:ident) => {
        if $Module::Matches(MethodName) {
            return $Module::CreateEffect::<R>(MethodName, Parameters);
        }
    };
}

Additional Scope for Same PR

  • Audit FileReadAlias.rs — confirm it does not duplicate logic already in FileSystem.rs; fold aliases into FileSystem::Matches if so.
  • Add a comment to Utilities/Params.rs noting that str_at / bool_at should be replaced by a ParsedParams wrapper parsed once at the DispatchSideCarRequest boundary (log as a separate follow-up issue).

Metadata

Metadata

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions