perf(react-icons-font-subsetting-webpack-plugin): improve plugin performance #966
+47
−14
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
follows #961 (comment)
1) Regex handling + module filtering
isFluentUIReactFontChunkcreated and executed an inline RegExp for every module (/.../.test(m.resource)) . This was executed ~300 times while runningnpm testREACT_ICONS_FONT_MODULE_IMPORT_PATTERN) andisFluentUIReactFontChunkadds a cheap prefilter (resource.includes('react-icons')) before running the regex.Impact: Fewer regex executions across large module graphs; lower per-module overhead.
2) Subset text generation complexity
subsetTextby scanning all glyph entries in the font codepoint map:Object.entries(codepointMap).filter(...).map(...).join('')subsetTextby iterating onlyusedExportsand doing O(1) lookups incodepointMap:for (const glyphName of usedExports) { codepointMap[glyphName] ... }Impact: Changes from O(total glyphs in font) per font → O(used icons) per font, which is typically much smaller.
3) Correct async waiting (also affects perf/consistency)
await optimizationPromises;(does not actually await the array of promises).await Promise.all(optimizationPromises);Impact: Ensures all subsetting work completes during
optimizeAssets(fixes non-determinism and prevents leftover async work outside the compilation stage).Perf gains
npm test)