Module: Git::Parallel
- Defined in:
- lib/git/parallel.rb
Overview
Minimal parallel helpers built on the Ruby standard library, replacing the former ‘pmap` gem. The work these drive is I/O-bound – every block shells out to git – so threads give real concurrency even under MRI’s GVL: a subprocess spawned by backticks runs outside the lock while other threads proceed. Keeping this in-tree is what lets git-report run on stock Ruby with no gems to install.
Constant Summary collapse
- MAX_THREADS =
Upper bound on worker threads, and therefore on how many git subprocesses run at once. This cap is the whole point: a repository with thousands of authors must NOT spawn a thread (and a ‘git log`) per author – that would swamp the machine. 64 matches the historical default of the pmap gem this replaced, so throughput on large repositories is unchanged.
64
Class Method Summary collapse
-
.peach(enum, &block) ⇒ Object
Like Enumerable#each, but runs the block for each element across a bounded pool of threads.
-
.pmap(enum, &block) ⇒ Object
Like Enumerable#map, but runs the block for each element across a bounded pool of threads and returns the results in the original order.
Class Method Details
.peach(enum, &block) ⇒ Object
Like Enumerable#each, but runs the block for each element across a bounded pool of threads. Returns the original enumerable once all work is done.
32 33 34 35 |
# File 'lib/git/parallel.rb', line 32 def peach(enum, &block) process(enum) { |item, _index| block.call(item) } enum end |
.pmap(enum, &block) ⇒ Object
Like Enumerable#map, but runs the block for each element across a bounded pool of threads and returns the results in the original order.
20 21 22 23 24 25 26 27 28 |
# File 'lib/git/parallel.rb', line 20 def pmap(enum, &block) results = [] mutex = Mutex.new process(enum) do |item, index| value = block.call(item) mutex.synchronize { results[index] = value } end results end |