Skip to content

Commit

Permalink
Update to use the Dart Sass binary and the new v2 protocol
Browse files Browse the repository at this point in the history
E.g. use `sass --embedded`.

Note taht this will bumb to a new major version of this library (v2).

If you need to support the old protocol/binary, use the v1 (root path) version.

It seems to be twice as fast when running in parallel, but slightly slower serialized:

```bash
name                             old time/op    new time/op    delta
Transpiler/SCSS-10                  114µs ± 0%     145µs ± 1%  +26.40%  (p=0.029 n=4+4)
Transpiler/Start_and_Execute-10    25.6ms ± 2%    26.0ms ± 3%     ~     (p=0.486 n=4+4)
Transpiler/SCSS_Parallel-10        89.0µs ± 2%    44.4µs ± 3%  -50.12%  (p=0.029 n=4+4)

name                             old alloc/op   new alloc/op   delta
Transpiler/SCSS-10                 1.33kB ± 1%    1.33kB ± 0%     ~     (p=1.000 n=4+4)
Transpiler/Start_and_Execute-10    22.4kB ± 1%    22.4kB ± 1%     ~     (p=0.886 n=4+4)
Transpiler/SCSS_Parallel-10        1.34kB ± 3%    1.33kB ± 1%     ~     (p=1.000 n=4+4)

name                             old allocs/op  new allocs/op  delta
Transpiler/SCSS-10                   18.0 ± 0%      18.0 ± 0%     ~     (all equal)
Transpiler/Start_and_Execute-10       144 ± 1%       150 ± 0%   +4.16%  (p=0.029 n=4+4)
Transpiler/SCSS_Parallel-10          18.0 ± 0%      18.0 ± 0%     ~     (all equal)
```

See gohugoio/hugo#11059
Fixes #15
  • Loading branch information
