<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Palak Agrawal on Medium]]></title>
        <description><![CDATA[Stories by Palak Agrawal on Medium]]></description>
        <link>https://medium.com/@palak1998agrawal?source=rss-b34ad28da018------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*72MtB49F2XOBqqf4V8MhQw.jpeg</url>
            <title>Stories by Palak Agrawal on Medium</title>
            <link>https://medium.com/@palak1998agrawal?source=rss-b34ad28da018------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 11:18:13 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@palak1998agrawal/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Part 2 — How Glide Cheats at Memory Management (And You Can Too)]]></title>
            <link>https://medium.com/@palak1998agrawal/part-2-how-glide-cheats-at-memory-management-and-you-can-too-c87da925c9c6?source=rss-b34ad28da018------2</link>
            <guid isPermaLink="false">https://medium.com/p/c87da925c9c6</guid>
            <dc:creator><![CDATA[Palak Agrawal]]></dc:creator>
            <pubDate>Mon, 19 May 2025 16:55:01 GMT</pubDate>
            <atom:updated>2025-05-19T17:25:39.797Z</atom:updated>
            <content:encoded><![CDATA[<h3>Part 2 | How Glide Cheats at Memory Management (And You Can Too)</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*QjH-HopSOByv1gh6WV6gcA.png" /></figure><p><strong>Welcome back to Bitmap Bootcamp!</strong><br> In <a href="https://medium.com/@palak1998agrawal/bitmaps-in-android-the-pixelated-trouble-maker-part-1-5e904945692a">Part 1</a>, we discovered that Bitmaps are loveable memory hogs who just want all your RAM and aren’t afraid to crash your app to get it. 🐷💣</p><p>Now in Part 2, we’ll:</p><ul><li>Peek into Glide’s Bitmap pool spa</li><li>Build our own reusable pool</li><li>Spy on which bitmaps are memory-hogging monsters</li><li>Decode smarter with inJustDecodeBounds</li><li>Add lifecycle &amp; thread-safety like a pro</li></ul><p>Let’s start with a mystery:</p><blockquote><em>How does Glide magically load 100s of images without your app wheezing like it’s running on a potato?</em></blockquote><h3>🔍 Understanding inJustDecodeBounds = true</h3><p>You’ve probably seen this:</p><pre>val options = BitmapFactory.Options().apply {<br>    inJustDecodeBounds = true<br>}<br>BitmapFactory.decodeFile(path, options)</pre><p>This might look like a <strong>no-op</strong>, but it’s secretly a <strong>spy mission</strong>. 🕵️</p><h3>🧠 What happens?</h3><p>Android peeks at the image <strong>headers only</strong>, without loading the actual pixel data. It then populates:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*T8epJMAsNyebhUMAaeXUcA.png" /></figure><p><strong>Why use this?</strong></p><p>To <strong>measure before cutting</strong>.You don’t want to load a 5000×5000 image into a 200×200 thumbnail. That’s like wearing an XL hoodie to a ring ceremony.</p><p>So you:</p><ul><li>Read the bounds</li><li>Calculate the downsampling factor (inSampleSize)</li><li>THEN decode efficiently</li></ul><h3>Final decode:</h3><pre>options.inJustDecodeBounds = false<br>options.inSampleSize = 4<br>val bitmap = BitmapFactory.decodeFile(path, options)</pre><p>Boom. Small image, happy memory, zero crash.</p><h3>♻️ Glide’s Secret Weapon: LruBitmapPool</h3><p>Now let’s talk about the <em>real hero</em>: <strong>Glide’s Bitmap pool</strong>.</p><p>Glide is smart. Instead of doing this:</p><pre>val bitmap = BitmapFactory.decodeFile(...) // Allocates new memory every time</pre><p>It reuses old, mutable bitmaps:</p><pre>options.inBitmap = reusableBitmap<br>options.inMutable = true</pre><p>This avoids:</p><ul><li>GC pressure</li><li>Lag during scrolling</li><li>Random jank that makes users hate you</li></ul><h3>But wait, there’s a catch…</h3><p>🧨 You <em>can’t</em> reuse just any bitmap. Rules:</p><ul><li>Bitmap must be <strong>mutable</strong></li><li>Must be <strong>same config</strong> (ARGB_8888, etc.)</li><li>Must be <strong>equal or larger</strong> than what you’re trying to decode</li></ul><h3>Glide uses an LruBitmapPool under the hood:</h3><ul><li><strong>Lru</strong> = Least Recently Used (evict oldest first)</li><li>Tracks total size in bytes</li><li>Evicts when full</li><li>Handles API version quirks (KitKat relaxed reuse rules)</li></ul><h3>🏗️ Build Your Own BitmapPool (DIY Glide 😎)</h3><p>Time to roll up your sleeves. Let’s build a <strong>custom bitmap pool</strong>.</p><h3>Step 1: Interface</h3><pre>interface BitmapPool {<br>    fun put(bitmap: Bitmap)<br>    fun get(width: Int, height: Int, config: Bitmap.Config): Bitmap?<br>    fun clearMemory()<br>}</pre><h3>Step 2: LRU Implementation</h3><pre>class LruBitmapPool(private val maxSize: Int) : BitmapPool {<br>    private val pool = LinkedList&lt;Bitmap&gt;()<br>    private var currentSize = 0<br><br>    override fun put(bitmap: Bitmap) {<br>        if (!bitmap.isMutable || bitmap.isRecycled) return<br><br>        val size = bitmap.byteCount<br>        if (size &gt; maxSize) {<br>            bitmap.recycle()<br>            return<br>        }<br><br>        pool.add(bitmap)<br>        currentSize += size<br>        trimToSize()<br>    }<br><br>    override fun get(width: Int, height: Int, config: Bitmap.Config): Bitmap? {<br>        val iterator = pool.iterator()<br>        while (iterator.hasNext()) {<br>            val candidate = iterator.next()<br>            if (canUse(candidate, width, height, config)) {<br>                iterator.remove()<br>                currentSize -= candidate.byteCount<br>                return candidate<br>            }<br>        }<br>        return null<br>    }<br><br>    private fun canUse(b: Bitmap, w: Int, h: Int, c: Bitmap.Config): Boolean {<br>        return b.width &gt;= w &amp;&amp; b.height &gt;= h &amp;&amp; b.config == c<br>    }<br><br>    private fun trimToSize() {<br>        while (currentSize &gt; maxSize &amp;&amp; pool.isNotEmpty()) {<br>            val removed = pool.removeFirst()<br>            currentSize -= removed.byteCount<br>            removed.recycle()<br>        }<br>    }<br><br>    override fun clearMemory() {<br>        for (b in pool) b.recycle()<br>        pool.clear()<br>        currentSize = 0<br>    }<br>}</pre><p>This is 90% of what Glide does — minus threading, logging, and multi-bucket logic.</p><h3>🕵️ Add Logging: Who’s Hoarding Memory?</h3><p>Track usage like a paranoid performance profiler:</p><pre>Log.d(&quot;BitmapPool&quot;, &quot;Pool size: ${currentSize} bytes&quot;)<br>Log.d(&quot;BitmapPool&quot;, &quot;Added bitmap: ${bitmap.width}x${bitmap.height}&quot;)<br>Log.d(&quot;BitmapPool&quot;, &quot;Reused bitmap: YES/NO&quot;)</pre><p>You’ll be surprised how often you <em>don’t</em> reuse anything.</p><h3>⚙️ Pro Mode: Lifecycle, Threading, Trimming</h3><ul><li>❗ Always call pool.clearMemory() or trim in onTrimMemory() or onLowMemory()</li><li>🔁 Make your pool thread-safe (synchronised or use ConcurrentLinkedQueue)</li><li>⚖️ Track size in bytes, not just bitmap count</li><li>👷 Pre-fill bitmaps during app idle state for faster loading (more in Part 3)</li></ul><h3>🧃 Summary</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*uV3vGUAIEdzSUeCEdOy3GQ.png" /></figure><h3>👀 Coming in Part 3:</h3><ul><li>Preloading strategies (like Glide’s prefill)</li><li>Disk caching vs memory caching</li><li>InputStream/Uri handling</li><li>Handling decode failures</li><li>Memory config tuning (RGB_565 vs ARGB_8888)</li><li>Real-world usage patterns in RecyclerView &amp; image-heavy apps</li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c87da925c9c6" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Bitmaps in Android — The Pixelated Trouble Maker (Part 1)]]></title>
            <link>https://medium.com/@palak1998agrawal/bitmaps-in-android-the-pixelated-trouble-maker-part-1-5e904945692a?source=rss-b34ad28da018------2</link>
            <guid isPermaLink="false">https://medium.com/p/5e904945692a</guid>
            <dc:creator><![CDATA[Palak Agrawal]]></dc:creator>
            <pubDate>Mon, 19 May 2025 16:49:26 GMT</pubDate>
            <atom:updated>2025-05-19T17:25:06.375Z</atom:updated>
            <content:encoded><![CDATA[<h3>📸 Part 1 | Bitmaps in Android — The Pixelated Trouble Maker</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ITV4Q3l6JDpoY1r2w7L7ZA.png" /></figure><p><strong>“Why does my app keep crashing when I load one image?”</strong><br> Ah yes, the age-old Android rite of passage — <strong>fighting with Bitmaps</strong>.</p><p>Welcome to Part 1 of this blog series where we go <strong>beyond Glide</strong> and get our hands dirty with what actually happens underneath all that smooth image loading magic.</p><p>Let’s start with the <strong>culprit of so many OutOfMemoryErrors: the Bitmap.</strong></p><h3>🤔 What’s a Bitmap, Really?</h3><p>Think of a Bitmap as a <strong>giant table of pixels</strong>, each holding color data (like RGBA). It’s basically Android saying:</p><blockquote><em>“You want this image on screen? Cool. Let me load every. single. pixel. into memory.”</em></blockquote><p>Even a regular JPEG image of your cat becomes a memory hog when converted to a Bitmap.</p><h4>Example:</h4><pre>val bitmap = BitmapFactory.decodeResource(resources, R.drawable.cute_cat)<br>imageView.setImageBitmap(bitmap)</pre><p>Looks innocent, right? WRONG.</p><p>That cat might be <strong>5MB as a file</strong>, but could take up <strong>50MB in RAM</strong> when decoded. Surprise!</p><h3>🧠 The Memory Horror Show</h3><p>Let’s do some pixel math:</p><p>📐 A 4000x3000 image in ARGB_8888 =<br> 4000 × 3000 × 4 bytes = <strong>~46MB</strong></p><p>Now imagine you load 5 such images into a RecyclerView.<br>Welcome to crash-land: ✈️💥 OutOfMemoryError.</p><h3>🩹 So What Does Android Give You?</h3><h3>1. Downsampling</h3><p>You don’t need full-size images 99% of the time.</p><pre>val options = BitmapFactory.Options().apply {<br>    inSampleSize = 4 // Load 1/4th width &amp; height → 1/16th memory<br>}<br>val bitmap = BitmapFactory.decodeFile(&quot;image.jpg&quot;, options)</pre><h3>2. inBitmap: Reuse or Die Trying</h3><p>Android lets you reuse old Bitmaps instead of allocating new ones:</p><pre>options.inBitmap = oldBitmap<br>options.inMutable = true</pre><p>⚠️ Caveat: Only works if the new image is <em>equal or smaller</em> and uses the <em>same config</em>. This is where bitmap pooling comes into play.</p><h3>🧪 Real-World Analogy</h3><blockquote><strong><em>Bitmaps are like pizza boxes.</em></strong><em><br> Once you’re done with the pizza, you can </em><strong><em>reuse the box</em></strong><em> for another one — </em>but only if it’s the same size and shape<em>.</em></blockquote><p>Glide? Glide has a <strong>pizza box warehouse</strong> (BitmapPool).<br> You? You probably throw the box away and regret it later.</p><h3>💡 So What Should You Be Doing?</h3><p>Before throwing your images at ImageViews like a caveman:</p><p>✅ Decode Bitmaps off the main thread.<br>✅ Downsample them to actual display size.<br>✅ Use inBitmap and pooling where possible.<br>✅ Avoid decodeResource() for huge images. <br>✅ Respect your device’s memory limits.</p><h3>🛠️ Code You Should Probably Copy</h3><pre>val options = BitmapFactory.Options().apply {<br>    inJustDecodeBounds = true<br>}<br>BitmapFactory.decodeFile(path, options) // First decode for bounds only<br><br>options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight)<br>options.inJustDecodeBounds = false<br>options.inMutable = true<br>options.inBitmap = findReusableBitmap()<br><br>val bitmap = BitmapFactory.decodeFile(path, options) // Actual decoding</pre><p><em>Don’t worry, we’ll write </em><em>calculateInSampleSize() together in the next part.</em></p><h3>🧵 Up Next: Glide’s Bitmap Pool Is Basically a Spa for Pixels</h3><p>In <a href="https://medium.com/@palak1998agrawal/part-2-how-glide-cheats-at-memory-management-and-you-can-too-c87da925c9c6"><strong>Part 2</strong></a>, we’ll:</p><ul><li>Peek into Glide’s LruBitmapPool</li><li>Build our own BitmapPool from scratch</li><li>Add logging to track who’s hoarding memory</li><li>Handle threading, eviction, and reuse smartly</li></ul><p>Ready to go from “why is my app crashing?” to “I built my own image pipeline”?<br><strong>Let’s go full bitmap hacker mode. 🧑‍💻</strong></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5e904945692a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Steering Through Change: Essential Tips for Managing a Large-Scale Technical Migration]]></title>
            <link>https://medium.com/@palak1998agrawal/steering-through-change-essential-tips-for-managing-a-large-scale-technical-migration-38a7d4fcfb30?source=rss-b34ad28da018------2</link>
            <guid isPermaLink="false">https://medium.com/p/38a7d4fcfb30</guid>
            <dc:creator><![CDATA[Palak Agrawal]]></dc:creator>
            <pubDate>Sun, 27 Apr 2025 13:46:18 GMT</pubDate>
            <atom:updated>2025-04-27T13:46:18.988Z</atom:updated>
            <content:encoded><![CDATA[<p>About six months ago, our team made the decision to transition from a React Native-based hybrid app to fully native development. This move was driven by several factors, with performance improvements and a better user experience being the top priorities — our React Native setup had started to feel noticeably sluggish.<br> Throughout this migration journey, we gathered some valuable lessons, and I’m excited to share those insights with you in this article.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/510/0*xnT5Bxg4s3ocR5Jw" /></figure><h3>Why Consider Migration?</h3><p>Migration is usually undertaken for the following reasons:</p><ul><li><strong>Performance Enhancement</strong>: Transitioning tech stacks can lead to significant performance gains.</li><li><strong>Developer Experience</strong>: Adopting better tools, languages, or frameworks can greatly boost developer productivity.</li><li><strong>Cost Optimization</strong>: Shifting from reliance on a single cloud provider to a hybrid solution tailored to optimize each service for its workload, or migrating workloads to services offering optimal pricing..</li><li><strong>Scalability and Security</strong>: Changes in compliance or security requirements may necessitate large migrations, which require careful planning due to tight deadlines.</li></ul><h3><strong>Do’s for a successful migration</strong></h3><h4>1. Plan of Action</h4><p>Large migrations can span anywhere from a few sprints to several years.<br>Having a clear and detailed vision before you start is critical. Your plan should include:</p><ul><li>Defined milestones</li><li>Estimated timelines</li><li>Resource allocation</li><li>Cost projections</li></ul><p>Good planning allows you to identify risks early and prepare contingency plans.</p><p>Expect failures — and plan for them from day one.</p><h4>2. Prioritize Documentation</h4><p>Once your plan is ready, <strong>document everything</strong> — even the smallest details.<br> A well-documented process ensures alignment across teams and avoids duplicated efforts.</p><p>Before starting, secure organizational approval to make sure everyone is on the same page.</p><p>⚡ <strong>Pro Tip:</strong> Treat documentation as a living document. Update it regularly as the migration evolves.</p><h4>3. Communication is Key</h4><p>The longer and more complex the migration, the louder your communication should be.<br> Communicate clearly and frequently with all stakeholders, tailoring the depth of information based on their involvement level.</p><ul><li>Never work in complete silos.</li><li>Regular updates prevent surprises and keep everyone aligned.</li></ul><p>Open communication channels for feedback — they’re invaluable.</p><h4>4. Test, Test, and Test Again</h4><p>Testing is critical to ensuring a smooth migration.<br> Before moving anything over, build comprehensive test suites to validate correctness at every phase.</p><p>For example, in a frontend tech stack migration:</p><ul><li>Define the migration scope clearly.</li><li>Plan necessary enhancements and rollout strategies.</li><li>Ensure you have unit, integration, and end-to-end tests covering all key workflows.</li></ul><p>Rigorous testing at every step minimizes the chance of major surprises later.</p><h4>5. Plan for Fallback and Rollback</h4><p>Fallback and rollback strategies must be baked into your migration plan.<br> Be prepared to revert changes if things don’t go as expected. Taking your systems completely offline is often not an option, so seamless fallback mechanisms are crucial.</p><ul><li>Test rollback strategies in a staging environment.</li><li>Maintain backups and use version control (e.g., Git) for safe change management.</li></ul><p>Rolling back gracefully can be a lifesaver during high-pressure moments.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/600/0*Hp4uHuHp7sabc1Yw.jpg" /></figure><p><strong>Example of a Frontend Tech Stack Migration:</strong></p><p><strong>1. Plan of Action:</strong></p><ul><li><strong>Define the scope</strong>: Is phase roll out possible ?<br>Migrate of what feature will be covered in which phase.</li><li><strong>Milestones:</strong><br>Setup (1 sprints)<br>Migrate core features (3 sprints)<br>Initial testing (2 sprints)<br>Initial rollout to internal users (4 sprints)<br>Full deployment (8 sprints)</li><li><strong>Timelines:</strong> Estimated 6 months for full migration.(Define complete plan)</li><li><strong>Resources: </strong><br>5 developers, 1 project lead, 2 QA testers</li><li><strong>Risks: </strong>Compatibility issues, team learning curve, potential downtime.</li></ul><p><strong>2. Documentation:</strong></p><ul><li>Create a detailed migration plan.</li><li>Document each step: setup, coding standards, Product requirements, design requirements, Backend Contract, Analytics requirements, component migration, testing procedures.</li><li>Secure approval from stakeholders.</li><li>Continuously update the document with progress and changes.</li></ul><p><strong>3. Communication:</strong></p><ul><li>Establish a communication plan.</li><li>Weekly updates to the development team.</li><li>Bi-weekly progress reports to management.</li><li>Monthly high-level summaries to executives.</li><li>Ensure open channels for feedback and queries.</li></ul><p><strong>4. Test:</strong></p><ul><li>Develop unit tests.</li><li>Do integration testing to ensure migration working correctly with existing services.</li><li>Do end-to-end testing to simulate user interactions.</li><li>Validate each migration phase with comprehensive testing.</li></ul><p><strong>5. Fallback and Rollback:</strong></p><ul><li>Prepare a rollback strategy to revert to if critical issues occur.</li><li>Maintain backups of all codebases.</li><li>Use version control (e.g., Git) to manage changes and revert if needed.</li><li>Test the rollback process in a staging environment.</li></ul><h3>Conclusion</h3><p>Migration is not just a technical decision — it’s a strategic one.<br> Success lies in meticulous planning, continuous documentation, clear communication, rigorous testing, and having a robust rollback strategy.<br> No migration is perfect, but with the right approach, it can become a seamless evolution instead of a disruption.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=38a7d4fcfb30" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>