linkedin / eyeglass

NPM Modules for Sass
741 stars 60 forks source link

Optimize eyeglass asset installation. #226

Closed chriseppstein closed 5 years ago

chriseppstein commented 5 years ago

Eyeglass assets are installed for each invocation of asset-url() which can add performance overhead at scale especially when the same asset is installed many times.

ember-cli-eyeglass now intercepts asset installation and records which assets are installed to which locations. It does this by writing all those assets into a single tree for the entire app and all addons and engines after they are built, which it only needs to do once per distinct url. To accomplish this, I wrote a new broccoli-plugin in this commit which makes in possible to symlink arbitrary files into an output tree.

This PR has the benefit of also ensuring that asset urls can be resolved to any path instead of forcing those urls to resolve to a location relative to the current tree, which fixes a long-standing annoyance that forced assets to be duplicated in engines (note: this patch doesn't change the asset installation locations -- a custom resolver is required to accomplish this for now).

This patch was made more tricky because of my bone-headed insistence of having a generic broccoli sass plugin as the base class for the broccoli eyeglass plugin. The pure sass plugin is in charge of the caching strategy so it uses events to delegate knowledge of how additional outputs are restored from cache to the external code that is invoking this plugin and doing weird things with assets outside the output tree.

A few other things to note:

TODO: I need to add some additional test cases.

stefanpenner commented 5 years ago

@chriseppstein nice, I plan to take a thorough look this evening/weekend.

stefanpenner commented 5 years ago

@chriseppstein I think the overall approach here is very interesting. Good way to have a single "install" step.