Skip to content

Commit

Permalink
Use FixedThreadPool instead of default (:io) executor
Browse files Browse the repository at this point in the history
Soft-limit max concurrency to lower of 8 or current processor count.
  • Loading branch information
wjordan committed Mar 3, 2018
1 parent 05b27b6 commit df60ba2
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/sprockets/manifest.rb
Expand Up @@ -77,6 +77,7 @@ def initialize(*args)
end

@data = data
@executor = Concurrent::FixedThreadPool.new([8, Concurrent.processor_count].min)
end

# Returns String path to manifest.json file.
Expand Down Expand Up @@ -115,6 +116,8 @@ def files
@data['files'] ||= {}
end

attr_accessor :executor

# Public: Find all assets matching pattern set in environment.
#
# Returns Enumerator of Assets.
Expand All @@ -131,27 +134,26 @@ def find(*args)
environment = self.environment.cached

promises = paths.map do |path|
Concurrent::Promise.execute do
Concurrent::Promise.execute(executor: executor) do
environment.find_all_linked_assets(path) do |asset|
yield asset
end
end
end
promises.each(&:wait!)

if filters.any?
promises = environment.logical_paths.map do |logical_path, filename|
Concurrent::Promise.execute do
promises += environment.logical_paths.map do |logical_path, filename|
Concurrent::Promise.execute(executor: executor) do
if filters.any? { |f| f.call(logical_path, filename) }
environment.find_all_linked_assets(filename) do |asset|
yield asset
end
end
end
end
promises.each(&:wait!)
end

Concurrent::Promise.zip(*promises).wait!
nil
end

Expand Down

0 comments on commit df60ba2

Please sign in to comment.