Replace rand with rand_r in airbrush noisy as well as total random color source
Closed, ResolvedPublic

Description

At least on my machine, rand spends a lot of time making sure nothing else is using the random number generator currently via a "lock" instruction.

rand_r circumvents this problem by keeping its RNG state in the instance of the class using it, which I believe only runs on a single thread.

This gives a noticable performance improvement for big "airbrush noisy" brushes. for the total random color source, the improvement is measurable, but on my machine it was very slow before and is still very slow (for a big brush - small brushes are fine of course)

tpaulssen updated the task description. (Show Details)
tpaulssen raised the priority of this task from to Needs Triage.
tpaulssen added a project: Krita.
tpaulssen added a subscriber: tpaulssen.

actually, i was wrong: the class is used from multiple threads simultaneously, so the random state would get accessed concurrently. even though that's not problematic per se, as reproducibility is not needed here, i'm going to make a second version of my patch that creates a random state on the stack and seeds that from the global (locked) random number generator.

the new diff version has been uploaded at the same spot.

tpaulssen closed this task as Resolved.Dec 14 2015, 3:45 PM
tpaulssen claimed this task.

landed the patch in master. the improvement will soon roll out to our users and i'm happy :)

Restricted Application added a subscriber: woltherav. · View Herald TranscriptDec 14 2015, 3:45 PM