<?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: Karen Barseghyan</title>
    <description>The latest articles on DEV Community by Karen Barseghyan (@karen_barseghyan_8df21c6d).</description>
    <link>https://dev.to/karen_barseghyan_8df21c6d</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%2F4036959%2F5c5eda7c-1634-4366-a26a-f6b04b9ba46f.jpeg</url>
      <title>DEV Community: Karen Barseghyan</title>
      <link>https://dev.to/karen_barseghyan_8df21c6d</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/karen_barseghyan_8df21c6d"/>
    <language>en</language>
    <item>
      <title>Columnar Data Structure in Java</title>
      <dc:creator>Karen Barseghyan</dc:creator>
      <pubDate>Mon, 31 Aug 2026 19:52:12 +0000</pubDate>
      <link>https://dev.to/j-util/columnar-data-structure-in-java-3o20</link>
      <guid>https://dev.to/j-util/columnar-data-structure-in-java-3o20</guid>
      <description>&lt;p&gt;What if we need traditional object-oriented API and extra high performance for field-wise operations in one place?&lt;/p&gt;

&lt;p&gt;I designed my &lt;a href="https://github.com/j-util/columnar-projection-store" rel="noopener noreferrer"&gt;CPS&lt;/a&gt; exactly having this in mind. The article is for describing the idea behind the library.&lt;/p&gt;

&lt;p&gt;Imagine you have 10 million &lt;code&gt;product&lt;/code&gt; objects, which have the following structure:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;Product&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;quantity&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;price&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You need to calculate the grand total value by summing &lt;code&gt;quantity * price&lt;/code&gt; for every product. You would create an &lt;code&gt;ArrayList&amp;lt;Product&amp;gt;&lt;/code&gt;, iterate on them one way or another and calculate the sum. And you would be right. Or you need the product with max quantity or lowest price.&lt;/p&gt;

&lt;p&gt;Now imagine you are the CPU doing those operations. You would pick the object references from the backing &lt;code&gt;array&lt;/code&gt;, go through them one by one, capture field values and then do the computation. In the best case you will cache more of those references. But you still need to chase them to get the data inside. This is called &lt;em&gt;&lt;strong&gt;pointer chasing&lt;/strong&gt;&lt;/em&gt;: following object references to reach data stored at other memory locations. It is because Java arrays do not store object data inline. Object arrays store references, while primitive arrays store primitive values directly.&lt;/p&gt;

&lt;p&gt;Now imagine you have this class:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ProductColumnarStore&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="nc"&gt;String&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;names&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;quantities&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt;&lt;span class="o"&gt;[]&lt;/span&gt; &lt;span class="n"&gt;prices&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="n"&gt;offset&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Each offset position represents one logical &lt;code&gt;Product&lt;/code&gt;. Now your data is a good candidate for efficient CPU cache utilization during sequential access. And for primitive columns, no pointer chasing in the loop. Just loading new chunks of data from the arrays inside &lt;code&gt;productColumnarStore&lt;/code&gt;. You have a &lt;code&gt;contiguous&lt;/code&gt; data layout, which is especially good for sequential field-wise operations and &lt;code&gt;SIMD&lt;/code&gt; instructions.&lt;/p&gt;

&lt;p&gt;Why would you choose this way? It is not convenient to create this structure every time you need. You need to fill it first, then you need to handle bookkeeping of the offset during the iteration and you will not have the &lt;code&gt;product&lt;/code&gt; object.&lt;/p&gt;

&lt;p&gt;This is where &lt;a href="https://github.com/j-util/columnar-projection-store" rel="noopener noreferrer"&gt;CPS&lt;/a&gt; helps you. You design a &lt;code&gt;projection&lt;/code&gt; based on your class, it is doing the heavy lifting.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight java"&gt;&lt;code&gt;&lt;span class="kd"&gt;interface&lt;/span&gt; &lt;span class="nc"&gt;ProductProjection&lt;/span&gt; &lt;span class="o"&gt;{&lt;/span&gt;
&lt;span class="nc"&gt;String&lt;/span&gt; &lt;span class="nf"&gt;name&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;quantity&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="kt"&gt;int&lt;/span&gt; &lt;span class="nf"&gt;price&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt;
&lt;span class="o"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Later I will show &lt;strong&gt;how&lt;/strong&gt; and &lt;strong&gt;when&lt;/strong&gt; to use this library.&lt;/p&gt;

</description>
      <category>java</category>
      <category>datastructures</category>
      <category>lowlatency</category>
      <category>simd</category>
    </item>
  </channel>
</rss>
