d3 / d3

Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:

Home Page:https://d3js.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

D3 is slow to import

j-f1 opened this issue · comments

I think this is a bug with how D3 itself is packaged. Calling import("d3") with d3@7.1.1 installed takes over 300ms to complete. (probably because Node has to resolve all of the modules being re-exported). For comparison, I edited the package.json of d3 to reference dist/d3.min.js as a CommonJS module. Calling import("d3") after making that change only took 15–30ms, which is much more reasonable. Is there any way to change the way the main d3 package is bundled to make it faster to import in a non-bundled environment?

I noticed that I was only using methods from d3-array, and I found that importing d3-array itself takes 64ms. I wonder if it would be more performant to have each package at least bundle all its source files into one (using Rollup or similar) so Node would only have to import 31 different files (d3/index.js + one for each d3-* package) rather than the current 349 (!)

D3 does not provide an ES module bundle, so if you use import, you’re getting potentially hundreds of source files. If you want to load D3 as an ES module, and you don’t want to load the source files, you’ll need to provide a bundle yourself or use a service such as skypack.dev which will do it for you.