Direct Answers
Does enabling asynchronous document loading in Inkscape 1.2 completely remove the lock contention between GUI and CLI? No. Async loading (sp_document_load_async) parallelizes the initial SVG parse, but the final DOM integration and all subsequent mutations (filters, gradients, display-list updates) still require the single Glib::Mutex that protects SPDocument. While the GUI rendering loop holds a write lock during zoom/pan/selection, CLI export verbs block on the same mutex, so contention persists during active GUI manipulation.
Is there a way to configure the singleton to allow non‑blocking read‑only access for export while the GUI holds a write lock? No runtime configuration exists. The document mutex is a plain Glib::Mutex without read/write separation, and SPDocument does not expose a read‑only accessor that bypasses the lock.
Can the export pipeline be decoupled from the GUI singleton without breaking existing extensions or scripts? Not without a major refactor. Decoupling would require making SPDocument thread‑safe (e.g., copy‑on‑write XML tree) and rewriting all verbs/extensions that assume single‑threaded DOM access — a breaking change for the inkex Python API and third‑party scripts.
Why the Contention Exists
- Singleton document model: Each open SVG is represented by one
SPDocument instance shared between the GUI canvas (SPDesktop) and CLI verbs.
- Single mutex: A
Glib::Mutex guards all access to the XML tree and display lists. The GUI's idle render loop (SPDesktop::update_idle) acquires it for write during zoom, pan, and selection. CLI export (--export-type=png) calls sp_document_read()/write() and blocks on the same mutex.
- Observed latency: On a 5 MB SVG in 1.1.x, export time roughly doubles when the GUI is actively panning/zooming. In 1.2+, async loading reduces the initial parse overlap but does not eliminate the serialization point at DOM integration.
What Inkscape 1.2 Async Loading Actually Changes
Async loading moves the SVG parsing phase off the GUI thread. However, once the parse tree is ready, it must be merged into the live SPDocument under the mutex. Any subsequent DOM mutations (filter evaluation, gradient updates, bounding-box recalculation) also serialize on that mutex. Therefore, if the GUI is mid‑interaction (holding the lock for rendering), the CLI export still waits.
Practical Workarounds (No Code Changes)
- Export from a file copy:
cp input.svg input-copy.svg && inkscape --export-type=png input-copy.svg -o output.png while the GUI edits the original. This gives the CLI its own SPDocument instance and mutex.
- Reduce GUI lock hold time: Script the GUI to iconify/minimize the window (
wmctrl -r "Inkscape" -b add,iconic or platform equivalent) before triggering export. The render loop pauses, releasing the mutex.
- Avoid concurrent heavy operations: Schedule batch exports when the GUI is idle (no pan/zoom/selection).
Verification Steps (If You Need Current Proof)
# 1. Build current main (1.4-dev) and compare latency
# git clone https://gitlab.com/inkscape/inkscape.git && cd inkscape
# mkdir build && cd build && cmake .. && make -j$(nproc)
# time ./inkscape --export-type=png test.svg -o /dev/null
# (Run while GUI pans the same file in a separate 1.2.2 binary)
# 2. Inspect mutex usage in source
# grep -n "mutex_" src/document.cpp
# grep -n "sp_document_load_async" src/document.cpp
# 3. Check if SPDesktop::update_idle still locks during canvas ops
# grep -A5 -B5 "update_idle" src/desktop.cpp
# 4. Search issue tracker for recent discussions
# https://gitlab.com/inkscape/inkscape/-/issues?search="export%20latency%20GUI"
# 5. Test copy-file workaround
# cp test.svg test-copy.svg && inkscape --export-type=png test-copy.svg -o out.png
Assumptions & Uncertainties
- Lock behavior is an implementation detail; future releases (1.3+, 1.4 dev) may introduce finer‑grained locking or a read‑write lock — verify against current source.
- Measured latency varies with SVG complexity (embedded rasters, filters, large node counts), not just file size.
- Extension API (
inkex, Python scripts) assumes synchronous DOM access; any decoupling breaks backward compatibility.
- No official CLI flag exists to request non‑blocking or read‑only document access.
One Diagnostic Detail That Could Refine Advice
What Inkscape version are you running, and does the SVG contain filters or embedded raster images? (Filter-heavy files increase mutex hold time during render, making the copy-file workaround more impactful.)