-
Notifications
You must be signed in to change notification settings - Fork 28
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
Subfont consumes infinite memory on tailwind sites #159
Comments
It reaches 38GiB and never finishes :( |
Ok, I tested all of subfont versions and there's no difference. And the debug option
|
And here's the profiling report.
|
I traced source code, and I found that the Line 679 in 048b4bb
// subsetFonts.js L679
console.log('tracing font...');
const textByProps = fontTracer(htmlOrSvgAsset.parseTree, {
stylesheetsWithPredicates: gatherStylesheetsWithPredicates(
htmlOrSvgAsset.assetGraph,
htmlOrSvgAsset
),
getCssRulesByProperty: memoizedGetCssRulesByProperty,
asset: htmlOrSvgAsset,
});
console.log(`1) textByProps.length: ${textByProps.length}`); It stucks printing below.
|
I traced some more. I found a function When I looked into the input object, it has 64 keys which has 35184372088832 of all possible permutations... Is it intended? I'm not sure which side is wrong for input or it's logic. Please let me know if you need more information. Thank you. |
I finally found a correct cause and a way to bypass it. The actual cause of this problem is again, the So I added a small script to remove them(I'm sure they never contribute for font tracing). (Before the below) // Purge the custom css properties from the tailwindcss
for (const styledText of styledTexts) {
styledText.props =
Object.keys(styledText.props)
.filter(key => !key.startsWith("--tw-")).reduce((acc, key) => {
acc[key] = styledText.props[key];
return acc;
}, {});
} And good, it works again! (and quite fast 🚀) But I'm still wondering if this specific care can be generalized. What do you think? Can we add a configuration to ignore some css properties? Thank you again! |
Thank you for reporting this. I didn't know that a large number of CSS variables would cause an exponential effect on permutations in that way. I can think of no easy fix right now, but we'll definitely have to look into how to avoid that somehow. Looking at https://play.tailwindcss.com/ it seems like tailwind applies all of its theme variables to EVERY element and pseudo-element with a I think it's going to be difficult to avoid diving into permutations, but maybe there's are optimizations that can be achieved by only creating permutations for variables known to affect font styles, or realizing that the selector is the same, and maybe using that information to reduce the number of permutations. It's a long time since I looked at that code, so I am not entirely sure what can be done. Maybe @papandreou has more qualified insights here. I don't think a CSS blacklist is the way to go. It could very easily end up resulting in wrong subsets with no good way of detecting that |
I've also been thinking about this problem. I've been wondering if it's possible to collapse some of the hypothetical states together if we can prove that a bunch of predicates are all false or true together. I'm not sure it'll work, and it'll probably be a big effort, so no promises :) |
@AcrylicShrimp, can you share a copy of your |
@papandreou Here's what you want :) |
…operties unrelated to fonts are in play. Munter/subfont#159
The subfont trying to consume all of the memory.
(It reaches 28GiB now)
What's wrong with it?
I'm using subfont version
6.4.2
on M1 Macbook.The text was updated successfully, but these errors were encountered: