X20 Times Faster Overview Refresh Rate (and Histogram)

Hello everyone, my recent modify of Krita gives a x20 times faster response of both overview and histogram, without changing the result of all unit tests. Here’s the demonstration.

This is my first time to edit code in such a huge project. Could you please help me? Here’s my concern:


I admit this laggy overview window is the part made my most curious of. In fact this is the very reason I give up Krita and turn to Sai2 for a few days during May because Sai2 has a instantaneous overview window :rofl:.

The Principle of Overview (and Histogram) Update

The current version of Krita got it’s updating overview modified by multi people from a varity of time and it’s quite complex. But I think where I edit makes no sense to me.

See OverviewWidget::registerIdleTask, it 's the start point of everything


This piece of code adds a Idle Task(which means this task will only run when the user finished their stroke aka Idle) to acquire thumbnail image from a fresh new KisImageThumbnailStrokeStrategy. By there KisImageThumbnailStrokeStrategyBase::initStrokeCallback registers a parallel work of computing thumbnail image, and a final job of resizing it and then immediately announce the fact.

These parts are connected by signals and slots. Following the clue, there should be no latency because the overview regeneration is tied with the stroke(not a long peroid internal refresher, which is my first guess).

The point is in the Idle Task part. The KisIdleWatcher is the class that is responsible for deciding whether the image edit is finished so that thumbnail update can be launched (used indirectly, you need to march twice following the call stack). In all, it sets a internal timer which will regularly call this function:

You can see that, if we reach line 141, then it will consider image is idle and trigger thumbnail and histogram. But the condition for a normal Krita usage will need idleCheckCounter to be greater than 4, the current value of IDLE_CHECK_COUNT. And the only way to increase idleCheckCounter is to fall in line 144.

Each time the idleCheckTimer(for overview the timer is 200ms) is started, the counter can only increase by one. Which means that the user needs to wait at least 4*200 = 800ms to see the result. Not to say that the growing procedure can be broken by image update(say, the user draw another stroke) or some internal updates. So cause the overview to be laggy.

So I change the idleCheckTimer to refresh every 10ms and it’s at least 20 times faster than before(40ms compared to 800ms). The change will both apply to overview and histogram because they use the default parameter of delay value.

Performance Concern

I don’t think a regular timer that refreshes every 10ms is a performance bottleneck, 10ms is quite long for a computer and can perform millions of instructions on my computer.

In a peroid of Krita when overview is still using simple strategy, the refresh rate is 150ms. But after this bug fix the minimum refresh rate become a shockingly 800ms and I think it’s not acceptable.

If you indeed think is a performance issue, should I make a option in the setting so that it can be choosed by the user freely? What’s your opinion about this? There is indeed an feature request for this in Krita forum.

Should It be Even Faster?

Now the refreshing rate is quite comfortable for me, considering the best athletes will have a response time of about 120ms, it’s rarely noticable for a refresh that will be done in 40ms.

Why Quadruple Test of Idle Image Detection

I don’t know why Dmitry Kazakov used a quadruple test of idle image, and left a comment to confirm this quadruple test is needed:

Will it Break anything

This change will not change the result of any unit test. The Krita master branch d0a1ca38e805ae292154f92f997533eff2e8289e got two tests broken and the same happens to my version when testing on my Windows11 PC.

Broken Unit Tests

And I tried the overview process for a large (5000x4000) image and a 1000px wide wet brush, the overview does show up instantaneously even the stroke is a bit laggy.

So I think this should work. But is it normal to have Krita master branch doesn’t pass all unit test on Windows platform?

About Pull Request

This is my first time editing such a huge project and I didn’t get the meaning of every single line of code. But I think that is good enough for me to keep this modification because that works. I wonder if such a small change can have a pull request so I don’t have to perform the same modification and build Krita every time?

Thanks for your patience to read till the end! :hugs:

6 Likes

Hi

You can always create a MR, in the worst case it will be rejected or it will be asked to you additional explanation or change to the code.

Grum999

2 Likes

Hey, I think reducing the timeout slightly may be fine, but my gut tells me it’s made to be slow on purpose. It may be optimized for the low-end hardware and reduced power consumption.

The delay is a deal breaker for me, and I suggest to just use a secondary view of the same document as the true real-time overview, if anyone needs it.

1 Like

A secondary view can’t dock in the current window. :rofl: And not possible to use when using a non-tab Krita window management.

I’d like to try to have a MR, it seems that Dmitry Kazakov is quite active for Krita development, maybe I could also ask Kazakov there :melting_face:

Dmitry is the main developer. The best way to ask him anything is by doing so in the irc channel.

I get a feeling it might be a bit too fast somehow

Asking about code changes is best done with context, so I suggest you just open an MR and describe what you are trying to achieve clearly. Sooner or later someone will get back to you with comments, or just merge it if there are no concerns.

The change in the current form is trivial, so it’s a matter of experience if it could affect some other part of the app adversely. Core developers will be able to help with that.

Regarding your comment, I use a separate view in subwindows mode and it’s working fine. You just need to arrange windows or pin that view always on top. Another option is to use the view in a separate OS window. It’s rather flexible, but yes you can’t dock it. For my use case it works well, for others the overview docker will be better.

I ask the forum members to test this in the nightly builds. The change is merged - Make IdleWatcher checking idle more often to speedup IdleTasks (!2180) · Merge requests · Graphics / Krita · GitLab

So please test it.

2 Likes

I’ve tested this nighty build and it works pretty well. Thanks everyone

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.