Skip to content

Commit

Permalink
parallel out, concurrent-ruby in
Browse files Browse the repository at this point in the history
  • Loading branch information
soutaro committed Apr 21, 2023
1 parent 507b450 commit 13b4fc4
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 18 deletions.
3 changes: 1 addition & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@ PATH
specs:
steep (1.4.0.dev.4)
activesupport (>= 5.1)
concurrent-ruby (>= 1.2.2)
csv (>= 3.0.9)
fileutils (>= 1.1.0)
json (>= 2.1.0)
language_server-protocol (>= 3.15, < 4.0)
listen (~> 3.0)
logger (>= 1.3.0)
parallel (>= 1.0.0)
parser (>= 3.1)
rainbow (>= 2.2.2, < 4.0)
rbs (>= 2.8.0)
Expand Down Expand Up @@ -46,7 +46,6 @@ GEM
minitest (> 5.3)
minitest-slow_test (0.2.0)
minitest (>= 5.0)
parallel (1.23.0)
parser (3.2.2.0)
ast (~> 2.4.1)
rainbow (3.1.1)
Expand Down
2 changes: 1 addition & 1 deletion lib/steep.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
require "yaml"
require "securerandom"

require "parallel/processor_count"
require "concurrent/utility/processor_counter"
require "terminal-table"

require "rbs"
Expand Down
2 changes: 0 additions & 2 deletions lib/steep/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ class CLI
attr_reader :stderr
attr_reader :command

include Parallel::ProcessorCount

def initialize(stdout:, stdin:, stderr:, argv:)
@stdout = stdout
@stdin = stdin
Expand Down
4 changes: 1 addition & 3 deletions lib/steep/drivers/utils/jobs_option.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@ module Utils
class JobsOption
attr_accessor :jobs_count, :steep_command, :jobs_count_modifier

include Parallel::ProcessorCount

def initialize(jobs_count_modifier: 0)
@jobs_count_modifier = jobs_count_modifier
end

def default_jobs_count
physical_processor_count + jobs_count_modifier
Concurrent.physical_processor_count + jobs_count_modifier
end

def jobs_count_value
Expand Down
39 changes: 39 additions & 0 deletions sig/shims/concurrent-ruby.rbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module Concurrent
# Number of physical processor cores on the current system. For performance
# reasons the calculated value will be memoized on the first call.
#
# On Windows the Win32 API will be queried for the `NumberOfCores from
# Win32_Processor`. This will return the total number "of cores for the
# current instance of the processor." On Unix-like operating systems either
# the `hwprefs` or `sysctl` utility will be called in a subshell and the
# returned value will be used. In the rare case where none of these methods
# work or an exception is raised the function will simply return 1.
#
# @return [Integer] number physical processor cores on the current system
#
# @see https://github.com/grosser/parallel/blob/4fc8b89d08c7091fe0419ca8fba1ec3ce5a8d185/lib/parallel.rb
#
# @see http://msdn.microsoft.com/en-us/library/aa394373(v=vs.85).aspx
# @see http://www.unix.com/man-page/osx/1/HWPREFS/
# @see http://linux.die.net/man/8/sysctl
def self.physical_processor_count: () -> Integer

# Number of processors seen by the OS and used for process scheduling. For
# performance reasons the calculated value will be memoized on the first
# call.
#
# When running under JRuby the Java runtime call
# `java.lang.Runtime.getRuntime.availableProcessors` will be used. According
# to the Java documentation this "value may change during a particular
# invocation of the virtual machine... [applications] should therefore
# occasionally poll this property." Subsequently the result will NOT be
# memoized under JRuby.
#
# Otherwise Ruby's Etc.nprocessors will be used.
#
# @return [Integer] number of processors seen by the OS or Java runtime
#
# @see http://docs.oracle.com/javase/6/docs/api/java/lang/Runtime.html#availableProcessors()
#
def self.processor_count: () -> Integer
end
5 changes: 0 additions & 5 deletions sig/shims/parallel.rbs

This file was deleted.

2 changes: 0 additions & 2 deletions sig/steep/cli.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ module Steep

attr_reader command: Symbol

include Parallel::ProcessorCount

def initialize: (stdout: IO, stdin: IO, stderr: IO, argv: Array[String]) -> void

def self.available_commands: () -> ::Array[Symbol]
Expand Down
2 changes: 0 additions & 2 deletions sig/steep/drivers/utils/jobs_option.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ module Steep

attr_reader jobs_count_modifier: Integer

include Parallel::ProcessorCount

def initialize: (?jobs_count_modifier: Integer) -> void

def default_jobs_count: () -> Integer
Expand Down
2 changes: 1 addition & 1 deletion steep.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ Gem::Specification.new do |spec|
spec.add_runtime_dependency "listen", "~> 3.0"
spec.add_runtime_dependency "language_server-protocol", ">= 3.15", "< 4.0"
spec.add_runtime_dependency "rbs", ">= 2.8.0"
spec.add_runtime_dependency "parallel", ">= 1.0.0"
spec.add_runtime_dependency "concurrent-ruby", ">= 1.2.2"
spec.add_runtime_dependency "terminal-table", ">= 2", "< 4"
spec.add_runtime_dependency "securerandom", ">= 0.1"
spec.add_runtime_dependency "json", ">= 2.1.0"
Expand Down

0 comments on commit 13b4fc4

Please sign in to comment.