bep committed Jun 8, 2023
1 parent 9f9f1c1 commit b0d3c36
Show file tree
Hide file tree
Showing 8 changed files with 658 additions and 706 deletions.
29 changes: 15 additions & 14 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ on:
pull_request:
name: Test
env:
DART_SASS_VERSION: 1.56.1
SASS_VERSION: 1.63.2
jobs:
test:
strategy:
matrix:
go-version: [~1.18, ~1.19]
go-version: [~1.19, ~1.20]
os: [ubuntu-latest, macos-latest, windows-latest]
runs-on: ${{ matrix.os }}
steps:
Expand All @@ -19,24 +19,25 @@ jobs:
go-version: ${{ matrix.go-version }}
- name: Checkout code
uses: actions/checkout@v3
- name: Install dart-sass-embedded Linux
- name: Install dart-sass Linux
if: matrix.os == 'ubuntu-latest'
run: |
curl -LJO "https://github.com/sass/dart-sass-embedded/releases/download/${DART_SASS_VERSION}/sass_embedded-${DART_SASS_VERSION}-linux-x64.tar.gz";
tar -xvf "sass_embedded-${DART_SASS_VERSION}-linux-x64.tar.gz";
echo "DART_SASS_EMBEDDED_BINARY=$GITHUB_WORKSPACE/sass_embedded/dart-sass-embedded" >> $GITHUB_ENV
- name: Install dart-sass-embedded MacOS
curl -LJO "https://github.com/sass/dart-sass/releases/download/${SASS_VERSION}/dart-sass-${SASS_VERSION}-linux-x64.tar.gz";
tar -xvf "dart-sass-${SASS_VERSION}-linux-x64.tar.gz";
echo "DART_SASS_BINARY=$GITHUB_WORKSPACE/dart-sass/sass" >> $GITHUB_ENV
./dart-sass/sass --version
- name: Install dart-sass MacOS
if: matrix.os == 'macos-latest'
run: |
curl -LJO "https://github.com/sass/dart-sass-embedded/releases/download/${DART_SASS_VERSION}/sass_embedded-${DART_SASS_VERSION}-macos-x64.tar.gz";
tar -xvf "sass_embedded-${DART_SASS_VERSION}-macos-x64.tar.gz";
echo "DART_SASS_EMBEDDED_BINARY=$GITHUB_WORKSPACE/sass_embedded/dart-sass-embedded" >> $GITHUB_ENV
- name: Install dart-sass-embedded Windows
curl -LJO "https://github.com/sass/dart-sass/releases/download/${SASS_VERSION}/dart-sass-${SASS_VERSION}-macos-x64.tar.gz";
tar -xvf "dart-sass-${SASS_VERSION}-macos-x64.tar.gz";
echo "DART_SASS_BINARY=$GITHUB_WORKSPACE/dart-sass/sass" >> $GITHUB_ENV
- name: Install dart-sass Windows
if: matrix.os == 'windows-latest'
run: |
curl -LJO "https://github.com/sass/dart-sass-embedded/releases/download/${env:DART_SASS_VERSION}/sass_embedded-${env:DART_SASS_VERSION}-windows-x64.zip";
Expand-Archive -Path "sass_embedded-${env:DART_SASS_VERSION}-windows-x64.zip" -DestinationPath .;
echo "DART_SASS_EMBEDDED_BINARY=$env:GITHUB_WORKSPACE/sass_embedded/dart-sass-embedded.bat" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
curl -LJO "https://github.com/sass/dart-sass/releases/download/${env:SASS_VERSION}/dart-sass-${env:SASS_VERSION}-windows-x64.zip";
Expand-Archive -Path "dart-sass-${env:SASS_VERSION}-windows-x64.zip" -DestinationPath .;
echo "DART_SASS_BINARY=$env:GITHUB_WORKSPACE/dart-sass/sass.bat" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append
- name: Test
run: go test -race . -coverprofile=coverage.txt -covermode=atomic
- name: Upload coverage
Expand Down
17 changes: 3 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,13 @@
[![codecov](https://codecov.io/gh/bep/godartsass/branch/main/graph/badge.svg?token=OWZ9RCAYWO)](https://codecov.io/gh/bep/godartsass)
[![GoDoc](https://godoc.org/github.com/bep/godartsass?status.svg)](https://godoc.org/github.com/bep/godartsass)

This is a Go API backed by the native [Dart Sass Embedded](https://github.com/sass/dart-sass-embedded) executable.
This is a Go API backed by the native [Dart Sass](https://github.com/sass/dart-sass/releases) executable running with `sass --embedded`.

>**Note:** The `v2.x.x` of this project targets the `v2` of the Dart Sass Embedded protocol with the `sass` exexutable in releases that can be downloaeded [here](https://github.com/sass/dart-sass/releases). For `v1` you need to import `github.com/bep/godartsass` and not `github.com/bep/godartsass/v2`.
The primary motivation for this project is to provide `SCSS` support to [Hugo](https://gohugo.io/). I welcome PRs with bug fixes. I will also consider adding functionality, but please raise an issue discussing it first.

For LibSass bindings in Go, see [GoLibSass](https://github.com/bep/golibsass).

The benchmark below compares [GoLibSass](https://github.com/bep/golibsass) with this library. This is almost twice as fast when running single-threaded, but slower when running with multiple Goroutines. We're communicating with the compiler process via stdin/stdout, which becomes the serialized bottle neck here. That may be possible to improve, but for most practical applications (including Hugo), this should not matter.

```bash
Transpile/SCSS-16 770µs ± 0% 467µs ± 1% -39.36% (p=0.029 n=4+4)
Transpile/SCSS_Parallel-16 92.2µs ± 2% 362.5µs ± 1% +293.39% (p=0.029 n=4+4)

name old alloc/op new alloc/op delta
Transpile/SCSS-16 192B ± 0% 1268B ± 0% +560.42% (p=0.029 n=4+4)
Transpile/SCSS_Parallel-16 192B ± 0% 1272B ± 0% +562.37% (p=0.029 n=4+4)

name old allocs/op new allocs/op delta
Transpile/SCSS-16 2.00 ± 0% 19.00 ± 0% +850.00% (p=0.029 n=4+4)
Transpile/SCSS_Parallel-16 2.00 ± 0% 19.00 ± 0% +850.00% (p=0.029 n=4+4)
```
4 changes: 2 additions & 2 deletions internal/embeddedsass/README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

* Install protobuf: https://github.com/protocolbuffers/protobuf
* Install the Go plugin: go get -u google.golang.org/protobuf/cmd/protoc-gen-go
* Download the correct version of the proto file: https://github.com/sass/embedded-protocol/blob/master/embedded_sass.proto
* Install the Go plugin: go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
* Download the correct version of the proto file: https://github.com/sass/sass/blob/main/spec/embedded_sass.proto
* protoc --go_opt=Membedded_sass.proto=github.com/bep/godartsass/internal/embeddedsass --go_opt=paths=source_relative --go_out=. embedded_sass.proto
Loading

0 comments on commit b0d3c36

Please sign in to comment.