-
-
Notifications
You must be signed in to change notification settings - Fork 429
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
perf: reuse compiler process when using sass-embedded #1195
Changes from 1 commit
ecc9206
5952f5a
2e8a443
b111ffd
e75dbde
2514e16
ea88129
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -650,6 +650,7 @@ function getWebpackImporter(loaderContext, implementation, includePaths) { | |
} | ||
|
||
let nodeSassJobQueue = null; | ||
let sassEmbeddedCompiler = null; | ||
|
||
/** | ||
* Verifies that the implementation and version of Sass is supported by this loader. | ||
|
@@ -665,10 +666,16 @@ function getCompileFn(implementation, options) { | |
|
||
if (isNewSass) { | ||
if (options.api === "modern") { | ||
return (sassOptions) => { | ||
return async (sassOptions) => { | ||
const { data, ...rest } = sassOptions; | ||
|
||
return implementation.compileStringAsync(data, rest); | ||
if (!sassEmbeddedCompiler) { | ||
// Create a long-running compiler process that can be reused | ||
// for compiling individual files. | ||
sassEmbeddedCompiler = await implementation.initAsyncCompiler(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure about the lifetime of a webpack loader. If webpack provides some hook for this, we could close the compiler process by calling There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Firstly let's implement the Yes, we should close if (!sassEmbeddedCompiler && loader._compiler) {
sassEmbeddedCompiler = await implementation.initAsyncCompiler();
loader._compiler.hooks.shutdown.tap("name", () => { sassEmbeddedCompiler.dispose() })
} Some people can run loader in multi threading way and there is no There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also will be great to make some benches, for example for bootstrap to undestand how it is better There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Could you clarify this? (Why) can we not use the long-running subprocess in that case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It is slow for perf, initial start will be very long and we don't need subprocess There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've implemented your suggestions. Re:
is there a pre-existing repo or setup I can use to benchmark this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, let's just check it, I will put it in release notes There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For what it's worth, I don't have the exact numbers but on a larger project I'm working on, |
||
} | ||
|
||
return sassEmbeddedCompiler.compileStringAsync(data, rest); | ||
}; | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed unused argument.