Skip to content

Conversation

@jportner
Copy link
Contributor

@jportner jportner commented Mar 28, 2020

Overview

In this PR, I changed all of our usage of node-sass to (dart-)sass instead. The latter is the reference implementation of sass; it is more well maintained, has lightweight dependencies, and doesn't rely on C bindings*.

Performance

node-sass is generally faster than sass that is run as native JavaScript. However, based on some anecdotal manual testing, I didn't notice much of a performance difference for Kibana.

Before changes
np bld    log   [12:44:14.473] [success][@kbn/optimizer] 57 bundles compiled successfully after 99.8 sec, watching for changes
...
optmzr    log   [12:44:41.998] [info][optimize:dynamic_dll_plugin] Need to compile the client vendors dll
optmzr    log   [12:44:42.001] [info][optimize:dynamic_dll_plugin] Client vendors dll compilation started
optmzr    log   [12:45:05.281] [info][optimize:dynamic_dll_plugin] Client vendors dll compilation finished with success
optmzr    log   [12:45:17.549] [info][optimize:dynamic_dll_plugin] Finished all dynamic dll plugin tasks
optmzr    log   [12:45:17.551] [info][optimize] Optimization success in 120.33 seconds
optmzr    log   [12:45:22.639] [info][optimize:dynamic_dll_plugin] No need to compile client vendors dll
optmzr    log   [12:45:22.639] [info][optimize:dynamic_dll_plugin] Finished all dynamic dll plugin tasks
optmzr    log   [12:45:22.640] [info][optimize] Optimization success in 4.15 seconds
After changes
np bld    log   [12:50:32.665] [success][@kbn/optimizer] 57 bundles compiled successfully after 102.4 sec, watching for changes
...
optmzr    log   [12:51:19.476] [info][optimize:dynamic_dll_plugin] Need to compile the client vendors dll
optmzr    log   [12:51:19.493] [info][optimize:dynamic_dll_plugin] Client vendors dll compilation started
optmzr    log   [12:51:38.600] [info][optimize:dynamic_dll_plugin] Client vendors dll compilation finished with success
optmzr    log   [12:51:50.747] [info][optimize:dynamic_dll_plugin] Finished all dynamic dll plugin tasks
optmzr    log   [12:51:50.750] [info][optimize] Optimization success in 98.68 seconds
optmzr    log   [12:51:56.947] [info][optimize:dynamic_dll_plugin] No need to compile client vendors dll
optmzr    log   [12:51:56.948] [info][optimize:dynamic_dll_plugin] Finished all dynamic dll plugin tasks
optmzr    log   [12:51:56.948] [info][optimize] Optimization success in 5.17 seconds

* Note: I did include fibers in a couple of consumers to speed up async rendering, but this comes with prebuilt binaries instead of relying on node-gyp. See #61722 (comment).

@jportner jportner force-pushed the replace-node-sass branch from c998827 to 1940e9e Compare March 28, 2020 16:35
@jportner jportner added chore release_note:skip Skip the PR/issue when compiling release notes v7.8.0 v8.0.0 labels Mar 28, 2020
Copy link
Contributor Author

@jportner jportner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Author's notes.

Comment on lines -181 to +262
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While Dart Sass supports a JavaScript API that's fully compatible with Node Sass, I had to make this change:

  • Only the "expanded" and "compressed" values of outputStyle are supported.

Reference: https://github.com/sass/dart-sass#javascript-api

Comment on lines 151 to 155
Copy link
Contributor Author

@jportner jportner Mar 28, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made this optional change to boost performance:

Note however that by default, renderSync() is more than twice as fast as render() due to the overhead of asynchronous callbacks. To avoid this performance hit, render() can use the fibers package to call asynchronous importers from the synchronous code path.

Reference: https://github.com/sass/dart-sass#javascript-api

Note: we could change this to use the renderSync function instead, then we wouldn't need fibers here. However, we would still need fibers for the kbn-optimizer package.

@jportner
Copy link
Contributor Author

jportner commented Apr 1, 2020

@elasticmachine merge upstream

@jportner jportner removed the v7.8.0 label Jun 15, 2020
jportner added 4 commits June 15, 2020 13:01
This results in better performance for `sass.render()` by calling
asynchronous importers from the synchronous code path.
The `sass` module has a known limitation that prevents it from
running with the default Jest test environment of "jsdom". Needed
to create a separate Jest test config to allow the sass-related
unit tests to execute properly.
While this approach works just fine in practice, it doesn't seem
to execute properly in a Jest test environment. The `renderSync`
function obviates the need for `fibers`, so I used that instead
and it's now testable.

Note: snapshots needed to be updated because we are using a
different sass outputStyle ("compressed" instead of "nested").
@jportner jportner force-pushed the replace-node-sass branch from 5b67dcc to 73306fc Compare June 15, 2020 17:02
@kibanamachine
Copy link
Contributor

💔 Build Failed

Failed CI Steps

Build metrics

‼️ metrics were not reported for [#61722@73306fc]

History

  • 💔 Build #37831 failed 5b67dccd949c9f20748b5029b6535aa7ccc50f30
  • 💔 Build #37218 failed 76df323f79999715acc6c36f13e91286616bcac0
  • 💔 Build #37214 failed 986601f4c32728ec3414073aabb39be8db12995a
  • 💔 Build #36986 failed 1940e9e207ce874b80d2c24b0413edb6dea10756
  • 💔 Build #36984 failed c998827a5d6fcd2652bfd73ed14a6610e94811c2

To update your PR or re-run it, just comment with:
@elasticmachine merge upstream

@jportner jportner removed the v8.0.0 label Jul 7, 2020
@jportner jportner closed this Apr 15, 2021
@jportner jportner deleted the replace-node-sass branch January 19, 2022 20:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore release_note:skip Skip the PR/issue when compiling release notes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants