Optimize Concurrent OCR Generation and Autocompletion
Problem
OCR LLM Pipeline is synchronus and blocking to the main autocompletion engine. as a result, autocompletion is stalled until OCR completes. This leaves window of 5 seconds of no auto completions.
What we want
Investigate whether implementing llama_batch which allows decoding of multiple requests sycnhrously will improve latency, without degrading preformance. This approach is what llama_server does, but we don't want to bundle llama_server into this product since it has a lot of features that we don't care about.
Therefore we need to implement llama_batch
Path B: Implement llama_batch in Swift (The Hard Way)
If you are writing your own C-bindings and absolutely must run it natively in-process (without a local HTTP server), you have to rewrite your inference loop.
You can no longer use the simple single-sequence generation. You have to use the newer llama_batch C-API. You will need to manually construct batches, keep track of sequence IDs (your "slots"), evaluate the batch, and then pull the specific tokens out for each sequence. It is highly complex, but it is exactly what llama-server is doing under the hood.
Related: #453 (optional per-model performance tracking) would provide the latency/throughput metrics to measure the impact of OCR + autocomplete concurrency changes.
Resolved in 0.4.2-beta. We dropped the LLM summarization step entirely, so screen context doesn't block autocomplete anymore.