embroider-build / embroider

Compiling Ember apps into spec-compliant, modern Javascript.
MIT License
333 stars 136 forks source link

ember-composable-helpers compat is slow #1631

Open raycohen opened 10 months ago

raycohen commented 10 months ago

One thing I noticed in my build is almost 4 seconds taken by ember-composable-helpers/lib/strip-bad-reexports.js. I have a lot of engines, which I believe leads to this stripping happening many times (maybe once per engine that has ember-composable-helpers in its dependency tree?).

As this bottom of this sandwhich flame graph shows, most of that time comes from this resolve.sync call. (...)

Screenshot 2023-10-07 at 8 32 44 PM

When the addon tree is built this logic strips out re-export statements from the index.js barrel file that don't match up with anything that resolve can find. That makes sense, except... what good are these re-exports at all? Helpers are usually accessed from the template, which don't use the index.js re-exports. I realize any consumer could import from it, but how common is this?

My first thought was to contribute a new option to ember-composable-helpers to allow apps to have index.js get funneled out of the addon tree completely instead of running the StripBadReexports logic. But when I tried that, I got an error from embroider's ember-composable-helpers compat adapter because it expects that index.js file to exist.

What's the best path here? Make embroider's compat adapter more flexible? Fork (and rename) ember-composable-helpers and remove the addon/index.js file?

simonihmig commented 10 months ago

I needed a bit to understand what all of this StripBadReexports is even about, so it seems to be for supporting this manual "tree-shaking" using only and exclude, without keeping broken imports around...

Honestly, even though I have implemented similar things in ember-bootstrap when Embroider was not even a thing, I think nowadays it doesn't even make sense to have this anymore, and more so to invest precious developer time to make this outdated concept continue to work.

I'd rather invest the time to make https://github.com/DockYard/ember-composable-helpers/issues/450 happen, as @NullVoxPopuli suggested, and then you get tree-shaking out of the box without any manual configs, without custom broccoli stuff and without Embroider compat adapters.