Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

geotiler performance note #35

Open
time4tea opened this issue Feb 8, 2023 · 5 comments
Open

geotiler performance note #35

time4tea opened this issue Feb 8, 2023 · 5 comments

Comments

@time4tea
Copy link

time4tea commented Feb 8, 2023

hiya - thanks for your library, it is very nice, and I use it in https://github.com/time4tea/gopro-dashboard-overlay

as the rendering code in my project gets called a lot - i was looking for places that I could make some easy gains in performance - so i ran the rendering code in viztracer.

I got the following trace:
viztracer before

as you can see there is quite some time spent in PIL imagedecode - this seems to be because the cache in the system caches the data files, but there is no image cache in the library. When drawing maps in my program we reuse map tiles a lot, as the map is moving pixel by pixel around the place.

i couldn't find a good place to put an image cache in, so i kind of bodged it, and ended up with a trace that looks like this:

viztracer after

you can see that the time to create the image is much reduced - from about 7.5ms to about 1ms - assuming a cached tile.

The code is smashed in right now, so no prizes for quality - but you are welcome to it if it is useful for you.

https://github.com/time4tea/gopro-dashboard-overlay/blob/geotiler-perf/gopro_overlay/geo_render.py

It is a "drop-in" replacement for the geotiler.render_map (at least how I use it)

Hope this is useful/interesting - anyhow thanks for making a nice library.

Cheers!

James

@wrobell
Copy link
Owner

wrobell commented Feb 8, 2023

Thanks for all the information. I am not sure if you are aware, but GeoTiler support caching, example: https://wrobell.dcmod.org/geotiler/usage.html#caching.

But there might be need for GeoTiler be smarter here, i.e. cache whole map and allow to pan it around. Something to dwell on!

@time4tea
Copy link
Author

time4tea commented Feb 8, 2023

Hi yes - however the existing caching only caches the image data - not the image object. Each time the tile is retrieved from the cache, the image object is recreated.... at least that's what i saw - perhaps I'm making an error.
this happens at:
https://github.com/wrobell/geotiler/blob/master/geotiler/tile/img.py#L68

Cheers!

@wrobell
Copy link
Owner

wrobell commented Feb 8, 2023

This caches tile objects: https://github.com/wrobell/geotiler/blob/master/geotiler/cache.py. Tile object references existing image object.

In theory, you just need a similar function to "redis_downloader" function in the cache module, and then use that function the same way as in the documentation example.

@time4tea
Copy link
Author

time4tea commented Feb 8, 2023

Tile objects don't contain a PIL.Image they contain file data - like a PNG file.

@wrobell
Copy link
Owner

wrobell commented Feb 8, 2023

Good point. I see the problem now. This is something to reconsider. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants