Skip to content

Refactor batch write to use concurrent ThreadPoolExecutor - #9

Merged
codeyogi911 merged 2 commits into
mainfrom
claude/test-reflect-performance-BDpt3
Apr 9, 2026
Merged

Refactor batch write to use concurrent ThreadPoolExecutor#9
codeyogi911 merged 2 commits into
mainfrom
claude/test-reflect-performance-BDpt3

Conversation

@codeyogi911

Copy link
Copy Markdown
Owner

Summary

Refactored the _batch_write function in lib/ingest.py to use concurrent execution via ThreadPoolExecutor instead of sequential batch processing. This enables parallel page writes, improving throughput when processing multiple wiki pages.

Key Changes

  • Concurrent execution: Replaced sequential batch loop with ThreadPoolExecutor(max_workers=5) to write up to 5 pages in parallel
  • Two-phase processing:
    • Phase 1 (sequential): Prepare items by reading existing page content from disk
    • Phase 2 (concurrent): Call _write_page_content for each prepared item concurrently using as_completed()
  • Refactored helper functions: Extracted _write_one() to handle item preparation and _call_one() to handle concurrent page writes
  • Updated subagent CLI flags in both lib/ingest.py and lib/context.py:
    • Changed --append-system-prompt to --system-prompt
    • Added --setting-sources "" and --no-session-persistence flags
  • Version bump: Updated SKILL.md version from 0.5.2 to 0.6.0

Implementation Details

The refactoring maintains the same logic for handling update/resolve/create actions and fallback behavior when pages don't exist, but executes the expensive _write_page_content calls (which invoke subagents) concurrently rather than sequentially. The preparation phase (reading existing content) remains sequential since it's I/O bound and relatively fast.

The concurrent approach preserves result ordering and error handling by collecting futures and processing results as they complete via as_completed().

https://claude.ai/code/session_017Apv1ffJUpBe6xEmEd45Md

claude added 2 commits April 9, 2026 13:45
Subagent calls (claude -p) were broken because project/user hooks
(Entire CLI, stop-hook-git-check) injected messages about uncommitted
changes, causing the model to respond to those instead of the actual
triage/write task. Added --setting-sources "" and --no-session-persistence
to isolate subagent calls. Switched from --append-system-prompt to
--system-prompt to avoid loading the default Claude Code system prompt.

Also parallelized wiki write calls using ThreadPoolExecutor (up to 5
concurrent workers) instead of sequential batching. With 7 pages,
this reduces write stage from ~56s to ~15s.

Measured results: ingest goes from broken/66s to working/77s.
Per-call API time drops from ~13s to ~3-7s.

https://claude.ai/code/session_017Apv1ffJUpBe6xEmEd45Md

Entire-Checkpoint: f5406daa8b23
Generated by running `reflect init` + `reflect ingest` after the
subagent isolation and parallel writes fix. 7 wiki pages created
covering decisions and gotchas from project history.

https://claude.ai/code/session_017Apv1ffJUpBe6xEmEd45Md

Entire-Checkpoint: e278aa00b4e6
@codeyogi911
codeyogi911 merged commit 90a5cde into main Apr 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants