Bug 407062

Summary: Gaussian blur is much slower than it was in Krita 3.3.3
Product: [Applications] krita Reporter: Kate <pickledllamajuice>
Component: FiltersAssignee: Dmitry Kazakov <dimula73>
Status: RESOLVED FIXED    
Severity: normal CC: ahab.greybeard, halla, reptillia39
Priority: NOR Keywords: regression, release_blocker, triaged
Version: 4.1.7   
Target Milestone: ---   
Platform: Other   
OS: Microsoft Windows   
Latest Commit: Version Fixed In:
Sentry Crash Report:
Attachments: CPU and RAM usage with lock/freeze effect in action

Description Kate 2019-04-29 18:38:51 UTC
When attempting to open file, Krita becomes completely unresponsive. File size is small with limited layers. The problem appears to be the gaussian blur filter mask.

STEPS TO REPRODUCE
1. Download file 
2. Open with Krita

OBSERVED RESULT
Krita becomes unresponsive and must be forced closed. 
Removing the filter mask solves the issue.


SOFTWARE/OS VERSIONS
Windows: 10 64-bit

This has been tried on several computers of varying ability and power to no avail.
Comment 1 Ahab Greybeard 2019-04-29 20:28:15 UTC
The .kra file that makes krita unresponsive when opened can be downloaded here (at the moment):
https://www.dropbox.com/s/m2bafx3zs4rmf0r/Electric%20Dragon%20Base.kra?dl=0

This was first reported here: https://forum.kde.org/viewtopic.php?f=139&t=160413

I confirm it happens with a recent 4.2.0 pre-alpha appimage:
Krita

 Version: 4.2.0-pre-alpha (git ab98e9b)
 Languages: en_GB, en
 Hidpi: true

Qt

  Version (compiled): 5.12.2
  Version (loaded): 5.12.2

OS Information

  Build ABI: x86_64-little_endian-lp64
  Build CPU: x86_64
  CPU: x86_64
  Kernel Type: linux
  Kernel Version: 4.9.0-8-amd64
  Pretty Productname: Debian GNU/Linux 9 (stretch)
  Product Type: debian
  Product Version: 9
Comment 2 Halla Rempt 2019-05-01 09:31:56 UTC
Curiously, if I open my "fixed" version of the file and re-add a blur mask, the file opens fine.
Comment 3 Halla Rempt 2019-05-01 09:41:58 UTC
Looks like it's the specific setting for the blur mask in the original file that's causing the problems:

 <param name="horizRadius" type="string"><![CDATA[920.88]]></param>
 <param name="lockAspect" type="string"><![CDATA[true]]></param>
 <param name="vertRadius" type="string"><![CDATA[920.88]]></param>

What's also strange is how the colorize mask is used... Not to color line art (as in https://docs.krita.org/en/reference_manual/tools/colorize_mask.html), but as if it were just another paint layer.
Comment 4 Halla Rempt 2019-05-01 10:00:02 UTC
I've checked with 3.3.3, and Krita 4.2 pre-alpha really is a lot slower. 3.3.3 seems to be able to load the file, even though it takes a long time.
Comment 5 Halla Rempt 2019-05-01 10:04:18 UTC
4.0.0 also is much slower than 3.3.3 to load the gaussian blur filter mask.
Comment 6 Dmitry Kazakov 2019-05-01 11:16:33 UTC
Git commit 7e80b852e5b34177a74afea39bc4d657afd9d7fd by Dmitry Kazakov.
Committed on 01/05/2019 at 11:16.
Pushed by dkazakov into branch 'master'.

Fix activation of FFTW convolution worker

It seems like FFTW convolution was disabled since 18 Jun 2018,
when my faulty commit (31d8cf90822185675ba08f86b8b42a04bc4101e4)
applied De Morgan's laws incorrectly :(

M  +1    -1    libs/image/kis_convolution_painter.cc

