Skip to content

Parallelize extraction orchestrator to reduce pipeline latency#1823

Open
ankitgmishra wants to merge 1 commit into
Graphify-Labs:v8from
ankitgmishra:perf/parallel-extraction-orchestration
Open

Parallelize extraction orchestrator to reduce pipeline latency#1823
ankitgmishra wants to merge 1 commit into
Graphify-Labs:v8from
ankitgmishra:perf/parallel-extraction-orchestration

Conversation

@ankitgmishra

Copy link
Copy Markdown

The Problem:
Currently, the graphify extract orchestrator in cli.py runs its extraction stages sequentially. On a large repository, the CLI waits for AST extraction to completely finish before it begins the Semantic extraction, and waits for Semantic to finish before starting PostgreSQL/Cargo introspections. This creates an unnecessary linear bottleneck since these stages are entirely independent of one another.

The Solution:
This PR refactors the core orchestrator in cli.py to run the extraction stages concurrently, effectively masking the I/O and processing time of the faster stages behind the longest-running stage (typically Semantic LLM extraction).

Key Changes:

  • Decoupled monolithic extraction blocks in cli.py into standalone functions (run_ast, run_semantic, run_pg, run_cargo).
  • Implemented a concurrent.futures.ThreadPoolExecutor to dispatch these functions simultaneously.
  • Ensured thread-safe result accumulation by merging the results sequentially after the pool drains, preserving the strict merge-order needed for collision resolution.
  • Maintained accurate scope resolution for incremental cache counters (sem_cache_hits, sem_cache_misses) so CLI summary outputs remain correct.

Testing & Edge Cases Handled:
Added a comprehensive test suite (tests/test_parallel_orchestration.py) to validate:

  1. Concurrency Validation: Mathematically verified via time.sleep mocks that tasks run in parallel.
  2. Error Propagation: Verified that a hard failure in the LLM thread correctly triggers a SystemExit(1) and aborts the CLI gracefully rather than failing silently.
  3. Data Integrity: Verified that nodes/edges from all threads are successfully merged into the final graph.json without data loss.
  4. Code-Only Corpora: Verified that the ThreadPool safely handles empty document sets without crashing.

Performance Impact:

  • Sequential Baseline: AST Time + Semantic Time = Total Time
  • Parallelized (This PR): max(AST Time, Semantic Time) = Total Time
    (On large codebases, this effectively reduces the AST extraction time to 0.0s of overhead as it runs completely invisibly in the background during the LLM network calls).

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.

1 participant