Improve tree-shaking
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 55/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Active
- Tech stack
- javascript, node.js, rollup
- Domain
- build-system, performance
Research direction
Read the package build configuration and inspect how it produces dist/d3-shape.mjs; the issue identifies Rollup's output.preserveModules as a possible direction. Run the provided esbuild reproduction to record bundle sizes, then check whether publishing per-module files restores the 3.2.0 behavior while keeping the dist/ layout and bundled CDN builds.
Written by the indexing model from the issue text.
Description
Since 3.2.1, the package's default entry points to one bundled file, dist/d3-shape.mjs, instead of separate source files. sideEffects: false used to let bundlers drop unused files. With one file, importing anything keeps that module, and bundlers then have to prove each top-level statement is safe to remove.
Most of them can't be removed, so importing one curve now pulls in nearly all the others.
Reproduction
npm i [email protected]
echo "export { curveLinear } from 'd3-shape'" \
| npx [email protected] --bundle --minify --format=esm | gzip -c | wc -c
| Import | 3.2.0 (gzip) | 3.2.1 (gzip) |
|---|---|---|
curveLinear |
265 B | 2,509 B |
arc |
2,478 B | 4,871 B |
Other toolchains are affected too, though less.
Cause
The file has top-level statements that bundlers treat as side effects:
- 17 prototype assignments, such as
Linear.prototype = { … } - calls such as
var catmullRom = (function custom(alpha) { … })(0.5)andconst sqrt3 = sqrt(3)
The prototype assignments matter most. Adding /*#__PURE__*/ to all 18 top-level calls only reduced the curveLinear case to about 2.3 KB, and those annotations can't be applied to assignments.
Suggested fix
Publish one file per module again, for example with Rollup's output.preserveModules, while keeping the dist/ layout and the bundled CDN builds. This restores the behavior of 3.2.0 without changing the source.
The same build change shipped in d3-array 3.2.5 and d3-time 3.1.1, which grew in the same way under esbuild: ticks + tickIncrement from 420 B to about 1.3 KB, and timeDay + utcDay from 597 B to about 2.7 KB. I haven't looked at the cause in those packages.
- Dominant language
- JavaScript
- Stars
- 2.5k
- Forks
- 307
- Avg merge
- 4h 16m
- Merged PRs (30d)
- 1
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from d3/d3-shape
-
Difficulty 3/5 1-2 days Newbie friendliness 38/100
-
Difficulty 5/5 Over a week Newbie friendliness 35/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
Similar issues
-
ai bug design good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
neomjs/neo-agent-institution#927 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
gramps-project/gramps-web#1671 ·
Maintainers usually reply within 1 day
-
bug good first issue priority: P2 status: ready
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
RhinoLink-Tech/data-fabric#502 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 75/100
cline/mcp-marketplace#3708 ·
-
beginner-friendly category:finding-titles community enhancement first-timers-only good first issue help wanted low hanging fruit micro-contribution type: task up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Berserk-hub150/skillhawk#264 · 1 comment ·
Maintainers usually reply within 4 days