Conversation
|
I'm a little worried about reusing If someone called My only other thought is, should this be optional? There might be some reason not to want lazy loading, in which case maybe we could add a way to mark a library as not lazy. But I can't think of a specific reason at the moment, so perhaps that can wait. |
|
Maybe a cleaner version of this change would be to introduce a dedicated store for bundle-backed image bytes, something like
On the optional question, since |
|
Whoops, I missed this reply somehow. Agreed, a I also missed |
Summary
This changes
lime.utils.AssetLibraryto decode bundle images lazily instead of decoding everyIMAGEasset eagerly in__fromBundle().Bundle images are now stored in
cachedBytesfirst, then decoded on firstgetImage()/loadImage()access.isLocal(IMAGE)is also updated so synchronous access continues to work for bundle-backed images that have not been decoded yet.Why
The previous behavior eagerly called
Image.fromBytes(...)for everyIMAGEasset in a bundle as soon as the library was created from the bundle.For large bundles, this can create very large startup costs in both CPU and memory even when only a subset of the bundled images is actually used.
This change keeps bundle loading cheaper and shifts image decode cost to first real use, which is a better fit for large runtime-loaded libraries.
Behavior change
Before:
fromBundle()decoded allIMAGEassets immediatelyAfter:
fromBundle()keepsIMAGEassets as bytesgetImage()/loadImage()decode on demandisLocal(IMAGE)remains true for bundle images backed by cached bytesNotes
This does change when decode cost is paid:
Preloaded images still go through
loadImage()duringload(), so they are still decoded during preload as expected.