Skip to content

Commit b7d5532

Browse files
perf(pii): batch spaCy NER passes in redact_batch (#8772)
Presidio's BatchAnalyzerEngine defaults nlp.pipe to batch_size=1, so each 2000-text request ran 2000 separate forward passes. Batching at 256 roughly halves analysis time on prod-shaped chunks with identical detections.
1 parent 886cfa2 commit b7d5532

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

‎apps/pii/server.py‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,11 @@ def _analyze_one(
267267
)
268268

269269

270+
# Presidio's BatchAnalyzerEngine defaults nlp.pipe to batch_size=1, so a 2000-text
271+
# request runs 2000 separate spaCy forward passes.
272+
NLP_BATCH_SIZE = 256
273+
274+
270275
def _analyze_many(
271276
texts: list[str],
272277
language: str,
@@ -292,6 +297,7 @@ def _analyze_many(
292297
batch_analyzer.analyze_iterator(
293298
texts=texts,
294299
language=language,
300+
batch_size=NLP_BATCH_SIZE,
295301
entities=entities or None,
296302
score_threshold=score_threshold,
297303
ad_hoc_recognizers=ad_hoc_recognizers or None,

0 commit comments

Comments
 (0)