Lag specific page
Open, NormalPublic

Description

I attempted to write an article regarding the most common issues with lag. It explains first how computers work. I think this part will need some image to illustrate the metaphor I am using.


How to use Krita efficiently

So, Krita is slow on your system. How could that be, did the devs not optimise?

It might actually be the opposite. We designed Krita to be capable of using super big values everywhere, no matter whether the canvas itself can handle it. We allow these massive values because we know that people who use Krita professionally need it to be able to have really big files regardless of how speedy it is. Krita is not able to warn you about whether your computer might not be able to handle certain values, so you will need to develop an instinct for that yourself. This page describes the related factors.

Components of Speed: Hardware

This part is about what your computer is able to do. To determine your computer's abilities you need to look at several items.

The main determining factor of how fast your computer is, is the CPU, or processor. The processor is basically the calculator of your computer and handles all the commands and maths in the code.

Most computers nowadays have multiple cores in their processors, which means that if the code is designed for it, the processor can do multi-threading, or do two instructions at once. In Krita, we multi-thread wherever possible, like with the majority of the adjustment filters.

There are some parts to Krita that aren't multi-threadable for several reason, and one of the important ones is that Krita doesn't actually calculate that much. Rather, it manipulates pixels, that is data, which brings us to the next components of speed: Memory.

There's two types of memory. There's the long term memory, that's all on your harddrive. This is saved files, folders, and temporary files. The other memory is the RAM, the working memory.

The relationship between the working memory and the harddrive is somewhat like a desk and the archives. In the archives the data is stored in a file, and when a program needs to do something with that file, it gets the file from the archives, reads it and puts those into the working memory. After that, it can send the data to the processor.

Moving a file from the harddrive to the ram(loading) or back(saving) takes a lot of time, something you must have noticed yourself whenever saving or loading big files.

Similarly, moving files from the working memory to the processor also takes time. What this means is that the most important factor in speed is not just a good processor, but also how fast data can go from the memory to the processor.

All programs work this way, and as such, all programs that you have open on your computer use the RAM. Krita thus has to share the RAM with other programs, and some of them, like web-browsers, can take up quite a lot of it.

So, that means Krita can never actually use all of the ram you have on your computer. To prevent Krita from fighting with other programs, there's a limit to the amount of memory it takes. You can configure this in the settings under the performance tab.

[Of course, if you want your computer to act regularly, and have, like many artists some music running while you paint, or a tab open on some reference, you should not set this to 100%]

When you force Krita to go over this limit, Krita will try to do swapping. Swapping is a mechanism where a part of the drawing (the undo states, or something else) is stored onto the harddrive. You can configure where on the harddrive it does so. As noted before, swapping will make Krita slower, because it is saving and reading from the harddrive, so try to avoid swapping.

If this mechanism didn't exist, Krita would instantly crash due to an "Out of memory error". Sometimes it will still do this if you push it over the limit too fast so it has no chance to start swapping.

[Some people have a cheap flash drive(a usb stick for example) as the swap location. Flash drives are like the harddrive, but very fast to read from. However, using a flash drive for swapping will wear it out super quickly, which is why it is recommended to use a flash drive used for nothing else.]

The final component of speed is one that people expect a lot from, but is actually not that important. The graphics card.

