From bb5bb62ed9430bbb06f89c8aa038c1cee5969c3c Mon Sep 17 00:00:00 2001 From: Jason Morley Date: Thu, 22 Jan 2026 17:09:35 -1000 Subject: [PATCH] fix: Support parallel renders This change uses `OperationQueue` (with `maxConcurrentOperationCount` of 8) to re-parallelize renders in a non-asynchronous context. --- Sources/InContextCore/Utilities/ThreadExecutor.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Sources/InContextCore/Utilities/ThreadExecutor.swift b/Sources/InContextCore/Utilities/ThreadExecutor.swift index 81b0c5a..77b2a70 100644 --- a/Sources/InContextCore/Utilities/ThreadExecutor.swift +++ b/Sources/InContextCore/Utilities/ThreadExecutor.swift @@ -25,14 +25,18 @@ import Foundation class ThreadExecutor { private let workQueue = DispatchQueue(label: "RenderExecutor.workQueue") + private let operationQueue = OperationQueue() + + init() { + operationQueue.maxConcurrentOperationCount = 8 + } // Guarantee that a throwing synchronous block is executed in a classical thread context and not an async one, // wrapping it as a throwing async call in the process. This works by using `withCheckedThrowingContinuation` - // to cross the boundary, and then dispatching async onto a single internal serial queue, serializing all dispatched - // blocks. + // to cross the boundary, and then enqueueing the work on a concurrent operation queue. func perform(_ block: @escaping () throws -> T) async throws -> T { return try await withCheckedThrowingContinuation { continuation in - workQueue.async { + operationQueue.addOperation { do { let result = try block() continuation.resume(returning: result)