https://invent.kde.org/kde/krita/commit/7e80b852e5b34177a74afea39bc4d657afd9d7fd
Comment 7 Dmitry Kazakov 2019-05-01 12:03:15 UTC
Git commit ca927d0bb1e9d81e90a475c67309956f38bbb8b8 by Dmitry Kazakov.
Committed on 01/05/2019 at 12:02.
Pushed by dkazakov into branch 'master'.

Fix operator priority

M  +2    -2    libs/image/kis_convolution_painter.cc

https://invent.kde.org/kde/krita/commit/ca927d0bb1e9d81e90a475c67309956f38bbb8b8
Comment 8 Ahab Greybeard 2019-05-01 18:29:44 UTC
Created attachment 119777 [details]
CPU and RAM usage with lock/freeze effect in action

The May 01 17:09 build of  krita-4.2.0-pre-alpha-96b04ed-x86_64.appimage has the two commits listed but still shows lock/freeze with the sample file as before.
This time, the RAM usage varies in a cyclic manner over a long time with variations in CPU load characteristics as well.
The attached image shows the file being opened at about the 145 second mark then activity to the right.
Activity between 230 and 170 seconds is the activity of the Apr 26 4.2.0 appimage which does not show cyclic RAM usage. (The Network History is not relevant.)
Comment 9 Halla Rempt 2019-05-02 08:40:44 UTC
*** Bug 386694 has been marked as a duplicate of this bug. ***
Comment 10 Halla Rempt 2019-05-02 12:46:48 UTC
The bug marked as a duplicate of this bug shows that the regression happened between 3 and 4, and was present in the first alpha's for Krita 4.
Comment 11 Dmitry Kazakov 2019-05-08 07:46:54 UTC
Git commit 30796fcab77c73d94035dd287dbc75a2cc99f913 by Dmitry Kazakov.
Committed on 07/05/2019 at 20:14.
Pushed by dkazakov into branch 'master'.

Fix application of Gaussian Blur with FFTW (about 30% faster)

The patch fixes a slowdown we introduced when implemented
two-stage gaussian convolution application. This two-stage
approach is good for spacial convolution algorithm, but it
is no good for FFTW one. Because every kernel (even one-
dimensional) should be first split into 2D-wave-plane, which is
extremely slow.

M  +10   -0    libs/image/kis_convolution_painter.cc
M  +11   -7    libs/image/kis_convolution_painter.h
M  +27   -1    libs/image/kis_gaussian_kernel.cpp
M  +3    -0    libs/image/kis_gaussian_kernel.h

https://invent.kde.org/kde/krita/commit/30796fcab77c73d94035dd287dbc75a2cc99f913
Comment 12 Dmitry Kazakov 2019-05-08 07:46:54 UTC
Git commit 0d6b2a86082f90705a6c05ab71babf03ca2cb544 by Dmitry Kazakov.
Committed on 07/05/2019 at 20:14.
Pushed by dkazakov into branch 'master'.

Limit Gaussian Blur filter radius to 100px when used as a mask

When used as a mask, Krita should recalculate additional
need/changeRect of the processed area of size:
actualSize + 4 * radius, which is too much of work.

In older version of Krita the test file loaded fine, because
colorize mask did update itself on loading and didn't provoke
full mask update. If you provoke full gaussian mask update
manually, you'll get the same 12-minutes recalculation process
(and it cannot run in threads, because access rects intersect
heavily).

The patch does the following:

1) When loading filter masks and filter layers: forcefully
   (and silently) limit gaussian blur size to 100 px.

2) When creating filter masks and filter layers, limit radius
   slider to 100 px.

3) When changing properties of Gaussian Blur mask, limit the
   radius slider to 100 px.

4) When applying Gaussian Blur filter directly, allow the user
   to select radius in full range: 0...1000 px

