Supported Background Job Queues in Palmier Pro: Complete GCD Guide
Palmier Pro relies exclusively on Apple's Grand Central Dispatch (GCD) with only two supported queue types: the system-provided DispatchQueue.main for all UI operations and custom serial DispatchQueue instances labeled with the reverse-domain prefix io.palmier.<task-name> for heavy background processing.
Palmier Pro (palmier-io/palmier-pro) moves virtually all long-running work off the UI thread using a strict GCD-based architecture. The codebase defines a minimal, predictable queue system that separates main-thread rendering from serial background tasks, ensuring responsive SwiftUI and AppKit interfaces while handling intensive video frame processing and image encoding.
The Two Supported Queue Types in Palmier Pro
The Palmier Pro codebase implements exactly two kinds of dispatch queues, eliminating concurrency complexity and preventing race conditions.
DispatchQueue.main for UI Updates
All interface updates run on the system-provided main queue. According to the Palmier Pro source code, any code touching SwiftUI or AppKit state must execute within DispatchQueue.main.async blocks. This pattern appears throughout the UI layer in files like Sources/PalmierPro/Project/VideoProject.swift and Sources/PalmierPro/App/AppState.swift, where background tasks dispatch results back to the main thread before updating observable properties.
Custom Serial Queues for Heavy Background Work
CPU-intensive operations use dedicated serial queues created with DispatchQueue(label:) using reverse-domain naming. These queues process tasks sequentially on background threads, isolating heavy work such as video normalization and model downloading from the render loop. The Sources/PalmierPro/Preview/AlphaVideoNormalizer.swift file defines the specific queue io.palmier.alpha-normalize for pixel-format conversion operations.
How Palmier Pro Enqueues Background Work
The implementation follows a consistent pattern across the codebase. Background work uses custom serial queues with Swift concurrency, while UI updates explicitly target the main queue.
In AlphaVideoNormalizer.swift, the heavy pixel-format conversion runs on a dedicated serial queue:
// From Sources/PalmierPro/Preview/AlphaVideoNormalizer.swift
private let queue = DispatchQueue(label: "io.palmier.alpha-normalize")
func normalize(_ source: URL) async throws -> URL {
// Heavy-weight processing runs on the custom serial queue
return try await queue.async {
// ... do the pixel-format conversion here ...
}
}
When the background operation completes, UI state updates dispatch to the main queue. In VideoProject.swift, the pattern looks like this:
// From Sources/PalmierPro/Project/VideoProject.swift
DispatchQueue.main.async {
self.isSaving = false // UI state must be updated on the main queue
}
Similarly, Sources/PalmierPro/App/AppState.swift and Sources/PalmierPro/Editor/ViewModel/EditorViewModel.swift use DispatchQueue.main.async to ensure all observable property changes occur on the main thread.
Extending the Queue Architecture
Adding new background job types requires following the established naming convention and pattern. Create a private serial queue with the io.palmier.<task-name> label prefix, then wrap heavy operations in queue.async blocks:
private let myQueue = DispatchQueue(label: "io.palmier.my-task")
func processData() async throws -> Result {
return try await myQueue.async {
// background work
}
}
Because Palmier Pro centralizes all UI work on DispatchQueue.main and isolates heavy work on custom serial queues, you can reliably add more queues without risking UI jank or race conditions.
Summary
- Only two queue types are supported:
DispatchQueue.mainfor UI and custom serialDispatchQueueinstances for background work. - Custom queues use reverse-domain labels with the prefix
io.palmier.<task-name>, as seen inio.palmier.alpha-normalize. - Main queue usage is mandatory for all SwiftUI/AppKit state changes, implemented via
DispatchQueue.main.asyncthroughoutVideoProject.swiftandAppState.swift. - Serial queues prevent concurrency issues by processing video frames and model downloads sequentially on dedicated background threads.
Frequently Asked Questions
Does Palmier Pro support concurrent background queues?
No. The current Palmier Pro codebase implements only serial custom queues using DispatchQueue(label:). This design choice prevents race conditions during video processing and ensures deterministic execution order for heavy tasks like image encoding in AlphaVideoNormalizer.swift.
What naming convention should I use for custom queues?
Use reverse-domain notation prefixed with io.palmier.. For example, io.palmier.alpha-normalize is the specific label used in Sources/PalmierPro/Preview/AlphaVideoNormalizer.swift. This convention ensures queue identifiers remain unique and traceable to their functional domain.
How does Palmier Pro prevent UI jank during background processing?
The architecture strictly isolates heavy work on custom serial queues while confining all UI updates to DispatchQueue.main. By never performing pixel-format conversion or model downloading on the main thread, the app maintains responsive frame rates in SwiftUI views managed by EditorViewModel.swift and VideoProject.swift.
Where are the queue definitions located in the Palmier Pro codebase?
Custom queue definitions reside in task-specific service files like Sources/PalmierPro/Preview/AlphaVideoNormalizer.swift, while main queue dispatches appear throughout the UI layer in Sources/PalmierPro/Project/VideoProject.swift, Sources/PalmierPro/App/AppState.swift, and Sources/PalmierPro/Editor/ViewModel/EditorViewModel.swift.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →