arcade icon indicating copy to clipboard operation
arcade copied to clipboard

Drawing Thousands of Textures

Open eschan145 opened this issue 3 years ago • 12 comments

When running a performance test on drawing textures using draw_scaled_texture_rectangle, I found it laggy and slow. Is there an efficient way to draw thousands of images? I could try using pyglet's images and draw them in a batch, but I don't know if arcade supports batch drawing images. Could this be implemented, so that performance is much better than drawing textures individually?

eschan145 avatar Jul 12 '22 14:07 eschan145

I'm not sure if I understand your use case, but wouldn't sprites cover this?

pushfoo avatar Jul 12 '22 14:07 pushfoo

Using Sprites in a SpriteList you should be able to draw millions of sprites(though you probably have a long startup time for that) but the actual drawing should be fine.

Cleptomania avatar Jul 12 '22 14:07 Cleptomania

That draw command doesn't do any sort of batch drawing. It will be very slow. Really, we should update the docs to reflect that.

pvcraven avatar Jul 12 '22 14:07 pvcraven

Don't sprites take up a bunch of memory? It would take forever to start up. Hopefully, this could be optimized in the future.

eschan145 avatar Jul 12 '22 14:07 eschan145

It takes memory to store the image. But if you load multiple of the same image, it reuses the image data.

pvcraven avatar Jul 12 '22 14:07 pvcraven

@eschan145 I think we need to know more about the use case to give useful advice:

  • How many images do you need to draw?
  • How big are the original sizes?
  • How many of the images are unique, and how many are repeated?

Can you tell us more about what you're trying to build?

pushfoo avatar Jul 12 '22 14:07 pushfoo

I had roughly four thousand textures the size of 1x7 pixels. The scale was 1.0. The fps was about three or four. All of the images were repeated. Along with them, there were about four hundred sprites, although those wouldn't have made any difference.

eschan145 avatar Jul 12 '22 15:07 eschan145

Do it up as sprites. Are you loading the images from a file, or from a dynamic image?

pvcraven avatar Jul 12 '22 15:07 pvcraven

I had roughly four thousand textures the size of 1x7 pixels. The scale was 1.0. The fps was about three or four.

Are these the arrows you mentioned in #1264?

pushfoo avatar Jul 12 '22 15:07 pushfoo

Sprites were created exactly for what you are describing here. docs also describe texture caching and reuse: https://api.arcade.academy/en/latest/advanced/textures.html

Like already mentioned, you can probably do a million of them just fine.

In arcade 2.7 (development branch) you can also mix aracde and pyglet rendering freely if you are more comfortable with the pyglet way of doing things, but sprites in arcade are kind of the same.

In gpu based libraries you can't get away with that many draw calls. I'd say 400-500 is the practical limit with python before things really start to lag.

There's also an option to use custom shaders to speed things up even more, but that depends on the exact details.

einarf avatar Jul 12 '22 16:07 einarf

Could Cython be used to speed things up in drawing?

eschan145 avatar Jul 12 '22 17:07 eschan145

Could Cython be used to speed things up in drawing?

SpriteList will batch draw all your images, so you shouldn't really need cython. It's incredibly fastl. Like adding sprites to a batch in pyglet. There might of course be some details about your implementation we haven't taken into account. For example if you are moving thigs around a lot.

It could be useful to add more information about what you are trying to achieve here. Also we do have a discord server were discusstions like this are much more productuve.

einarf avatar Jul 12 '22 17:07 einarf

Closing, as this seems to have more to do with poor performance in drawing shapes.

pvcraven avatar Aug 17 '22 15:08 pvcraven