A library that compiles sweets files.
However, starting with rails 5.1, webpacker
is recommended for the javascript compiler, and from rails 6.0 the default for the javascript compiler has been changed to webpacker
.
Currently used as the default for CSS and image compilation.
CSS, image -> sprockets javascript -> webpacker
Execution result is not returned by asset precompilation.
By setting either of the following in the application settings, you can disable parallel processing and avoid problems.
Rails.config.assets.export_concurrent = false
Sprockets.export_concurrent = false
Maintenance of gem'sprockets' is slow, and it is expected that it will take time to fix, so it is one to use 3 series.
Sprockets 4.0 is now multithreaded and parallel running to improve compilation performance. See: https://github.com/rails/sprockets/pull/469
Concurrency uses Concurrent :: Promise
and thenwait!
Inpromises.each (&: wait!)
.
promises = args.flatten.map do |path|
Concurrent::Promise.execute(executor: executor) do
environment.find_all_linked_assets(path) do |asset|
yield asset
end
end
end
promises.each(&:wait!)
See: https://github.com/rails/sprockets/pull/469/files#diff-0d972076f2fbe7a73281fcc0282e57a1618bba231bc8023a4d5bc5705fb06da7R123-R130
At this time, the wait!
method waits for the timeout time until the processing is completed, but since no argument is specified, nil
is entered and it keeps waiting forever.
def wait!(timeout = nil)
wait(timeout).tap { raise self if rejected? }
end
See: https://github.com/ruby-concurrency/concurrent-ruby/blob/ffed3c3c0518030b0ed245637703089fa1f0eeee/lib/concurrent/concern/obligation.rb#L79-L89
If a deadlock occurs during concurrency, the asset precompilation process will never end. It seems that multiple threads are deadlocking trying to compile the same file during concurrency. A bug in ruby-concurrency? There is a possibility of. https://github.com/ruby-concurrency/concurrent-ruby/issues/870
There are also many similar issues. See: https://github.com/rails/sprockets/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+thread+OR+concurrent
https://github.com/rails/sprockets/issues/640 https://github.com/rails/sprockets/issues/581 https://github.com/ruby-concurrency/concurrent-ruby/issues/870 https://github.com/ruby-concurrency/concurrent-ruby/blob/ffed3c3c0518030b0ed245637703089fa1f0eeee/lib/concurrent/synchronization/lockable_object.rb#L6-L20
For discussions on sprockets, you can also study the WTF page below. https://discuss.rubyonrails.org/t/sprockets-abandonment/74371/24
Recommended Posts