Slow unocss config loading since v0.59.0
hi-ogawa opened this issue · comments
UnoCSS version
0.60.2
Describe the bug
I was seeing slower startup when integrating unocss in a recent project and it looks like this is happening since v0.59.0.
It might not be noticeable on a decent PC, but I happen to be (temporary) using a worst laptop and this felt like a significant slow down (for exampele, from 608.85ms to 2.020s in a stackblitz reproduction below).
I briefly checked perf from node --inspect-brk repro.mjs
and it appears that jiti
(used by unconfig
, which in turn used by @unocss/config
) is taking a long time transforming something. I'm suspecting this might be because jiti
is transforming entire unocss
after it became esm only.
Reproduction
https://github.com/hi-ogawa/reproductions/tree/main/unocss-jiti-esm-slow-config
https://stackblitz.com/github/hi-ogawa/reproductions/tree/main/unocss-jiti-esm-slow-config?file=repro.mjs
// node repro.mjs
import { loadConfig } from "@unocss/config";
console.time("[loadConfig]");
console.log(await loadConfig());
console.timeEnd("[loadConfig]");
$ npm install && (node repro.mjs && (cd fast && npm i && node repro.mjs))
... on v0.60.2 ...
{
config: {},
sources: [ '/home/projects/qgnigvkoz.github/uno.config.ts' ]
}
[loadConfig]: 2.020s
... on v0.58.9 ...
{
config: {},
sources: [ '/home/projects/qgnigvkoz.github/fast/uno.config.ts' ]
}
[loadConfig]: 608.85ms
System Info
(stackblitz)
Validations
- Read the Contributing Guidelines.
- Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- The provided reproduction is a minimal reproducible example of the bug.
On my latpop also reproducible (i7 12700H):
v0.58.9
:[loadConfig]: 889.937ms
v0.60.2
:[loadConfig]: 1.620s
@hi-ogawa you can provide cwd and file name when loading the configuration: await loadConfig(process.cwd(), 'unocss.config.ts')
:
v0.58.9
:[loadConfig]: 225.94ms
v0.60.2
:[loadConfig]: 664.644ms
Using in the reproductions (preparing PR):
"overrides": {
"unconfig": "0.4.1"
}
v0.58.9
:[loadConfig]: 215.667ms
v0.60.2
:[loadConfig]: 203.762ms