-
Notifications
You must be signed in to change notification settings - Fork 359
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
Use worker threads to implement render() #868
Comments
I am thinking about taking on the implementation of this and I had a few quick clarification questions:
Sorry I've got all of these clarification questions, I don't want to write a bunch of code only to realize I completely misinterpreted what you were asking for here. |
Yes, definitely!
You wouldn't need to port anything. Dart compiled to JS can invoke JS libraries, so you'd just need to call this library.
We'd definitely be getting rid of
You'd be doing this in |
It looks like this feature has now become more urgent than before, since |
Because of the breakage of fibers in Node.JS v16 and this dependency, It currently looks like using |
@lehni I'm working on a blog post describing the potential ways of working around this issue. We're going to be focusing on the Node embedded host as the main workaround. @jamesrwaugh Sass doesn't actually declare a dependency on |
What is the status of this issue? Our build time increased by about 500% when switching from Is there anything in particular blocking progress on this issue being implemented? |
If build times are a major limitation for you, I strongly suggest either using the native Sass CLI (available from GitHub releases as well as other places) or using the Node.js embedded host which also calls out to the native compiler. To address your specific question: this is still tagged "help wanted", which means that the Sass team doesn't have time to focus on it specifically but we'd welcome external contributions. There's still a draft pull request that someone could pick up as a starting point. |
Hunting down some more reading on sass perf, I found this gh issue: sass/dart-sass#868. That led to me looking at sass-embedded as a drop-in replacement for sass. I tried that, and yep, it does what it says on the tin. Works the same, but async is way faster and comparable to sync perf (with the benefit of much higher throughput if you're doing a lot of stuff concurrently). My entire build wall-clock time is now down to 8s, and the slowest css bundles are 4.5s. Biggest downside seems to be that dart isn't compatible with musl libc, so I had to swap the base docker image I was using for my esbuild pipeline. Unclear to me if there are other tradeoffs.
Hunting down some more reading on sass perf, I found this gh issue: sass/dart-sass#868. That led to me looking at sass-embedded as a drop-in replacement for sass. I tried that, and yep, it does what it says on the tin. Works the same, but async is way faster and comparable to sync perf (with the benefit of much higher throughput if you're doing a lot of stuff concurrently). My entire build wall-clock time is now down to 8s, and the slowest css bundles are 4.5s. Biggest downside seems to be that dart isn't compatible with musl libc, so I had to swap the base docker image I was using for my esbuild pipeline. Unclear to me if there are other tradeoffs.
Currently, we implement the asynchronous
render()
method in Node.js in one of two ways:By default, it's run through the
AsyncEvaluator
which is synchronized via code gen with the synchronousEvaluator
. This is much slower than running synchronously, and imposes developer overhead by requiring synchronization.If the user passes in a reference to the
fibers
package (which uses a C++ extension to add a coroutine-style asynchrony model to Node), we run the synchronous code path and use coroutines to call out to async helpers. This is as fast as running synchronously but requires the end user to opt in to a C++ compilation which may be difficult to compile.Sass's business logic itself is fully synchronous, so we get no benefit from this asynchrony other than the ability to invoke asynchronous function and importer callbacks. I think we can avoid the downsides of both of these methods by running the whole Sass compiler in a worker thread and using
Atomics.wait()
to block that thread until the callback completes.The text was updated successfully, but these errors were encountered: