Skip to content

Allow concurrent parsing of the same grammar during indexing #127

Description

@amondnet

Summary

PR #126 (#115) parallelizes per-file indexing, but chunk() in crates/csp/src/chunking/core.rs holds a per-grammar mutex around Parser::new, set_language, and parse. Files of the same language therefore still parse one at a time. On a repository dominated by one language, the speedup comes only from reading, hashing, merging, and tokenizing.

The lock exists because the language pack serializes all parsing behind a global PARSE_LOCK ("some third-party grammar scanner code keeps process-global mutable state"), and upstream semble sidesteps the issue with worker processes. The per-grammar lock is already more concurrent than the language pack's own default.

Proposal

  • Identify which grammars' external scanners actually keep process-global state, and keep an allowlist of grammars that are safe to parse concurrently (or a denylist of unsafe ones).
  • Alternatively, keep a per-thread parser pool for grammars known to be safe.
  • Add a single-language benchmark case (for example 300 .ts files) next to the existing multi-language index_build bench, so the effect is measurable.

Context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions