Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using icon libraries cause massive increases to build time #12793

Open
1 task
OiYouYeahYou opened this issue Dec 19, 2024 · 6 comments
Open
1 task

Using icon libraries cause massive increases to build time #12793

OiYouYeahYou opened this issue Dec 19, 2024 · 6 comments
Labels
needs triage Issue needs to be triaged

Comments

@OiYouYeahYou
Copy link

Astro Info

Astro                    v5.0.9
Node                     v23.3.0
System                   Linux (x64)
Package Manager          npm
Output                   static
Adapter                  none
Integrations             none

If this issue only occurs in one browser, which browser is a problem?

No response

Describe the Bug

Using icon libraries* increases build times by factors of seconds. The worst culprit being a 3,166,940% increase on page reloads in dev mode

Build (total time score) Average Page Load **
Clean 1.57s 5.2 ms
Importing 12.81s 16,4686 ms

I've also raised this issue in 2 icon libraries:

* and probably other types of libs, but I've not tested any others
** User hand refreshed consecutively

What's the expected result?

For the build command, I'm less concerned

For the dev command and single page refreshes, I expect the load time to be sub second, not tens of seconds like the repro and other projects

Link to Minimal Reproducible Example

https://github.com/oy3-archive/astro-dep-perf

Participation

  • I am willing to submit a pull request for this issue.
@github-actions github-actions bot added the needs triage Issue needs to be triaged label Dec 19, 2024
@Firaenix
Copy link

Firaenix commented Dec 19, 2024

I'm hitting this too - seems to be the fault of a new Astro version. I'm still trying to identify which version introduced the slowness.

EDIT: It seems to happen as soon as you go from Astro v4 to Astro v5.
I'm not using lucide-astro but lucide-svelte with the @astrojs/svelte adapter.
In dev mode, I'm getting builds of around 3-6 second per page load that has lucide-svelte icons included. the lucide-svelte JS bundle ends up being around 3.4MB or so

@OiYouYeahYou
Copy link
Author

OiYouYeahYou commented Dec 20, 2024

It happens in v4 as well, but the build time inflation is still sub second, so at least tolerable. My personal projects still suffer an intolerable build time bloat though

@ematipico
Copy link
Member

I thought we fixed that, but maybe this is another issue. Thank you for reporting

@Firaenix
Copy link

Is this something easily worked around with some vite config changes? Or is this something inherent to Astro?

@bluwy
Copy link
Member

bluwy commented Jan 6, 2025

For dev, since lucide-astro is an astro library that needs to be compiled, it's added by Astro to be transformed by Vite. When Vite transforms the library in dev, it doesn't perform treeshaking so all files are imported and processed by default. You can follow vitejs/vite#8237 for some details, but there's not much possible to fix this for now.

For build, it seems like Rollup will transform all files in the library before taking into account of sideEffects false for treeshaking. So it's not quite possible to skip transforming the unused icons early on without some rollup architecture change.

As a workaround, the library needs to export the icons individually and be imported individually, which understandably isn't a very good solution. Or when Vite & rolldown lands. Otherwise personally I use unocss icons.

@Firaenix
Copy link

Firaenix commented Jan 8, 2025

But seems weird that the build size has suddenly ballooned just from upgrading Astro.
I was having page build times in no more than 100ms and likely even lower, however with the latest version of Astro its reached 3-9 seconds per page, which is just a ridiculous time increase and obviously impacts dev experience.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage Issue needs to be triaged
Projects
None yet
Development

No branches or pull requests

4 participants