AnalyticalGraphicsInc/cesium — pull request #836 by kring (2013-06-03 21:00:43+00:00)
Title: Improve performance of missing tile check

Some imagery providers - Bing most notably - don't return errors when tiles are missing, but instead return a valid (but useless) image. We determine if a given tile we just downloaded is the "missing tile" by checking the value of a few choice pixels. This yields terrible performance because we have to first draw the image to a canvas. The HTML `Image` doesn't give us access to ... well... anything, so we can't do much better while using that.

So, this pull request instead requests images using an `XMLHttpRequest` with a `responseType` of `blob`, and then creates a blob URI (different from a data URI!) for the image, and then passes that blog URI to an HTML `Image` to decode it. This gives us access to the size of the blob, so then we can restrict our "missing tile" pixel-check to those tiles that have the same size as the actual missing tile. Some day, if Bing starts including all the CORS headers that it should, we can check a header directly and won't have to check pixels at all.

The end result here is smoother animation during fast camera motion, because missing tile checking used to take 10+% CPU time when moving moderately quickly. Now it is negligible. There is a small amount of new overhead from the blob URI indirection, but it looks to be very small.

This also requires some pretty fancy browser features that only became available in Chrome about a year ago. I've attempted to do feature detection and fall back on the old method when necessary. If you have an old browser handy with which to try it, please do.