<?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: Христо Тодоров</title>
    <description>The latest articles on DEV Community by Христо Тодоров (@__4b46469ccc).</description>
    <link>https://dev.to/__4b46469ccc</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%2F3963360%2F5c6c6e7f-a3a7-4f66-a784-f33e3a8dcbdc.png</url>
      <title>DEV Community: Христо Тодоров</title>
      <link>https://dev.to/__4b46469ccc</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/__4b46469ccc"/>
    <language>en</language>
    <item>
      <title>Where does your startup time actually go?</title>
      <dc:creator>Христо Тодоров</dc:creator>
      <pubDate>Mon, 01 Jun 2026 20:46:19 +0000</pubDate>
      <link>https://dev.to/__4b46469ccc/where-does-your-startup-time-actually-go-1m21</link>
      <guid>https://dev.to/__4b46469ccc/where-does-your-startup-time-actually-go-1m21</guid>
      <description>&lt;p&gt;&lt;em&gt;A visual look at why &lt;code&gt;index.ts&lt;/code&gt; re-export files are slow — with real flame graphs.&lt;/em&gt;&lt;/p&gt;




&lt;p&gt;You've written this file. Everyone has:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// icons/index.ts&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./Activity&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./Airplay&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./Anchor&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="c1"&gt;// ...and 12 more&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's the &lt;strong&gt;barrel file&lt;/strong&gt;. One tidy entry point so consumers can write the clean version:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Activity&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./icons&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;instead of the noisy version:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Activity&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./icons/Activity&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Looks harmless. It is not. That one import just loaded &lt;strong&gt;every module in the folder&lt;/strong&gt; — and I can show you, frame by frame.&lt;/p&gt;




&lt;h2&gt;
  
  
  The setup
&lt;/h2&gt;

&lt;p&gt;A folder of 15 icon modules, each importing a small shared &lt;code&gt;base&lt;/code&gt; and doing a little work at load (parse, set up, register — the stuff every real module does):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;icons/
  base.js
  Activity.js   Airplay.js   Anchor.js   ...   Briefcase.js   (15 of them)
  index.js      ← the barrel: re-exports all 15
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Two ways to grab a single icon:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// barrel/main.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Activity&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./icons/index.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;      &lt;span class="c1"&gt;// through the barrel&lt;/span&gt;

&lt;span class="c1"&gt;// direct/main.js&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Activity&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./icons/Activity.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;   &lt;span class="c1"&gt;// straight to the file&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Both give you the exact same &lt;code&gt;Activity&lt;/code&gt;. I profiled each with &lt;a href="https://www.npmjs.com/package/loadometer" rel="noopener noreferrer"&gt;loadometer&lt;/a&gt;, a tiny tool that times every module your app loads and prints a flame graph:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node &lt;span class="nt"&gt;--import&lt;/span&gt; loadometer/register main.js
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  The result
&lt;/h2&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;import&lt;/th&gt;
&lt;th&gt;modules loaded&lt;/th&gt;
&lt;th&gt;load time&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;./icons&lt;/code&gt; (barrel)&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;18&lt;/strong&gt; (the barrel + 15 icons + base)&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;95 ms&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;code&gt;./icons/Activity.js&lt;/code&gt; (direct)&lt;/td&gt;
&lt;td&gt;
&lt;strong&gt;3&lt;/strong&gt; (just Activity + base)&lt;/td&gt;
&lt;td&gt;&lt;strong&gt;9 ms&lt;/strong&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;Same icon. &lt;strong&gt;~10× the work&lt;/strong&gt;, for importing one thing instead of fifteen.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Through the barrel&lt;/strong&gt; — every icon lights up, even though we used one:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feneqnl4br58039zfzrxp.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Feneqnl4br58039zfzrxp.png" alt=" "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Direct&lt;/strong&gt; — one sliver:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F80fy7suvaq94lkltglbn.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F80fy7suvaq94lkltglbn.png" alt=" "&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The flame graph makes the cost obvious in a way a number never does: the barrel is &lt;strong&gt;as wide as the entire folder&lt;/strong&gt;, because importing it &lt;em&gt;is&lt;/em&gt; importing the entire folder.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why it happens
&lt;/h2&gt;

&lt;p&gt;A module's job, when loaded, is to run its top-level code. The barrel's top-level code is "load and re-export all 15 icons." So the runtime has no choice — to give you &lt;code&gt;Activity&lt;/code&gt;, it must first &lt;strong&gt;evaluate the whole barrel&lt;/strong&gt;, which means evaluating every module the barrel touches. Your &lt;code&gt;Activity&lt;/code&gt; is at the bottom of a 95ms pile you never asked for.&lt;/p&gt;

&lt;p&gt;This is true for &lt;code&gt;require&lt;/code&gt; and for &lt;code&gt;import&lt;/code&gt;. It's not a bug — it's just what "re-export everything" &lt;em&gt;means&lt;/em&gt; at runtime.&lt;/p&gt;

&lt;h2&gt;
  
  
  Devil's advocate: "but I use all of them anyway"
&lt;/h2&gt;

