Effect masks are calculated every time an update job is added, and the calculation is relatively expensive:
The 2.9% of effectMasks seen above is actually only one call. There are five calls in total, i.e. the call above is only 20% of all calls to that function, as can be seen here:
With this PR effect masks are precalculated each time the layer's children get changes (adding or removing of nodes), and each time any change (in terms of KisBaseNode::baseNodeChangedCallback) in a mask node happens that lies beneath a layer node. As far as I understand, this should cover all cases (adding, removing, visibility, activeness) that are checked for in the construction of the effects masks list. I lack knowledge of Krita though to really test this.
The caching of selection masks was added as it seems natural to do it in the same way (there was no profiling evidence).
Though this change adds brittleness due to the notification system, it removes an expensive call from the inner dab loops.
With this PR, the call to effectMasks vanishes from profiling:
The main caller, KisLayer::changeRect goes from 4.1% to 0.4%. As this is only 20% of all calls, we can expect a performance benefit of up to (4.1-0.4)*5 = 18.5%.