Add parallelization to our converters if there are noticeable performance gains
Summary
Several file converters in haystack/components/converters/ process a list of sources sequentially. For workloads with many files, adding parallelism via ThreadPoolExecutor could significantly speed up processing.
This came up in the call with @bogdankostic and @ju-gu where we noticed that Sol is using thread-based parallelism to speed up PDF processing that can occur in a query pipeline when retrieving PDF files from a web search + content fetcher request.
Motivation
Converters currently iterate over sources one at a time in their run method. Depending on the nature of the work per file, parallel execution could provide meaningful speedups:
Network I/O-bound (highest gain):
TikaDocumentConverter- requires a synchronous call to an external service. Using a thread pool executor would greatly speed this up.File I/O + CPU parsing (good gain):
DOCXToDocument,PPTXToDocument,MSGToDocument,HTMLToDocument,XLSXToDocument,PDFToImageContent,ImageFileToImageContent- a mix of file reads (I/O, releases the GIL) and moderate CPU parsing. Threads would help primarily during the I/O phase.Typically CPU-bound PDF parsing (moderate gain):
PyPDFToDocument,PDFMinerToDocument- parsing is pure Python and the GIL limits thread-based parallelism.ThreadPoolExecutorstill helps by overlapping file reads across files, but if the pdf parsing is the dominant cost then this doesn't parallelize well with threads.Low priority:
TextFileToDocument,MarkdownToDocument,CSVToDocument,JSONConverter,FileToFileContent- per-item work is light enough that adding the executor is probably not worth the overhead.
Investigation needed
- Benchmark sequential vs.
ThreadPoolExecutorfor each converter category above - Determine appropriate default
max_workersvalues
Hello there! This issue will be handled internally and isn't open for external contributions. If you'd like to contribute, please take a look at issues labeled contributions welcome or good first issue. We'd really appreciate it!
Source: deepset-ai/haystack