sass/dart-sass

Use worker threads to implement render()

Open

#868 opened on Oct 30, 2019

View on GitHub
 (7 comments) (8 reactions) (0 assignees)Dart (4,192 stars) (376 forks)batch import
JavaScriptenhancementhelp wanted

Description

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 synchronous Evaluator. 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.

Contributor guide