M  +11   -0    libs/image/filter/kis_filter.cc
M  +3    -0    libs/image/filter/kis_filter.h
M  +1    -1    libs/image/kis_base_processor.cpp
M  +3    -1    libs/image/kis_base_processor.h
M  +1    -1    libs/image/kis_node_filter_interface.cpp
M  +1    -1    libs/libqml/plugins/kritasketchplugin/models/FiltersCategoryModel.cpp
M  +2    -2    libs/libqml/plugins/kritasketchplugin/models/FiltersModel.cpp
M  +1    -1    libs/ui/dialogs/kis_dlg_adj_layer_props.cc
M  +4    -1    libs/ui/dialogs/kis_dlg_filter.cpp
M  +3    -1    libs/ui/widgets/kis_filter_selector_widget.cc
M  +1    -1    libs/ui/widgets/kis_wdg_generator.cpp
M  +1    -1    plugins/filters/asccdl/kis_asccdl_filter.cpp
M  +1    -1    plugins/filters/asccdl/kis_asccdl_filter.h
M  +1    -1    plugins/filters/blur/kis_blur_filter.cpp
M  +1    -1    plugins/filters/blur/kis_blur_filter.h
M  +27   -2    plugins/filters/blur/kis_gaussian_blur_filter.cpp
M  +4    -1    plugins/filters/blur/kis_gaussian_blur_filter.h
M  +1    -1    plugins/filters/blur/kis_lens_blur_filter.cpp
M  +1    -1    plugins/filters/blur/kis_lens_blur_filter.h
M  +1    -1    plugins/filters/blur/kis_motion_blur_filter.cpp
M  +1    -1    plugins/filters/blur/kis_motion_blur_filter.h
M  +5    -3    plugins/filters/blur/kis_wdg_gaussian_blur.cpp
M  +1    -1    plugins/filters/blur/kis_wdg_gaussian_blur.h
M  +1    -1    plugins/filters/colors/kis_color_to_alpha.cpp
M  +1    -1    plugins/filters/colors/kis_color_to_alpha.h
M  +1    -1    plugins/filters/colorsfilters/kis_color_balance_filter.cpp
M  +1    -1    plugins/filters/colorsfilters/kis_color_balance_filter.h
M  +1    -1    plugins/filters/colorsfilters/kis_cross_channel_filter.cpp
M  +1    -1    plugins/filters/colorsfilters/kis_cross_channel_filter.h
M  +1    -1    plugins/filters/colorsfilters/kis_desaturate_filter.cpp
M  +1    -1    plugins/filters/colorsfilters/kis_desaturate_filter.h
M  +1    -1    plugins/filters/colorsfilters/kis_hsv_adjustment_filter.cpp
M  +1    -1    plugins/filters/colorsfilters/kis_hsv_adjustment_filter.h
M  +1    -1    plugins/filters/colorsfilters/kis_perchannel_filter.cpp
M  +1    -1    plugins/filters/colorsfilters/kis_perchannel_filter.h
M  +1    -1    plugins/filters/convertheightnormalmap/kis_convert_height_to_normal_map_filter.cpp
M  +1    -1    plugins/filters/convertheightnormalmap/kis_convert_height_to_normal_map_filter.h
M  +1    -1    plugins/filters/dodgeburn/DodgeBurn.cpp
M  +1    -1    plugins/filters/dodgeburn/DodgeBurn.h
M  +1    -1    plugins/filters/edgedetection/kis_edge_detection_filter.cpp
M  +1    -1    plugins/filters/edgedetection/kis_edge_detection_filter.h
M  +1    -1    plugins/filters/embossfilter/kis_emboss_filter.cpp
M  +1    -1    plugins/filters/embossfilter/kis_emboss_filter.h
M  +1    -1    plugins/filters/fastcolortransfer/fastcolortransfer.cpp
M  +1    -1    plugins/filters/fastcolortransfer/fastcolortransfer.h
M  +1    -1    plugins/filters/gradientmap/krita_filter_gradient_map.cpp
M  +1    -1    plugins/filters/gradientmap/krita_filter_gradient_map.h
M  +1    -1    plugins/filters/halftone/kis_halftone_filter.cpp
M  +1    -1    plugins/filters/halftone/kis_halftone_filter.h
M  +1    -1    plugins/filters/imageenhancement/kis_simple_noise_reducer.cpp
M  +1    -1    plugins/filters/imageenhancement/kis_simple_noise_reducer.h
M  +1    -1    plugins/filters/imageenhancement/kis_wavelet_noise_reduction.cpp
M  +1    -1    plugins/filters/imageenhancement/kis_wavelet_noise_reduction.h
M  +1    -1    plugins/filters/indexcolors/indexcolors.cpp
M  +1    -1    plugins/filters/indexcolors/indexcolors.h
M  +1    -1    plugins/filters/levelfilter/kis_level_filter.cpp
M  +1    -1    plugins/filters/levelfilter/kis_level_filter.h
M  +1    -1    plugins/filters/noisefilter/noisefilter.cpp
M  +1    -1    plugins/filters/noisefilter/noisefilter.h
M  +1    -1    plugins/filters/oilpaintfilter/kis_oilpaint_filter.cpp
M  +1    -1    plugins/filters/oilpaintfilter/kis_oilpaint_filter.h
M  +1    -1    plugins/filters/phongbumpmap/kis_phong_bumpmap_filter.cpp
M  +1    -1    plugins/filters/phongbumpmap/kis_phong_bumpmap_filter.h
M  +1    -1    plugins/filters/pixelizefilter/kis_pixelize_filter.cpp
M  +1    -1    plugins/filters/pixelizefilter/kis_pixelize_filter.h
M  +1    -1    plugins/filters/posterize/posterize.cpp
M  +1    -1    plugins/filters/posterize/posterize.h
M  +1    -1    plugins/filters/raindropsfilter/kis_raindrops_filter.cpp
M  +1    -1    plugins/filters/raindropsfilter/kis_raindrops_filter.h
M  +1    -1    plugins/filters/randompickfilter/randompickfilter.cpp
M  +1    -1    plugins/filters/randompickfilter/randompickfilter.h
M  +1    -1    plugins/filters/roundcorners/kis_round_corners_filter.cpp
M  +1    -1    plugins/filters/roundcorners/kis_round_corners_filter.h
M  +1    -1    plugins/filters/smalltilesfilter/kis_small_tiles_filter.cpp
M  +1    -1    plugins/filters/smalltilesfilter/kis_small_tiles_filter.h
M  +1    -1    plugins/filters/threshold/threshold.cpp
M  +1    -1    plugins/filters/threshold/threshold.h
M  +1    -1    plugins/filters/unsharp/kis_unsharp_filter.cpp
M  +1    -1    plugins/filters/unsharp/kis_unsharp_filter.h
M  +1    -1    plugins/filters/wavefilter/wavefilter.cpp
M  +1    -1    plugins/filters/wavefilter/wavefilter.h
M  +1    -1    plugins/generators/pattern/patterngenerator.cpp
M  +1    -1    plugins/generators/pattern/patterngenerator.h
M  +1    -1    plugins/generators/simplexnoise/simplexnoisegenerator.cpp
M  +1    -1    plugins/generators/simplexnoise/simplexnoisegenerator.h
M  +1    -1    plugins/generators/solid/colorgenerator.cpp
M  +1    -1    plugins/generators/solid/colorgenerator.h
M  +18   -2    plugins/impex/libkra/kis_kra_load_visitor.cpp
M  +1    -0    plugins/impex/libkra/kis_kra_load_visitor.h
M  +1    -1    plugins/paintops/libpaintop/kis_filter_option.cpp

https://invent.kde.org/kde/krita/commit/0d6b2a86082f90705a6c05ab71babf03ca2cb544