<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Daksh Goel</title>
    <description>The latest articles on DEV Community by Daksh Goel (@ugbeast).</description>
    <link>https://dev.to/ugbeast</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3092055%2Fec644ba1-68b7-4978-b9dc-9c11ee3dfeb9.jpg</url>
      <title>DEV Community: Daksh Goel</title>
      <link>https://dev.to/ugbeast</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/ugbeast"/>
    <language>en</language>
    <item>
      <title>Why contiguous Data Structures (DS) are faster than non-contiguous DS</title>
      <dc:creator>Daksh Goel</dc:creator>
      <pubDate>Sun, 20 Sep 2026 09:25:18 +0000</pubDate>
      <link>https://dev.to/ugbeast/why-contiguous-data-structures-ds-are-faster-than-non-contiguous-ds-3od0</link>
      <guid>https://dev.to/ugbeast/why-contiguous-data-structures-ds-are-faster-than-non-contiguous-ds-3od0</guid>
      <description>&lt;h1&gt;
  
  
  Summary:
&lt;/h1&gt;

&lt;p&gt;The massive performance gap between contiguous DS and node-base structures is due to CPU Cache lines and spatial locality.&lt;/p&gt;

&lt;h1&gt;
  
  
  Deep Dive:
&lt;/h1&gt;

&lt;h3&gt;
  
  
  RAM Bottleneck:
&lt;/h3&gt;

&lt;p&gt;CPU is very fast, but RAM is slow. To prevent CPU from idling, CPU is fitted with CPU Caches (L1, L2, L3).&lt;/p&gt;

&lt;p&gt;This includes 2 major things:&lt;/p&gt;

&lt;p&gt;Spatial Locality: States that, if a program accesses a specific memory address, it will almost certainly need the data at the immediately adjacent address very soon.&lt;/p&gt;

&lt;p&gt;Cache Lines: Because of spatial locality, CPU grabs a fixed-size block of contiguous memory all at once. Generally it's 64 bytes long contiguous block in modern machines.&lt;/p&gt;

&lt;h3&gt;
  
  
  Contiguous Memory DS (eg. Arrays):
&lt;/h3&gt;

&lt;p&gt;Perfect spatial locality.&lt;/p&gt;

&lt;p&gt;When you read the first item (say, 4-byte integer) in an array, the CPU fetches a 64-byte cache line from RAM. This brings first integer + the next 15 integer immediately. When the loop moves to the 2nd, 3rd, ..... items, the CPU doesn't have to wait for RAM; the data is already present in the L1-cache (a cache hit). You only suffer a slow RAM fetch once every 16 steps.&lt;/p&gt;

&lt;h3&gt;
  
  
  Non-contiguous Memory DS (eg. Linked List):
&lt;/h3&gt;

&lt;p&gt;Linked List nodes are dynamically allocated, meaning they are scattered randomly across the heap wherever there happens to be free space.&lt;/p&gt;

&lt;p&gt;When you ask for the first node, the CPU fetches a 64-byte cache line from RAM. However, because the next node is stored at a completely different, random memory address, the rest of that cache line is filled with unrelated data.&lt;/p&gt;

&lt;p&gt;When we follow pointer to 2nd node, the CPU discovers it isn't in the cache (a cache miss). It has to make a slow trip to RAM again. We have to pay the massive latency penalty on almost every step, making linked list traversal slower regardless of theoretical speed.&lt;/p&gt;

</description>
      <category>algorithms</category>
      <category>computerscience</category>
      <category>performance</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
