Improvements to mask distort efficiency via incremental caching and reduced malloc/free cycles.#20729
Improvements to mask distort efficiency via incremental caching and reduced malloc/free cycles.#20729masterpiga wants to merge 1 commit intodarktable-org:masterfrom
Conversation
TurboGit
left a comment
There was a problem hiding this comment.
After activating lens correction module, try enabling another module (liquify in my case) and you'll see Darktable freeze.
Via incremental caching and reduced malloc/free cycles.
aa2e88d to
c839984
Compare
|
Thanks, @TurboGit, PTAL. The fix for the deadlock introduced another deadlock. Can you break it again? 😅 |
|
@masterpiga : How to best test this? In other word the best way to have a slow process with current master and check speed improvement the new version? |
For correctness: -d pipe will likely be sufficient, maybe masks too. The verbose switch might also be helping. What happens when using space bar and coming back later? Cache cleared when doing stuff via lighttable like orientation? Haven't looked into code or any testing yet. We want to ask @s7habo, he knows how to stress-test masking stuff. |
|
@masterpiga : I'm sad, I cannot break it :( So it works, it feels fast but I'll let @s7habo test too. My test has included at least one picture with lens correction, perspective correction, liquify and retouch, all together. |
Pascal, i'll do my very best being a bad-boy tomorrow :-) |
Awwww
I was hoping that you had some kind of monster image specifically for mask testing. I basically did as you did: started editing images, adding a bunch of distortions and masks on top. I couldn't find any obvious issue but I am sure that there are infinite code paths that I did not hit.
Yes, please :) |
|
Perhaps this will be of help to you? https://darktable.info/en/system-ui-2/performance-analysis/dt-real-time-monitor/ If you need any further features, just let me know. |
I did a first round of testing and indeed i couldn't break it (yet). But - unfortunately i couldn't yet spot any Give me a few more days :-) |
|
When this appears in the master branch, I'd be happy to test it :) |
In the discussion of #20712 it was brought to my attention that a clear area for efficiency improvements in the pixelpipe would be mask distorts. @jenshannoschwalm @TurboGit
Co-authored with Claude.
Key efficiency gains:
List of changes
pixelpipe_hb.h
dt_dev_distorted_mask_cache_tstruct — holds cached distorted mask data, ROI, and hash at geometric module boundariesdetail_mask_cacheandraster_mask_cachefields todt_dev_pixelpipe_iop_t— per-piece cache slotsmask_distort_buf[2]andmask_distort_buf_size[2]todt_dev_pixelpipe_t— reusable ping-pong bufferspixelpipe_hb.c
_ensure_distort_buf()lazily grows buffers,_free_distort_bufs()cleans up_detail_mask_cache_hash()and_raster_mask_cache_hash()compute invalidation-aware hashes combining source identity + cumulative pipe state_update_detail_mask_cache(),_update_raster_mask_cache(),_clear_piece_mask_caches()dt_dev_distort_detail_mask(): Searches backward from target for nearest valid cached intermediate result, walks forward from there using ping-pong buffers, stores results at each geometric boundarydt_dev_get_raster_mask(): Same backward-search + ping-pong + caching pattern for raster masksinit_cached(), freed incleanup(). Per-piece caches cleaned incleanup_nodes()dt_dev_clear_scharr_mask()now clears all per-piece mask caches. Hash-based invalidation handles param changes naturallydevelop.c
Fixed ABBA deadlock.
dt_dev_undo_end_record()(which raisesDT_SIGNAL_DEVELOP_HISTORY_CHANGE) is moved to after thehistory_mutexunlock in_dev_add_history_item. Signal handlers triggered by that signal can calldt_control_get_mouse_over_id, which acquiresglobal_mutex— doing so without holdinghistory_mutexeliminates the inversion.dt_dev_zoom_moveis reverted to its original lock order (global_mutex → history_mutex), consistent withdt_dev_get_viewport_params→dt_dev_distort_transform_plus.