Krita uses the graphics card via OpenGL, and it uses it to display the canvas really quickly. This is necessary to make rotating, panning and zooming very fast. We don't ask OpenGL to calculate much, but often times the drivers of a graphics card aren't very good, causing slow downs, bugs and crashes on very simple things. On this front, on windows, you can switch to ANGLE, which will use DirectX(windows' personal graphics card api) instead.

So for fast efficient use of Krita on the pure hardware level:

  • Make sure that your image fits on the amount of RAM you have available, so that Krita does not do the swapping mechanism, and will not have out-of-memory-crashes. We will go over how you can figure out image size later on.
  • Make sure that other programs aren't hogging the ram, so that Krita doesn't fight with them.
  • When buying a computer and trying to find the best for Krita, the most important number is the speed at which the RAM and the CPU can communicate.
  • As for the graphics card, it is not important to have a super fast graphics card, because we don't tell the graphics card to do a lot of calculating, but it is important to have one with good quality drivers.

Resources and loading.

When Krita starts up, it is loading the files. So each file needs to be moved from the archives to the working memory. On some systems, each file needs to pass through security as well.

So if Krita loads slow for you, this is either because you have too many resources active, or one of your security programs is thoroughly checking each loaded file for risks.

You can reduce the loaded files by going to the resource manager and disabling bundles there.

The perfect Canvas

So, if we have only limited amount of ram, how do we make proper use of it?

A start is figuring out how much ram our drawing takes up.

An image is made up out of layers, and those layers out of pixels, so we can figure out how big an image is by first figuring out how big a single pixel is.

This is where bit depth comes in. We use numbers to store which color a pixel is. And just like how writing down a number in real life will require more space the bigger the number is, a computer needs more memory the bigger the maximum number is.

For a regular image, we use four different numbers per pixel. That's one for the amount of red, green, blue and alpha, the transparency. The lowest about Krita can handle is 8bits per number. So that's 8*4=32 bits per pixel.

Then, if we take our image, say, an A4 image of 2480 * 3508 pixels, that is 869840 pixels in total. There's 32bits per pixel, so in total 869840 * 32= 278394880 bits.

278394880/8= 34799360 bytes, which is 34799 kilobytes, which is roughly 35 megabytes.

So if we'd fill a whole layer of the image, that'd take up 35 megabytes.

However, we usually have multiple layers, so there's 35 megabytes per layer. We also need to keep two copies of all the layers together, so it can be displayed and stored, so that's another 2 layers. For each time we use masks or filter layers, another layer is added.

Best is to take your avarage image size, and amount of layers, say 30(common for image with complex composition, like comics), then add half of that for filter layers and the like, becoming 45.

45*35mb=1575 mb.

If you have a 2 gb computer, that is a bit much(more than 3/4th of what you computer can handle), and thus you will need to be a bit more careful with the amount of layers you use. For a more modern computer with 4 or 8 gb of ram, this is suitable.

However, if we then double the bitdepth, to 16 or even 32, the image size will also get doubled or quadrupled to such sizes. The same image would take up 3 gb for 16bit, and 6gb for 32 bit, making it a bit hard to handle even for beefier computers.

Of course, there's optimisations happening in the background. If you make a 32bit/channel A4 image with 45 layers and only draw a single dot on each layer, you will find it won't take up anywhere near 6 gb of ram. This is because Krita will only store the total square that little dot takes up, abstracting the rest away.

You can thus reduce the amount of ram used by cropping the layers with the crop too set to "layer". Other types of optimsations include just merging or removing layers after you're done with them, or reducing the bitdepth of layers that don't need higher precision by going into layers->convert->convert layer colorspace.

A thousand dabs a second: Optimizing Brushes

Our base brushes are... optimized for A4 print size, and tend towards high quality strokes instead of speed.

If you work big, there's thus several optimizations you can try.

  • Brush Engine. Some brush engines are faster than others. The fastest brush engines are the Quick Brush engine and the pixel brush. The color smudge brush is a slow engine because it always places two dabs at once. So choose the quick brush engine or the pixel brush when sketching, and use the color smudge brush for precision and finishing work.
  • Spacing. The majority of Krita's brushes work in a dab based manner. This means that it makes the strokes by putting down a series of brush dabs. The spacing parameter determines how often a brush dab is placed. Too high a spacing and the stroke will look weird, but too low a spacing and you get a laggy brush.
  • Precision. Precision determines how hard Krita will do it's best to align brush dabs. It's effect is most noticable with textured rake brushes. For really big brushes, said effect is difficult to see, so turning it down, or turning on auto-precision can make a big difference.
  • Fuzzy rotate is a pretty slow function, so use it sparsely.

Other things that could be tried:

  • Check if you accidentally turned on the stabilizer in the tool options docker.
  • Try another display filter like trilinear. settings → configure Krita → display
  • Try a lower channel depth than 16-bit.
  • For NVidia, try a 16-bit floating point color space.
  • For AMD (Krita 2.9.10 and above), turn off the vector optimizations that are broken on AMD CPUs. settings → configure Krita → performance
  • It's a fairly memory hungry program, so 2GB of ram is the minimum, and 4 gig is the preferable minimum.
  • Check that not something else is hogging your CPU
  • Check that Instant Preview is enabled if you're using bigger brushes (for very small brushes, disabled)
  • Set brush precision to 3 or auto
  • Use a larger value for brush spacing
  • If all of this fails, record a video and post a link and description on the Krita forum.
  • check whether opengl is enabled, and if it isn't, enable it, or if it is, and you'r on windows, try the Angle renderer. Or disable it.

Nope, still slow.

If you have read this full page, and you still have trouble with getting print quality images using Krita, you can do the following to help us figure out what is causing it:

  1. We need a file that lags. Maybe there's something unique about your image that is revealing a bottleneck.
  2. We need to have a video showing the lag. Oftentimes, we have noticed people have the stablizer turned on which we, who have the stablizer turned off cannot reproduce. The video allows us to spot these things. To allow this, we need to see the whole Krita screen.
  3. A list of system information. Krita gives you a copy-pastable list under help->system information.

Make a thread on the forums, and add the appropriate links. It must be the forums, because otherwise we can't make multiple suggestions.

woltherav updated the task description. (Show Details)Nov 26 2017, 8:10 PM
woltherav updated the task description. (Show Details)Nov 26 2017, 8:34 PM