Remove barrel file imports from internal code for better tree-shaking#21350
Merged
NullVoxPopuli merged 2 commits intomainfrom May 6, 2026
Merged
Remove barrel file imports from internal code for better tree-shaking#21350NullVoxPopuli merged 2 commits intomainfrom
NullVoxPopuli merged 2 commits intomainfrom
Conversation
Contributor
📊 Package size report -0.44%↓
Show files (239 files)
🤖 This report was automatically generated by pkg-size-action |
6 tasks
NullVoxPopuli-ai-agent
pushed a commit
to NullVoxPopuli-ai-agent/ember.js
that referenced
this pull request
May 1, 2026
The smoke tests on emberjs#21350 fail with "Cannot read properties of null (reading 'syscall')" in `AppendOpcodes.evaluate`. Cause: the lint autofix replaced barrel imports of `@glimmer/runtime` with deep paths (`@glimmer/runtime/lib/...`), so nothing pulled in the package index. The index's `import './lib/bootstrap';` was the only thing loading the opcode handler files (each `lib/compiled/opcodes/*.ts` registers via top-level `APPEND_OPCODES.add(...)`), so 28 of 90 handlers stayed unregistered. Fix: own the bootstrap from the file that actually consumes registered handlers — `lib/vm/low-level.ts`, where `evaluateSyscall` calls `APPEND_OPCODES.evaluate(...)`. Any deep-import path that uses the VM (directly or transitively) now triggers bootstrap; consumers that don't need the VM don't pay for opcode handlers in their bundle. Verified by counting top-level `APPEND_OPCODES.add(...)` calls in `dist/dev`: origin/main: 90 in a chunk loaded by everyone nvp/remove-barrel-imports: 62 loaded + 28 trapped in the unused `@glimmer/runtime/index.js` this commit: 90 reachable from `@ember/-internals/glimmer/index.js` Note for reviewers: the validator duplicate-package guard in `@glimmer/validator/index.ts` and the `class EmberObject extends CoreObject.extend(Observable)` extension in `@ember/object/index.ts` are also barrel-only side effects. EmberObject's case is handled naturally — `import EmberObject from '@ember/object'` is a default import, which the lint rule's `kept` mechanism preserves on the barrel. The validator guard becomes dormant under deep imports; if that's a concern, move the registration check into a shared leaf module (e.g. `lib/meta.ts`) in a follow-up. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
kategengler
previously approved these changes
May 2, 2026
Member
kategengler
left a comment
There was a problem hiding this comment.
I think this is annoying for core devs but fine.
You say that the lint rule is "hot garbage" but I believe we need the lint rule + fixing or nobody will ever adhere to this: The feedback needs to be at dev time and not in a CI job at PR submission time. SO, assuming you are willing to support correcting the lint rule when necessary, I'm 👍
cfe606e to
400b8a3
Compare
Contributor
📊 Size reportTarball size — dist/dev -0.96%↓
Show files (123 files)
dist/prod -0.39%↓
Show files (114 files)
smoke-tests/v2-app-hello-world-template/dist -3.18%↓
🤖 This report was automatically generated by wyvox/pkg-size |
9425764 to
c00601d
Compare
9 tasks
Contributor
Author
|
Here is the journey so far on top of this PR for the hello-world test: #21359 |
This was referenced May 3, 2026
Replace all internal barrel imports (from `@ember/-internals/glimmer`,
`@ember/-internals/environment`, etc.) with direct imports from the
specific source files that define what is needed. Also replace all
`export *` patterns in `@ember` packages with explicit named exports.
- Update ~40 source files to import from specific lib paths instead of
barrel `index.ts` files
- Replace `export *` with named exports in `@ember/-internals/environment`,
`@ember/engine/parent`, `@ember/template-compiler/*`, `ember-template-compiler`,
and `ember-testing`
- Replace `import * as environment` with named `{ hasDOM }` import in
`@ember/application/instance`
- Add deep import path entries to `@ember/-internals/package.json` exports map
- Add `@glimmer/opcode-compiler` dependency to `ember-template-compiler`
Test files are intentionally left unchanged as they may use barrel imports.
Revert manual changes, so we can test lint
Lint rule
Lint rule
Update sub-path exports
Lint rule
Lint rule
eslint
lint:fix
Lockfile
Fix
fix
c00601d to
0f20060
Compare
kategengler
approved these changes
May 6, 2026
kategengler
approved these changes
May 6, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The overall goal here is to be able to better analyze the dependency graph and not have arbitrary walls between packages, so that we can better refactor, trim away, and untangle all the imports.
Note
I'm ok with dropping the new lint rule - the code is hot garbage -- I think next, I want to PR a smoke test that + GH Action that gives us the bytes of the smallest app possible, so we have something to track against.
Replace all internal imports with direct imports from the specific source files that define what is needed. Also replace all
export *patterns in@emberpackages with explicit named exports.This is... quite a bit more annoying for typing out imports.... but, it allows us to better progress towards more optimized bundles, and allows us to analyze all of ember-source, without having to go through our artificially created package entrypoints.
The entrypoints are unchanged, as they are public/intimate API, but our own code won't be using them (except in tests).
I've also created a lint to autofix any usages of these things, because doing it manually is a bad time.
Test files are intentionally left unchanged as they may use barrel imports.
Here is an example of where we can go next: #21354
TLDR ALREADY
smallest project possible (weekend warrior enablement)
goes from 77kb gzip to 36kb gzip
(this is 31kb brotli)
once done, this would put us ahead of react in bundle size
https://bundlejs.com/?q=react%4019.2.5%2Creact-dom%2Fclient&treeshake=%5B%7B+%2F*+doesn%27t+matter%21+nothing%21+*%2F+%7D%5D%2C%5B%7B+createRoot+%7D%5D
60.9kb gzip
it seemed high, so I checked on stackblitz as vite reports it, not just bundlejs...
https://stackblitz.com/edit/vitejs-vite-n3xcucgm?file=index.html&terminal=dev