Skip to content

๐Ÿš€ A from-scratch Android image loader to explore how Glide & Coil work under the hood. Includes benchmarking for bitmap reuse, downsampling, and task cancellation.

Notifications You must be signed in to change notification settings

IamRaja007/BitmapPoolLearnings

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿงช Android Custom Image Loader Benchmark

A no-library, from-scratch low-tech image loader built to understand how libraries like Glide and Coil might work under the hood.


๐ŸŽฏ Why I Built This

Instead of using Glide blindly, I built my own image loader to explore:

  • What happens without downsampling?
  • Can I reuse bitmaps safely?
  • Does cancelling offscreen image loads help?
  • What do GC and memory stats reveal during scroll?

๐Ÿ› ๏ธ Benchmark Setup

  • Loads shuffled high-res images from Picsum

  • Displays in a RecyclerView

  • Benchmark flags:

    data class BenchmarkConfig(
        val usePool: Boolean,
        val useDownsampling: Boolean,
        val useCancellation: Boolean
    )
  • Measures scroll time, memory usage, GC events, and network stats

  • Automated scroll flow for consistent results


๐Ÿงต Image Loading Flow

  1. Cancel task if ViewHolder is recycled
  2. Decode via BitmapFactory
  3. Downsample based on ImageView size
  4. Try to reuse bitmap from custom pool
  5. Update UI only if still bound to correct image

๐Ÿ“Š Key Findings

Feature Impact
โŒ No Optimization High memory, GC storms, janky scroll
โœ… Downsampling Lower memory, faster decode, fewer GC events
โœ… Bitmap Pooling Reduces allocations, tricky to get right
โœ… Task Cancellation Huge win during flings, saves CPU & memory
๐Ÿ† All Combined Smoothest scroll, minimal GC, lowest network use

๐Ÿง  Lessons Learned

  • Reusing bitmaps requires exact match + inMutable=true
  • Downsampling is a no-brainer
  • Cancellation improves UX and performance drastically

โค๏ธ Final Thoughts

Donโ€™t use this in production โ€” use Glide or Coil.

But if you're curious, bored, or want to learn: build one. You'll walk away with a deep understanding of bitmaps, memory, and image loading internals.


About

๐Ÿš€ A from-scratch Android image loader to explore how Glide & Coil work under the hood. Includes benchmarking for bitmap reuse, downsampling, and task cancellation.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages