Skip to main content

Module parallel_parse

Module parallel_parse 

Source
Expand description

Parallel corpus parse on top of the L2 LRU cache. ROADMAP L3 substrate; fans get_or_parse across cores with rayon while preserving input order. ROADMAP L3 - parallel parse across file corpus.

Fan out ParsedSourceLru::get_or_parse across all available cores via rayon::par_iter. Corpus-wide deduplication still happens because each unique (content, extra) pair is submitted to the cache exactly once; duplicate entries in the input slice map back to the same Arc<T>.

§Design notes

  • Ordering is preserved: the final sequential pass maps each input index back to its parsed Arc<T>.
  • The cache is Send + Sync (backed by Mutex<…>), so sharing a &ParsedSourceLru<T> across rayon workers is safe.
  • parse must be Fn(&[u8]) -> T + Sync; the closure is invoked from multiple threads but never mutates shared state.
  • To avoid paying the parse cost multiple times for the same key under concurrent cache misses (the L2 cache does not dedup in-flight parses), the implementation first identifies unique keys, then calls get_or_parse once per unique key.

Functions§

parse_corpus_parallel
Parse every (content, extra_key) pair in sources in parallel, memoising through cache. Returns Arc<T> values in input order.