Search is single threaded
Summary
Currently, searching a document is done single threaded.
Reproduction
This can be spotted in two ways when search is initiated:
- One can hear their computer fans ramp up.
- Resource monitor showcases a single core spiking in usage.
Source
The issue is in the following function, in which a find job is initiated over all pages, pps_document_get_n_pages (doc)
.
Solution
The most obvious solution is instead of running a single thread over every single page of a document, the following pseudo code will suffice.
// Array is preallocated to match the pages of the document (fixed)
// Each element is a list of matches (variable)
DECLARE ARRAY of LIST
DECLARE FUNCTION QUERY_PAGE(PAGE, QUERY).
Queries a given page using QUERY, saving the matches into the ARRAY.
// A thread pool
DECLARE THREAD_POOL
FOR each PAGE, LAUNCH NEW THREAD in THREAD_POOL.
Each thread should be instructed to call QUERY_PAGE with a page its assigned to.
// Await for all threads to complete
AWAIT THREAD_POOL is DONE
This solution is not the best, but its simple.
A better solution is reactively displaying the results as they come in, instead of all at once.
Edited by Clocks