perf: avoid spaCy statistical pipeline for word tokenization#4408
perf: avoid spaCy statistical pipeline for word tokenization#4408KRRT7 wants to merge 7 commits into
Conversation
There was a problem hiding this comment.
0 issues found across 1 file (changes from recent commits).
Shadow auto-approve: would auto-approve. This change replaces the full statistical pipeline with the tokenizer-only path in word_tokenize(), preserving behavior while improving performance. The diff shows the bounded refactoring with output-parity tests and a no-invocation regression test, making it clearly beneficial.
Re-trigger cubic
There was a problem hiding this comment.
Review completed against the latest diff
Shadow auto-approve: would not auto-approve because issues were found.
Re-trigger cubic
There was a problem hiding this comment.
0 issues found across 2 files (changes from recent commits).
Shadow auto-approve: would not auto-approve. Auto-approval blocked by 1 unresolved issue from previous reviews.
Re-trigger cubic
There was a problem hiding this comment.
0 issues found across 2 files (changes from recent commits).
Shadow auto-approve: would auto-approve. This PR replaces the full spaCy pipeline with the tokenizer-only path in word_tokenize(), which is clearly bounded and beneficial. The diff shows all other callers retain the pipeline, truncation logic is preserved, and new regression tests confirm output parity.
Re-trigger cubic
There was a problem hiding this comment.
0 issues found across 1 file (changes from recent commits).
Shadow auto-approve: would auto-approve. Focused performance optimization replacing full spaCy pipeline with tokenizer-only path, preserving output behavior. Verified by exact parity tests and benchmarks. No new capabilities, no changes to public contracts, auth, data handling, or operational tradeoffs.
Re-trigger cubic
|
@cragwolfe looks like the transient issue was hiding a bug. |
Summary
Use spaCy's tokenizer-only
make_doc()path inword_tokenize()instead of running the complete statistical pipeline.Word tokenization only consumes
token.text, so running the tagger and dependency parser adds substantial work without affecting the result.This PR also:
Performance
Benchmarked on an 8-vCPU AMD EPYC host with 15 GiB RAM and Python 3.12.
The benchmark covers large TXT, HTML, DOCX, and PPTX documents through their format-specific partitioners. The spaCy model is warmed before measurement, while token, sentence, and POS result caches are cleared before every measured iteration. This measures the algorithmic improvement rather than repeated-document cache hits.
Each result is the median of three iterations.
upstream/mainOutput parity was exact for every document, covering:
The benchmark verifies every element's concrete type and text using a stable SHA-256 fingerprint.
Benchmark reproduction
The benchmark defaults to three iterations over the representative four-document matrix. Custom workloads can be supplied by repeating
--input:Testing
word_tokenize()never invokes the statistical pipeline.