Reduce copying in getStabilizedPaintInfo (WIP)
ClosedPublic

Authored by alvinhochun on Jul 9 2017, 7:09 AM.

Details

Summary

I am trying to reduce the copying and allocations made in getStabilizedPaintInfo by reusing the result KisPaintInformation object in the mixing function.

Initial profiling shows stabilizerPollAndPaint taking 30% less time, but it's not very accurate.

The code looks a bit messy but it does what it does. Any suggestions on making it better or alternative approaches? (I dislike the implicit pass-by-reference parameter.)

Diff Detail

Repository
R37 Krita
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
alvinhochun created this revision.Jul 9 2017, 7:09 AM
Restricted Application added a subscriber: woltherav. · View Herald TranscriptJul 9 2017, 7:09 AM
dkazakov edited edge metadata.Jul 9 2017, 7:13 AM

It might be a good idea to denote KisPaintInformation::mix() function from 'statis' member to a usual method. Then the signature would be quite obvious :)

alvinhochun added inline comments.Jul 9 2017, 7:16 AM
libs/image/brushengine/kis_paint_information.cc
561

I think I might have made a redundant heap allocation here...

alvinhochun planned changes to this revision.Jul 9 2017, 12:14 PM
alvinhochun updated this revision to Diff 16404.Jul 9 2017, 5:50 PM
alvinhochun marked an inline comment as done.
alvinhochun edited the summary of this revision. (Show Details)

Changed to member functions, now seems to be clearer.

Haven't redo profiling yet...

Profiling results by drawing in circle continuously for 20s

Highlighted on the left is operator new(unsigned long long) and on the right are places calling it. (You can use https://demangler.com/ to demangle the names. Add an underscore before the name for it to work.)
The profiling result file is also attached, use Very Sleepy to open.

Original code:


New code:


(These are only results of one

Redid some profiling with VTune (it doesn't prevent Krita from updating the canvas like Very Sleepy did):

Original code:

New code (the other constructor takes too little time to be worth mentioning):

From these two particular samples, it appears the new code not only saves a lot of time (about 90% time saved from constructing KisPaintInformation), but it also enabled a bit better utilization of the second CPU core (not sure what operation it is though).

dkazakov accepted this revision.Jul 14 2017, 12:54 PM

Hi, @alvinhochun!

The patch looks fine, except of the mixture of different interfaces in KisPaintInformation. Could you add a bit of TODO with comments to the old-style mix() calls, so that people would know that they should be refactored?

Please also state in the comment that "on windows malloc/free is very slow and fragments the memory", so people would know that it is a Windows-specific problem.

libs/image/brushengine/kis_paint_information.h
268

Please add comments to the old-style functions that they are to be refactored :)

This revision is now accepted and ready to land.Jul 14 2017, 12:54 PM
This revision was automatically updated to reflect the committed changes.