&lt;p&gt;Fair challenge — so I measured it. Same demo, but importing &lt;strong&gt;all 15&lt;/strong&gt; icons both ways (&lt;code&gt;import * as icons from './icons'&lt;/code&gt; vs. 15 explicit imports):&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;you import&lt;/th&gt;
&lt;th&gt;barrel&lt;/th&gt;
&lt;th&gt;direct&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;one&lt;/strong&gt; icon&lt;/td&gt;
&lt;td&gt;~94 ms&lt;/td&gt;
&lt;td&gt;~9 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;
&lt;strong&gt;all 15&lt;/strong&gt; icons&lt;/td&gt;
&lt;td&gt;~94 ms&lt;/td&gt;
&lt;td&gt;~94 ms&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;When you genuinely use the whole folder, the barrel is &lt;strong&gt;not slower&lt;/strong&gt; — both load all 15 modules, so it's a wash (the barrel just adds one tiny extra file: the index itself). Barrels aren't &lt;em&gt;inherently&lt;/em&gt; slow, and "never use a barrel" is the wrong takeaway.&lt;/p&gt;

&lt;p&gt;But read that table the other way. &lt;strong&gt;The barrel makes "use one" cost exactly as much as "use all."&lt;/strong&gt; Direct imports scale with what you touch — 9 ms for one, 94 ms for fifteen. The barrel charges the full 94 ms &lt;em&gt;no matter what&lt;/em&gt;, even when you only wanted a single icon. It removes your ability to pay for only what you use.&lt;/p&gt;

&lt;p&gt;So the rule isn't "barrels bad." It's: &lt;strong&gt;a barrel is fine when consumers use most of it, and a tax everywhere it's used as a convenient front door for a slice&lt;/strong&gt; — which, for a 200-icon set or a &lt;code&gt;utils/&lt;/code&gt; grab-bag, is almost always.&lt;/p&gt;

&lt;h2&gt;
  
  
  "But tree-shaking fixes this"
&lt;/h2&gt;

&lt;p&gt;Sometimes. A good bundler in a production build &lt;em&gt;can&lt;/em&gt; drop the unused re-exports — &lt;strong&gt;if&lt;/strong&gt; every module is side-effect-free and the graph cooperates. In practice it often doesn't, and plenty of code never goes through that optimization at all:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Dev server / HMR&lt;/strong&gt; — unbundled, every barrel is paid in full, on every restart.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;SSR &amp;amp; serverless&lt;/strong&gt; — Node loads modules directly; a fat barrel is a fatter cold start.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tests&lt;/strong&gt; — importing one helper through a barrel drags the whole folder into every test file.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;CLIs and scripts&lt;/strong&gt; — no bundler, just &lt;code&gt;node&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Side-effectful or circular barrels&lt;/strong&gt; — tree-shaking quietly gives up and keeps everything.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The runtime cost is real wherever the bundler isn't — which is most of where your code actually runs while you're building it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Find your own barrels
&lt;/h2&gt;

&lt;p&gt;You don't have to guess. Point loadometer at your entry and look for a frame that's suspiciously wide for how little you used it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# prints folded stacks to a file…&lt;/span&gt;
&lt;span class="nv"&gt;LOADOMETER_OUT_FILE&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;imports.folded node &lt;span class="nt"&gt;--import&lt;/span&gt; loadometer/register app.js
&lt;span class="c"&gt;# …drop it on https://speedscope.app for the flame graph&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If a single &lt;code&gt;index&lt;/code&gt; frame spans half the chart, that's your barrel.&lt;/p&gt;

&lt;h2&gt;
  
  
  The fixes (cheapest first)
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Import from the file, not the barrel.&lt;/strong&gt; &lt;code&gt;from './icons/Activity'&lt;/code&gt;, not &lt;code&gt;from './icons'&lt;/code&gt;. Boring, free, works everywhere.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Stop re-exporting side effects.&lt;/strong&gt; If &lt;code&gt;index.ts&lt;/code&gt; exists only to save keystrokes, it may be costing more than it saves.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Make barrels narrow.&lt;/strong&gt; Group by what's actually imported together, not "everything in the folder."&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lint it.&lt;/strong&gt; Rules like &lt;code&gt;no-barrel-files&lt;/code&gt; / &lt;code&gt;import/no-namespace&lt;/code&gt;, or biome's import rules, catch new ones before they grow.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Lazy-load the heavy stuff&lt;/strong&gt; with dynamic &lt;code&gt;import()&lt;/code&gt; so it's off the startup path entirely.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  The takeaway
&lt;/h2&gt;

&lt;p&gt;Barrel files optimize for the &lt;strong&gt;writer&lt;/strong&gt; (one tidy import line) at the expense of the &lt;strong&gt;runtime&lt;/strong&gt; (loading a whole folder to use one file). The convenience is real, and so is the bill — it's just invisible until you put a flame graph next to it.&lt;/p&gt;

&lt;p&gt;So put a flame graph next to it.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Profiled with &lt;a href="https://www.npmjs.com/package/loadometer" rel="noopener noreferrer"&gt;loadometer&lt;/a&gt; — &lt;code&gt;npm i -D loadometer&lt;/code&gt;, then &lt;code&gt;node --import loadometer/register app.js&lt;/code&gt;. It works with &lt;code&gt;require&lt;/code&gt; and &lt;code&gt;import&lt;/code&gt;, on Node and Bun.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>typescript</category>
      <category>node</category>
      <category>performance</category>
    </item>
  </channel>
</rss>
