<?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 Faiz Halde on Medium]]></title>
        <description><![CDATA[Stories by Faiz Halde on Medium]]></description>
        <link>https://medium.com/@haldefaiz?source=rss-775c6e3d8e05------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*7GYcrEvVqdUZbP8eTskoeQ.jpeg</url>
            <title>Stories by Faiz Halde on Medium</title>
            <link>https://medium.com/@haldefaiz?source=rss-775c6e3d8e05------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 20 Nov 2026 10:46:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@haldefaiz/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[Apps — Ever had dreams of grouping your browser tabs?]]></title>
            <link>https://medium.com/@haldefaiz/apps-ever-had-dreams-of-grouping-your-browser-tabs-a139106d82c8?source=rss-775c6e3d8e05------2</link>
            <guid isPermaLink="false">https://medium.com/p/a139106d82c8</guid>
            <category><![CDATA[productivity]]></category>
            <category><![CDATA[chrome-extension]]></category>
            <dc:creator><![CDATA[Faiz Halde]]></dc:creator>
            <pubDate>Wed, 21 Jun 2017 18:47:34 GMT</pubDate>
            <atom:updated>2017-06-21T18:52:47.181Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*GOhKhtuFsnq_LQWLLfoXXw.jpeg" /></figure><p>Once again I’m back with another chrome extension. With 80 tabs scattered across 5 windows, I happen to be spending my 20s searching for tabs here and there. I surely don’t have time for all that and neither do you, so how about I save you some hours and in return you just give me some <strong>m&amp;m’s</strong> ??</p><blockquote><a href="https://github.com/fhalde/jumble"><strong><em>Jumble</em></strong></a></blockquote><p>As usual, plug the plugin and press the icon!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a139106d82c8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Parallelism — What do you know about caching?]]></title>
            <link>https://medium.com/@haldefaiz/what-do-you-know-about-caching-4de6dc9209bf?source=rss-775c6e3d8e05------2</link>
            <guid isPermaLink="false">https://medium.com/p/4de6dc9209bf</guid>
            <category><![CDATA[parallel-computing]]></category>
            <category><![CDATA[threads]]></category>
            <category><![CDATA[programming]]></category>
            <category><![CDATA[concurrency]]></category>
            <dc:creator><![CDATA[Faiz Halde]]></dc:creator>
            <pubDate>Wed, 21 Jun 2017 18:30:40 GMT</pubDate>
            <atom:updated>2017-06-21T18:48:32.915Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/209/1*GZ5d61DpOE8bTHrlknSosA.jpeg" /></figure><p>In my quest to understand what the heck volatile keyword in C was all about, I ended up learning cache coherence. I did learn it in college, but who the hell remembers it anyway. You might be wondering, what? Wait for it, you&#39;ll get the gist of it.</p><p>CPU’s have evolved much faster than storage. From slowest to fastest order, it is disk, main memory, cache (L3-L2-L1 etc) and registers. They form the foundation of today&#39;s fast CPU architecture. These storage are usually kept in a hierarchy from fastest being closest to the CPU and so on. Registers and section of the cache called L1 and L2 cache are private to each core, others are simply shared.</p><p>One thing to point out is that caching into the various level of caches is not under our control, however registers are and compilers make great use of them if you hint/tell them to optimize your code.</p><p>Now why volatile keyword is important? Time to experiment.</p><p>Let’s say we have a global variable counter shared between two threads and initialized to zero. One thread loops until the counter<strong> </strong>value is changed to 1 by another thread. In a non-optimized world (that is no registers), this will work fine given the scheduler schedules both the threads. However in an optimized world (gcc -O3)<strong>, </strong>the following program never terminates. Try it yourself if you have trust issues. Here is my code:</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/337ea1173be69899684ce255b08892da/href">https://medium.com/media/337ea1173be69899684ce255b08892da/href</a></iframe><p>Why is it so? Because each core has its own set of registers, and since the compiler has decided that the variable should reside on the register (read/write happens only from/to the registers, no main memory), each thread is working with a different set of registers. So if thread bar<strong> </strong>does update the counter, thread foo won&#39;t be able to see it because their registers are not synced (and it&#39;ll never get synced because registers never get synced - context switching saves the CPU registers in the PCB and loads from PCB back to the CPU registers). The solution?</p><p>Volatile! The volatile keyword tells the compiler &quot;dude, stop being so aggressive about your optimizations. Store the damn variable into the main memory&quot;. This way each thread reads/writes a variable directly from/to the memory (or cache) and updates are reflected everywhere.</p><p>Ok great. What about the L1 and L2 cache which are private to each core? Well, cache is a completely different story. It has something called Cache coherence. The topic of this blog which I shamelessly drifted away from.</p><blockquote><strong><em>Cache coherence</em></strong><em> is the consistency of shared data that ends up stored in multiple local/private </em><strong><em>caches — </em></strong><em>WIKI</em></blockquote><p>Now you know the reason why registers don’t work for the above case. There is no means of being consistent when updates are happening across cores. Cache architectures implement the consistency model in them and that&#39;s why as a programmer you don&#39;t have to worry about your variables getting changed and stored across multiple local caches. There are several protocols to sync caches, the most widely used protocol however is the MESI protocol.</p><p>In order to understand my experiment, you should know how the CPU and Cache works. This is a really really high level explanation, so google if you want to know more</p><ul><li>The Cache consists of several cache lines.</li><li>Each cache line is typically 64 bytes (size increases from L1 to L2 to L3). So even if you just wanted a single variable from the memory, the cache will cache its vicinity memory along with it.</li><li>The CPU requests for a memory address</li><li>The Cache controller checks if this memory address is cached.</li><li>If it is, then return it, otherwise do a memory transaction</li><li>If the CPU writes to a variable, it gets stored in the cache and into the main memory depending on whether the cache uses a write-back or write-through policy. This update in turn invalidates entries in other cores local cache (if they have cached it).</li></ul><p>Now the 2nd last point. There are two reasons why a memory transaction can happen.</p><ul><li>The memory address requested for isn’t cached.</li><li>The memory is in the cache but is invalidated since some other core updated the same chunk of memory.</li></ul><p>The last point is crucial here and the reason for my experiment.</p><p>Let’s say you have two variables x<strong> </strong>and y. Likely to be in each other&#39;s vicinity in the memory. When your program requests for say variable x, the cache controller rather than just caching the variable x, will cache up memory chunk around it inside the same cache line. Now if the CPU requests for variable y, it gets it from the cache directly.</p><blockquote><em>Bookkeeping of every byte by the cache controller is very expensive. Also making the cache line too huge eats up bandwidth, since more bytes now need to be requested from the main memory. So the designers chose </em><strong><em>64 bytes</em></strong><em> for a single cache line for L1 cache.</em></blockquote><p>Now this is something a programmer must be aware of while writing multi-threaded programs. Why? Here’s why!</p><p>Let’s say we have two threads, foo and bar. foo<strong> </strong>is working with variable x<strong> </strong>and bar<strong> </strong>is working with variable y<strong>, </strong>both are working aggressively with the variables. If both the variables are in close vicinity, the cache controller of each core picks them up both and caches them.</p><p>Now I claim that such a program is not utilizing parallelism at all! Let&#39;s see why</p><ul><li>foo updates variable x.</li><li>Upon updating its cache, it invalidates the same cache line of other cores.</li><li>bar at the same time wanted to update y, the cache controller sees the cache line is invalidated, so either a memory transaction happens or the CPU waits until coherence hits in for the caches to sync!</li></ul><p>If this goes on and on, performance is likely to be screwed.</p><p>To justify my claim, here is the source code of my experiment. Notice that we are updating two very close memory addresses</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/aca0a0d1ee872fd4314ce7fae9d2207c/href">https://medium.com/media/aca0a0d1ee872fd4314ce7fae9d2207c/href</a></iframe><p>Upon running the above code, it finished within 1.4 seconds at average.</p><p>Here is the variation of the code where parallelism was fully achieved. Notice each thread is updating its local stack variable <strong>i </strong>and then assigning it to the final variable</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2f691720185fc1bb5394b5f94b767b44/href">https://medium.com/media/2f691720185fc1bb5394b5f94b767b44/href</a></iframe><p>Unsurprisingly, the above code on average ran for 0.3 seconds<strong> </strong>Do I even have to tell you how much 1.1 seconds<strong> </strong>of difference means to a computer.</p><p>Now, why should a programmer care about all this?</p><p>During my college time, we wrote threaded applications which worked on large arrays. The most crucial thing usually was on what segments should each thread work on. We usually agreed that even indexed slots will be worked on by thread 1, odd indexed slots will be worked by thread 2. If you are updating the array in place, you fallback to the same case as above (not achieving parallelism). If you do the updates on thread local variables and together in the end update the shared array, you may gain a little performance, but this is use case specific. The best way was to split the array into two half<strong>. </strong>Hardly any scope of cache invalidation due to simultaneous updates, except maybe on the region where the split happened!</p><p>That’s undoubtedly the biggest blog I’ve ever written, and my brain is cached with all these jargons. Time to invalidate me. However, this is definitely the biggest takeaway in my quest to learn parallel programming!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4de6dc9209bf" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Apps — Where is that screamer]]></title>
            <link>https://medium.com/@haldefaiz/apps-where-is-that-screamer-273120982000?source=rss-775c6e3d8e05------2</link>
            <guid isPermaLink="false">https://medium.com/p/273120982000</guid>
            <category><![CDATA[plugins]]></category>
            <category><![CDATA[chrome-extension]]></category>
            <category><![CDATA[productivity]]></category>
            <dc:creator><![CDATA[Faiz Halde]]></dc:creator>
            <pubDate>Wed, 21 Jun 2017 18:19:46 GMT</pubDate>
            <atom:updated>2017-06-21T18:20:21.425Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/549/1*nqjlCTAjMGCbDfT9JeZm7A.gif" /></figure><p>I love keeping my browser tabs open. My god if they get closed, there’s no purpose in my life. But quite often, thanks to ads/auto-play, tabs starts screaming. Screams music. Screams junk. Shut up you tab!</p><p>So, meet <a href="https://github.com/fhalde/goto-audio"><strong>goto-audio</strong></a>. Just plug the plugin, click the audio icon and that screamer is yours!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=273120982000" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scalability — Fiddling with MySQL]]></title>
            <link>https://medium.com/@haldefaiz/fiddling-with-mysql-c2b93b79926d?source=rss-775c6e3d8e05------2</link>
            <guid isPermaLink="false">https://medium.com/p/c2b93b79926d</guid>
            <category><![CDATA[scalability]]></category>
            <category><![CDATA[mysql]]></category>
            <category><![CDATA[design]]></category>
            <dc:creator><![CDATA[Faiz Halde]]></dc:creator>
            <pubDate>Tue, 13 Jun 2017 11:43:11 GMT</pubDate>
            <atom:updated>2017-06-15T22:32:54.907Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/738/1*lqh4oGTugw8VEnNuAKG79Q.jpeg" /></figure><p>MySQL needs no introduction. So I’ll go straight to the point where the idea of fiddling with MySQL popped in me.</p><p>Every morning when I meet my team, we don’t start working directly. Thank god to humanity, there are casual talks happening. They end up in technical talks, though.</p><p>One such talk involved our database design. Oh look a <strong>primary key</strong> to reduce lookup time. Ahh varchar, so space efficient. By no means I’m planning on talking about primary keys. But varchar? Interesting.</p><p>You all know varchar datatype allocates only the required disk space based on the column content, in contrast to char data type where the fixed size — provided during the creation of table — is allocated no matter the size of the content you are trying to insert/update.</p><p>So I questioned myself. What if I later try to update the varchar column to some large content (less than the max size of the column). Since MySQL only allocated as much as disk size necessary previously, it surely can’t fit in the extra characters. Either the record is copied to a new place completely or the varchar points to some new location in the disk having the desired disk space. More reads more seeks. Nevertheless, the filesystem is upset because his personal space is getting occupied.</p><p>To actually test the truthiness of my claim, I prepared a dummy database with two tables. varchar_tb and char_tb having a name column of size 255 with bajillion records inserted in it. 400k roughly. Each entry had a constant string of 128 characters. To verify if varchar actually occupied as much as space required, I checked the sizes of the two tables and varchar_tb was roughly half the size of char_tb.</p><p>Now the part where I get the answers to my questions! I updated each row with a constant string of 255 characters. It was not a surprise to see that the update on char_tb was 5 seconds faster than the update on varchar_tb. The time difference is definitely expected to increase if there are more records in the table.</p><blockquote>The point made is, <strong>do not take the obvious path always</strong>.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c2b93b79926d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Apps — Annoying mouse pads]]></title>
            <link>https://medium.com/@haldefaiz/annoying-mouse-pads-31760f1f4f45?source=rss-775c6e3d8e05------2</link>
            <guid isPermaLink="false">https://medium.com/p/31760f1f4f45</guid>
            <category><![CDATA[chrome-extension]]></category>
            <category><![CDATA[plugins]]></category>
            <category><![CDATA[accessibility]]></category>
            <category><![CDATA[chrome]]></category>
            <dc:creator><![CDATA[Faiz Halde]]></dc:creator>
            <pubDate>Tue, 13 Jun 2017 11:33:44 GMT</pubDate>
            <atom:updated>2017-06-21T18:49:33.094Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZGbbPYvGJCJp_ricvBywwg.jpeg" /></figure><p>Ever went on to type something in a website just to realize the focus over the input was gone? And whatever you typed was lost? No problem amigo, I’ve got a hack.</p><p><a href="https://github.com/fhalde/happy-typing"><strong>Happy-typing</strong></a></p><p>Plug the plugin and that’s it.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=31760f1f4f45" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Scalability — Scaling beyond clusters]]></title>
            <link>https://medium.com/@haldefaiz/scaling-beyond-clusters-82ab100dade?source=rss-775c6e3d8e05------2</link>
            <guid isPermaLink="false">https://medium.com/p/82ab100dade</guid>
            <category><![CDATA[scalability]]></category>
            <category><![CDATA[linux]]></category>
            <category><![CDATA[operating-systems]]></category>
            <category><![CDATA[performance]]></category>
            <category><![CDATA[distributed-systems]]></category>
            <dc:creator><![CDATA[Faiz Halde]]></dc:creator>
            <pubDate>Tue, 13 Jun 2017 11:30:56 GMT</pubDate>
            <atom:updated>2017-06-15T08:03:54.173Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*PnURrMMubdomOp1kNRUs5w.jpeg" /></figure><p>When every nanosecond matters while you have a budget to satisfy, you need to work with what you’ve got.</p><blockquote><a href="http://epickrram.blogspot.co.uk/2015/09/reducing-system-jitter.html"><strong><em>Scaling beyond clusters. Machine level</em></strong></a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=82ab100dade" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[First pull request]]></title>
            <link>https://medium.com/@haldefaiz/first-pull-request-7169e1ab6be4?source=rss-775c6e3d8e05------2</link>
            <guid isPermaLink="false">https://medium.com/p/7169e1ab6be4</guid>
            <category><![CDATA[first-job]]></category>
            <category><![CDATA[software-development]]></category>
            <dc:creator><![CDATA[Faiz Halde]]></dc:creator>
            <pubDate>Tue, 13 Jun 2017 07:59:25 GMT</pubDate>
            <atom:updated>2017-06-13T11:43:48.830Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*IZfJtztOxNM6dy2-oF2rVA.png" /></figure><p>Every day I wake up, dress neat to impress my beloved cubicle. Monitors joined together depicting a hacking scenario around me. But tell me what I have done? Silence follows.</p><p>I’ve spent two months just browsing through the emails that kept popping up like the popcorn from those kettle machines. Written a line of code? Not even close. So yeah I get paid every month and life’s great. But soon you realize pay is not the only thing that matters. You want to get paid for your contributions. Have I contributed? Nope.</p><p>So I go ask my scrum master to assign me some work. She looks up at the pending works and gives me one. The simplest of all. I say to myself,</p><blockquote><strong><em>Seriously?</em></strong></blockquote><p>Anyways I appreciate what’s been given to me and I start working on it. To a guy who has worked extensively on various aspects of programming, a simple database query should not be a problem, right? How about I say it took me 2 days to finish off the work.</p><p>It was not that I couldn’t formulate an SQL query or something, but the guidelines one needs to follow in a collaborative environment, make use of best practices and cooperating with the established code standards of the company that affected my productivity. The worst course of my college days, Software Engineering finally makes sense to me.</p><p>It’s all done. My code is running locally, that heavenly feel. But the code needs to be deployed for it to matter. I was quite paranoid when I was pushing my code for deployment. What if it fails? What if I haven’t tested it thoroughly? Corner cases? Clean code? But I push it. Next thing I get is a mail from the code reviewer telling me to do so and so changes. I panic. Another half day refactoring it. Once again I raise a pull request. Curious to know if it was accepted, I quickly go to my team’s main repo, and there it was. All merged. In the sheer excitement of it, I send a mail to my manager about my contribution. And the next thing I know is I’m recognized. It’s a proud moment trust me.</p><p>Finally, I’ll be paid for about 10 lines of code contribution.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7169e1ab6be4" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>