Files
ruflo/v3/@claude-flow
Reuven 33cb210e67 perf: drop redundant dynamic imports of already-loaded stdlib modules
memory-tools.ts and hooks-tools.ts had 5 + 1 sites that did
\`await import('fs')\` / \`await import('os')\` inside handler bodies even
though the same exports were already imported statically at the top of
the file. Each await-import on a cached module adds:

  - one async microtask roundtrip (~2µs per call on this host)
  - an async boundary that propagates up the call chain
  - a TypeScript erasure that hides which module the binding came from

Microbench (50k iters, M2 Mac):
  dynamic await import('fs')+import('os'): 107.47 ms (2.15 µs/iter)
  static reference:                          0.25 ms (0.005 µs/iter)
  speedup: 423x

Sites changed:
  memory-tools.ts:
    - memory_import_claude: 1× await import('os') + 2× await import('fs')
    - memory_bridge_status: 1× await import('os') + 1× await import('fs')
    Pulled readdirSync + homedir into the static import block at top.
    Also removed dead line `const projects = readFileSync;` (was a leftover
    no-op assignment with a misleading comment).
  hooks-tools.ts:
    - file-scanner handler: 1× await import('node:fs') for readdirSync+
      statSync that were already imported at the top.

Verified:
  tsc --noEmit clean
  __tests__/mcp-tools-deep + memory-ruvector-deep: 252/252 passing.
2026-05-03 20:47:35 -04:00
..