Closed AcrylicShrimp closed 2 years ago
Hard to know exactly what's going on without a copy of your dist
directory, but it could look like subfont is trying to slurp a bunch of big video files into memory as part of the population.
@papandreou Thanks! But I'm wonder: why subfont
tries to load video files? Does it needed?
And here's the dist
directory. Check it if you need some tests.
Thanks. No, it doesn’t need the video files, so we’re in bug territory :)
I removed whole pages that contains video and same again. It still stuck.
Hmm, it works for me (with node.js 12.16.1) with your command and dist
directory.
I noticed that you have some quite heavy fonts:
15395184 NotoSansMonoCJKkr-Bold.woff
12114352 NotoSansMonoCJKkr-Bold.woff2
14928504 NotoSansMonoCJKkr-Regular.woff
11416896 NotoSansMonoCJKkr-Regular.woff2
All of those will be loaded into memory, so you have to make sure that you have enough and that node.js is allowed to use it.
All of those will be loaded into memory, so you have to make sure that you have enough and that node.js is allowed to use it.
You mean I have to make sure that nodejs takes enough memory? My machine has 32GiB memory, I think it's ok. Is there way to specify memory related options in subfont
?
Hmm, it works for me (with node.js 12.16.1) with your command and
dist
directory.I noticed that you have some quite heavy fonts:
15395184 NotoSansMonoCJKkr-Bold.woff 12114352 NotoSansMonoCJKkr-Bold.woff2 14928504 NotoSansMonoCJKkr-Regular.woff 11416896 NotoSansMonoCJKkr-Regular.woff2
All of those will be loaded into memory, so you have to make sure that you have enough and that node.js is allowed to use it.
Wait, I removed whole fonts and it still stucks. Hmm.
Wrt. allowing it to use the memory I meant something like node --max-old-space-size=30000 path/to/subfont ...
From the GC message it could look like your node thinks it's only allowed to use 512 MB.
@papandreou How long does it take to complete when you tested? And yes, it seems it's memory problem.
real 1m30,825s
user 1m44,569s
sys 0m3,159s
real 1m30,825s user 1m44,569s sys 0m3,159s
1 minute and 30 seconds? That's weird. It's still running on my machine for a long time.
Does --max-old-space-size=...
help?
Does
--max-old-space-size=...
help?
With below command, it stuck too.
node --max-old-space-size=30000 ./node_modules/subfont/lib/cli.js --root ./dist --canonical-root https://blog.ashrimp.dev/ --output ./dist-opt --inline-css --no-fallbacks --debug ./dist/**/*.html
Okay, weird that we're getting different results. Which version of node are you on?
I tried both v17.1.0
and v16.13.0
. subfont
version is 6.4.0
. And I also in Windows 10.
Looks like it also works for me with node.js 16.13.0, although it takes longer:
real 2m26,533s
user 2m34,528s
sys 0m2,580s
Thanks for testing :) But still I don't get it... Hmmmmm.
Are you also trying with the exact contents of dist
that you put into dropbox?
Yes.
I can reproduce this problem in even macOS. Hmm.
Ok, I got it. I tested it a lot on my macOS machine and found that the subfont
won't work when the dist/index.html
is included. Below command,
node --max-old-space-size=30000 ./node_modules/subfont/lib/cli.js --root ./dist --canonical-root https://blog.ashrimp.dev/ --output ./dist-opt --inline-css --no-fallbacks ./dist/**/*.html
doesn't include the dist/index.html
(I think its bug or something). But the fun fact is when I remove the input, the subfont
is going to defaults it with below message.
No input files specified, defaulting to file:///Users/ashrimp/Devel/Projects/devlog/devlog-ssg/dist/**/*.html
In this case, the subfont
tries to process dist/index.html
even though the explicit input ./dist/**/*.html
does not.
Anyway, the subfont
won't work when the dist/index.html
is included. Hmmmmmmm. I'll try more.
After some printf-debugging, I found that its not stuck but it takes toooooooo long to call fontTracer
. I don't know why.
What do you think? I'm going to analyze the font-tracer
.
After many, many tries, I finally profiled the subfont
, and got some critical informations.
Look at this:
ticks parent name
11890 69.1% C:\Program Files\nodejs\node.exe
9765 82.1% C:\Program Files\nodejs\node.exe
5957 61.0% LazyCompile: *DOMException D:\Devel\Projects\devlog\devlog-ssg\node_modules\domexception\lib\DOMException.js:86:18
5957 100.0% LazyCompile: ~emit D:\Devel\Projects\devlog\devlog-ssg\node_modules\nwsapi\src\nwsapi.js:559:13
5957 100.0% Function: ^compileSelector D:\Devel\Projects\devlog\devlog-ssg\node_modules\nwsapi\src\nwsapi.js:775:13
5957 100.0% LazyCompile: *compile D:\Devel\Projects\devlog\devlog-ssg\node_modules\nwsapi\src\nwsapi.js:724:13
1977 20.2% LazyCompile: ~emit D:\Devel\Projects\devlog\devlog-ssg\node_modules\nwsapi\src\nwsapi.js:559:13
1977 100.0% Function: ^compileSelector D:\Devel\Projects\devlog\devlog-ssg\node_modules\nwsapi\src\nwsapi.js:775:13
1971 99.7% LazyCompile: *compile D:\Devel\Projects\devlog\devlog-ssg\node_modules\nwsapi\src\nwsapi.js:724:13
1971 100.0% LazyCompile: *_matches D:\Devel\Projects\devlog\devlog-ssg\node_modules\nwsapi\src\nwsapi.js:1364:22
582 6.0% C:\Program Files\nodejs\node.exe
276 47.4% LazyCompile: *traceProp D:\Devel\Projects\devlog\devlog-ssg\node_modules\font-tracer\lib\fontTracer.js:217:25
177 64.1% LazyCompile: *memoizeSync.argumentsStringifier D:\Devel\Projects\devlog\devlog-ssg\node_modules\font-tracer\lib\fontTracer.js:160:5
177 100.0% Function: ^memoizer D:\Devel\Projects\devlog\devlog-ssg\node_modules\memoizesync\lib\memoizeSync.js:47:26
99 35.9% Function: ^memoizeSync.argumentsStringifier D:\Devel\Projects\devlog\devlog-ssg\node_modules\font-tracer\lib\fontTracer.js:160:5
99 100.0% Function: ^memoizer D:\Devel\Projects\devlog\devlog-ssg\node_modules\memoizesync\lib\memoizeSync.js:47:26
100 17.2% LazyCompile: *_matches D:\Devel\Projects\devlog\devlog-ssg\node_modules\nwsapi\src\nwsapi.js:1364:22
99 99.0% LazyCompile: *ElementImpl.matches D:\Devel\Projects\devlog\devlog-ssg\node_modules\jsdom\lib\jsdom\living\nodes\Element-impl.js:568:42
98 99.0% LazyCompile: *traceProp D:\Devel\Projects\devlog\devlog-ssg\node_modules\font-tracer\lib\fontTracer.js:217:25
1 1.0% LazyCompile: *safeMatchesSelector D:\Devel\Projects\devlog\devlog-ssg\node_modules\font-tracer\lib\fontTracer.js:21:29
1 1.0% Function: ^ElementImpl.matches D:\Devel\Projects\devlog\devlog-ssg\node_modules\jsdom\lib\jsdom\living\nodes\Element-impl.js:568:42
1 100.0% LazyCompile: *safeMatchesSelector D:\Devel\Projects\devlog\devlog-ssg\node_modules\font-tracer\lib\fontTracer.js:21:29
...
The DOMException
takes most of the time. So I added some debug logs to know what's going on.
class DOMException {
constructor() {
const args = [];
{
let curArg = arguments[0];
if (curArg !== undefined) {
curArg = conversions["DOMString"](curArg, { context: "Failed to construct 'DOMException': parameter 1" });
} else {
curArg = "";
}
args.push(curArg);
}
{
let curArg = arguments[1];
if (curArg !== undefined) {
curArg = conversions["DOMString"](curArg, { context: "Failed to construct 'DOMException': parameter 2" });
} else {
curArg = "Error";
}
args.push(curArg);
}
console.log(`DOMException constructor args: ${args}`);``
return iface.setup(Object.create(new.target.prototype), globalObject, args);
}
And here's the output:
DOMException constructor args: unknown pseudo-class selector ':translate-x-8',SyntaxError
DOMException constructor args: unknown pseudo-class selector ':translate-x-7',SyntaxError
DOMException constructor args: unknown pseudo-class selector ':translate-x-6',SyntaxError
DOMException constructor args: unknown pseudo-class selector ':translate-x-5',SyntaxError
DOMException constructor args: unknown pseudo-class selector ':translate-x-4',SyntaxError
DOMException constructor args: unknown pseudo-class selector ':translate-x-3',SyntaxError
DOMException constructor args: unknown pseudo-class selector ':translate-x-2',SyntaxError
DOMException constructor args: unknown pseudo-class selector ':translate-x-1',SyntaxError
DOMException constructor args: unknown pseudo-class selector ':translate-x-0',SyntaxError
DOMException constructor args: unknown pseudo-class selector ':-translate-y-full',SyntaxError
DOMException constructor args: unknown pseudo-class selector ':-translate-y-3\/4',SyntaxError
DOMException constructor args: unknown pseudo-class selector ':-translate-y-2\/4',SyntaxError
DOMException constructor args: unknown pseudo-class selector ':-translate-y-1\/4',SyntaxError
DOMException constructor args: unknown pseudo-class selector ':-translate-y-2\/3',SyntaxError
DOMException constructor args: unknown pseudo-class selector ':-translate-y-1\/3',SyntaxError
DOMException constructor args: unknown pseudo-class selector ':-translate-y-1\/2',SyntaxError
DOMException constructor args: unknown pseudo-class selector ':translate-y-full',SyntaxError
DOMException constructor args: unknown pseudo-class selector ':translate-y-3\/4',SyntaxError
DOMException constructor args: unknown pseudo-class selector ':translate-y-2\/4',SyntaxError
DOMException constructor args: unknown pseudo-class selector ':translate-y-1\/4',SyntaxError
DOMException constructor args: unknown pseudo-class selector ':translate-y-2\/3',SyntaxError
DOMException constructor args: unknown pseudo-class selector ':translate-y-1\/3',SyntaxError
DOMException constructor args: unknown pseudo-class selector ':translate-y-1\/2',SyntaxError
DOMException constructor args: unknown pseudo-class selector ':-translate-y-3\.5',SyntaxError
DOMException constructor args: unknown pseudo-class selector ':-translate-y-2\.5',SyntaxError
DOMException constructor args: unknown pseudo-class selector ':-translate-y-1\.5',SyntaxError
DOMException constructor args: unknown pseudo-class selector ':-translate-y-0\.5',SyntaxError
DOMException constructor args: unknown pseudo-class selector ':-translate-y-px',SyntaxError
DOMException constructor args: unknown pseudo-class selector ':-translate-y-96',SyntaxError
DOMException constructor args: unknown pseudo-class selector ':-translate-y-80',SyntaxError
What is it? It tries to select pseudo-class :-translate
and similar. And yes, they came from the tailwindCSS
. The tailwindCSS
uses special character :
for class names by escaping it with \
. So the cause is so obvious now. The logic for extracting all used CSS selector does not handle escapes correctly. I'm not sure what part is wrong for now, but I'll comment here when it's done.
Ah, wow, nice work!
Ok, I ended this with enabling purge option in the tailwindCSS
... It dramatically reduces css classes so it's working. But it's good to handle escapes correctly(not easy though).
I'm sure we can figure that out together!
I found that I don't need to handle backslash escapes for now. There's no class names includes :
after purging unused classes. So, let's close this issue. I'll re-open it when the problem arises again.
Thanks for your hark work @papandreou.
You're welcome, happy that you found a way to avoid it. If you feel that there's a bug in font-tracer
, please give me a hint 😇
Hello! Suddenly the
subfont
is stuck atpopulate
.And it never finishes without any additional output. What things should I check? Thank you!
EDIT
After long waiting, below is printed.