# Very slow blitting, trying to optimize

**URL:** <https://www.ruby-forum.com/t/very-slow-blitting-trying-to-optimize/198310>\
**Category:** wxRuby\
**Created:** [October 29, 2010, 4:30pm UTC](https://www.ruby-forum.com/t/very-slow-blitting-trying-to-optimize/198310 "2010-10-29T16:30:32Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![okkezSS](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/85f322/32.png) [@okkezSS](https://www.ruby-forum.com/u/okkezSS)\
**Post date:** [October 29, 2010, 4:30pm UTC](https://www.ruby-forum.com/t/very-slow-blitting-trying-to-optimize/198310/1 "2010-10-29T16:30:32Z")

</div>

Hello,

I’m coding a 2D map editor for a small game engine on MSW and I’m  
running into blitting problems. The bigger my map is, the longer it  
takes to blit a  
tile on it. sometimes, when I try to draw a tile to fast, it even fails  
completely at blitting and I have to close and reopen the program for it  
to work again.

I have attached the main drawing methods to this post.

How it works:

1. I have a custom cache class that creates and retrieves bitmaps on  
demand to speed up things a bit. Used especially when using tiles,  
layers or the whole tilemap bitmap. All get\_X\_bitmap methods you see are  
used to retrieve bitmaps from cache.

2. The draw\_layer and draw\_tilemap methods have a rect argument. When  
not nil, only the region specified by this rect is redrawn. Again, this  
is to speed up the whole process.

I did some basic speed test using the Time class to see how log it takes  
to blit a tile depending on the map size, using 32x32 tiles.

On a 20x20 map, the whole process takes around 0.032 to 0.041 seconds  
On a 100x100 map, it can take up to 0.5 seconds

The most weird part is when I try to draw tiles to fast on a big map.  
It starts to blit the first few tiles (with a log of lag) and then it  
completly fails. Blitting now takes 0.0 seconds and nothing is drawn on  
screen.

Any idea on how I can fix this?  
And pease tell me if there is not enough imformation or source code, i  
can provide more.🙂

Thank you very much!

- Sasha
