-
Notifications
You must be signed in to change notification settings - Fork 357
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
Implement sass --embedded
in pure JS mode
#2413
base: main
Are you sure you want to change the base?
Conversation
8d7d4de
to
7084da7
Compare
e66df5b
to
d53fcc5
Compare
d7e6206
to
b3794eb
Compare
9112b44
to
54fabf3
Compare
257b4fd
to
ac718ee
Compare
c9124f8
to
b6d9e98
Compare
Here are some benchmark results on 1.80.5 native binary vs pkg-npm-release (node v22.9.0). I tested three cases. All of them on a single persisted compiler, lines that marked with
On single-threaded test Dart is much faster than pure JS, especially in the compute heavy bootstrap test. However, in nearly all multi-threaded test, pure JS is not far from Dart, which is actually great.
Benchmark coderequire 'benchmark'
require 'sass-embedded'
puts Sass.info
BOOTSTRAP = Gem::Specification.find_by_name('bootstrap').gem_dir + '/assets/stylesheets/_bootstrap.scss'
def run(n:, thread: 10, use_thread: false)
if use_thread
queue = Queue.new
n.times do
queue << nil
end
list = []
thread.times do
list << Thread.new do
loop do
queue.pop(true)
yield
rescue ThreadError
break
end
end
end
list.each(&:join)
queue.close
else
n.times do
yield
end
end
end
def sass_embedded_minimal(use_thread: false)
run(n: 10000, use_thread:) do
Sass.compile_string('a {b: c}', style: :compressed, logger: Sass::Logger.silent).css
end
end
def sass_embedded_round_trips(use_thread: false)
run(n: 1000, use_thread:) do
Sass.compile_string('@for $i from 1 through 10 { a:nth-child(#{$i}) { b: foo(); } }', functions: { 'foo()' => ->(_) { Sass::Value::String.new('test') } }, style: :compressed, logger: Sass::Logger.silent).css
end
end
def sass_embedded_bootstrap(use_thread: false)
run(n: 50, use_thread:) do
Sass.compile(BOOTSTRAP, style: :compressed, logger: Sass::Logger.silent).css
end
end
puts '--- Minimal Sass Input ---'
Benchmark.bm(16) do |x|
GC.start
x.report('sass-embedded') do
sass_embedded_minimal
end
GC.start
x.report('sass-embedded/MT') do
sass_embedded_minimal(use_thread: true)
end
end
puts '--- High Round Trips ---'
Benchmark.bm(16) do |x|
GC.start
x.report('sass-embedded') do
sass_embedded_round_trips
end
GC.start
x.report('sass-embedded/MT') do
sass_embedded_round_trips(use_thread: true)
end
end
puts '--- Bootstrap ---'
Benchmark.bm(16) do |x|
GC.start
x.report('sass-embedded') do
sass_embedded_bootstrap
end
GC.start
x.report('sass-embedded/MT') do
sass_embedded_bootstrap(use_thread: true)
end
end |
9cc1a2f
to
1586bbd
Compare
This PR is on my radar, it's just been a very review-heavy few weeks for me and this is unfortunately on the low end of the priority spectrum. |
6a51bdf
to
d11f856
Compare
d11f856
to
a81f9cb
Compare
a81f9cb
to
f0cfa3c
Compare
Closes #2325.
sass/embedded-host-node#344
Implementation
The actual isolate dispatcher and compilation dispatcher are nearly unchanged. However, I had to replace isolate with worker communication, and mock tons of small things that do not work on node.
Testing