<?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>Forem: Bhuban Padun(Senior Software Developer)</title>
    <description>The latest articles on Forem by Bhuban Padun(Senior Software Developer) (@oter_padun_eb662bf882af9e).</description>
    <link>https://forem.com/oter_padun_eb662bf882af9e</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.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3829309%2Fc6b1575b-81cc-4135-a3cd-51b3cb479222.jpg</url>
      <title>Forem: Bhuban Padun(Senior Software Developer)</title>
      <link>https://forem.com/oter_padun_eb662bf882af9e</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/oter_padun_eb662bf882af9e"/>
    <language>en</language>
    <item>
      <title>React WebWorker.</title>
      <dc:creator>Bhuban Padun(Senior Software Developer)</dc:creator>
      <pubDate>Tue, 17 Mar 2026 11:35:40 +0000</pubDate>
      <link>https://forem.com/oter_padun_eb662bf882af9e/webworker-2di0</link>
      <guid>https://forem.com/oter_padun_eb662bf882af9e/webworker-2di0</guid>
      <description>&lt;p&gt;&lt;strong&gt;Optimizing Bulk Excel-like Table Updates Using Web Workers&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Recently, I worked on improving the performance of a feature where users update large Excel-like table data (thousands of rows). Handling everything on the main thread was causing noticeable UI lag and freezing issues 😓&lt;/p&gt;

&lt;p&gt;To solve this, I used &lt;strong&gt;Web Workers&lt;/strong&gt; — and the results were a game changer.&lt;/p&gt;

&lt;p&gt;Instead of processing heavy data updates on the main thread, I moved the logic into a Web Worker. This allowed the UI to stay smooth and responsive while the data processing happened in the background.&lt;/p&gt;

&lt;p&gt;What I did:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Offloaded bulk row updates and transformations to a Web Worker&lt;/li&gt;
&lt;li&gt;Used &lt;code&gt;postMessage&lt;/code&gt; to send data between the main thread and worker&lt;/li&gt;
&lt;li&gt;Processed large datasets (filtering, mapping, calculations) inside the worker&lt;/li&gt;
&lt;li&gt;Sent back only the final processed result to update the UI&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;⚡ Result:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;No more UI freezing&lt;/li&gt;
&lt;li&gt;Smooth scrolling and interactions even with large datasets&lt;/li&gt;
&lt;li&gt;Better user experience overall&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;When to use Web Workers?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Large data processing (Excel-like tables, reports)&lt;/li&gt;
&lt;li&gt;Heavy computations&lt;/li&gt;
&lt;li&gt;Parsing big JSON responses&lt;/li&gt;
&lt;li&gt;Background tasks that shouldn’t block UI&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Web Workers are super underrated when it comes to frontend performance optimization. If you're dealing with heavy data operations, they are definitely worth trying!&lt;/p&gt;

&lt;p&gt;How Web Workers Work&lt;br&gt;
Normally, JavaScript runs on a single main thread (UI thread).&lt;br&gt;
So when you do heavy work (like updating thousands of rows), the UI gets blocked 😓&lt;br&gt;
👉 Web Workers solve this by running code in a separate background thread&lt;br&gt;
Flow:&lt;br&gt;
-&amp;gt; Main thread creates a worker&lt;br&gt;
-&amp;gt; Main thread sends data → worker.postMessage(data)&lt;br&gt;
-&amp;gt; Worker processes heavy task&lt;br&gt;
-&amp;gt; Worker sends result back → postMessage(result)&lt;br&gt;
-&amp;gt; Main thread updates UI&lt;br&gt;
-&amp;gt; So your UI stays smooth while heavy work runs in parallel &lt;br&gt;
Main Thread (UI)&lt;br&gt;
   ↓ send data&lt;br&gt;
Web Worker (Background Processing)&lt;br&gt;
   ↓ return result&lt;br&gt;
Main Thread (Update UI)&lt;/p&gt;

&lt;p&gt;Simple Implementation Demo&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create Worker File (worker.js)
// worker.js
self.onmessage = function (e) {
const data = e.data;
// Simulate heavy processing (Excel-like updates)
const updatedData = data.map((row) =&amp;gt; {
return {
  ...row,
  total: row.price * row.quantity,
};
});&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;// Send result back to main thread&lt;br&gt;
  self.postMessage(updatedData);&lt;br&gt;
};&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Use Worker in Your App
// main.js (or React component)
this should be initial component mounting state&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;const worker = new Worker(new URL('./worker.js', import.meta.url));&lt;/p&gt;

&lt;p&gt;const tableData = [&lt;br&gt;
  { id: 1, price: 100, quantity: 2 },&lt;br&gt;
  { id: 2, price: 200, quantity: 3 },&lt;br&gt;
  // imagine 10,000+ rows&lt;br&gt;
];&lt;/p&gt;

&lt;p&gt;// Send data to worker&lt;br&gt;
worker.postMessage(tableData);&lt;/p&gt;

&lt;p&gt;// Receive processed data&lt;br&gt;
worker.onmessage = function (e) {&lt;br&gt;
  const result = e.data;&lt;br&gt;
  console.log("Updated Data:", result);&lt;br&gt;
};&lt;/p&gt;

&lt;p&gt;React Example (Simple)&lt;br&gt;
import { useEffect, useState } from "react";&lt;/p&gt;

&lt;p&gt;function App() {&lt;br&gt;
  const [data, setData] = useState([]);&lt;/p&gt;

&lt;p&gt;useEffect(() =&amp;gt; {&lt;br&gt;
    const worker = new Worker(new URL("./worker.js",   import.meta.url));&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const bigData = Array.from({ length: 5000 }, (_, i) =&amp;gt; ({
  id: i,
  price: Math.random() * 100,
  quantity: Math.random() * 5,
}));

worker.postMessage(bigData);

worker.onmessage = (e) =&amp;gt; {
  setData(e.data);
};

return () =&amp;gt; worker.terminate();
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}, []);&lt;/p&gt;


&lt;p&gt;return &lt;/p&gt;Rows processed: {data.length};&lt;br&gt;&lt;br&gt;
}

&lt;h1&gt;
  
  
  WebPerformance #JavaScript #WebWorkers #Frontend #Optimization #React
&lt;/h1&gt;

</description>
      <category>frontend</category>
      <category>javascript</category>
      <category>performance</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
