Replace pmap gem with pure-Ruby thread pool#14
Merged
Conversation
git_report's only dependency was the pmap gem, used for parallel `map`/`each` over authors, emails, and file slices. Replace it with a small in-tree helper (Git::Parallel) built on the standard library, so the tool now runs on stock Ruby with no gems to install. - Add lib/git/parallel.rb: a bounded worker pool (MAX_THREADS = 64, matching pmap's historical default) providing pmap/peach. The cap is essential -- one thread per author would spawn thousands of git subprocesses on large repositories. Workers drain a pre-filled queue and exit when empty; Thread#value propagates the first worker exception to the caller. - author.rb: accumulate +LOC/-LOC on the main thread after the parallel blocks return, fixing a latent cross-thread `+=` race. - bin/git_report: drop the gem-vendoring/first-run install machinery that existed solely to install pmap; the launcher is now a few lines. - Gemfile: remove `gem 'pmap'`; keep it dependency-free. - Update README and smoke-test comments to reflect zero dependencies. Verified: smoke test passes on Ruby 3.4, runs on stock macOS Ruby 2.6 with no gems, RuboCop clean, and a 5000-item stress test confirms concurrency never exceeds the 64-thread cap.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
git_report's only dependency was thepmapgem, used for parallelmap/eachover authors, emails, and file slices. This replaces it with a small in-tree helper,Git::Parallel, built entirely on the Ruby standard library. The tool now runs on stock Ruby (including the macOS system Ruby) with nothing to install.What changed
lib/git/parallel.rb(new) — a bounded worker pool providingpmap/peach.MAX_THREADS = 64matches pmap 1.1.1's historical default, so throughput on large repos is unchanged. The cap is essential: a naive one-thread-per-element version would spawn thousands of concurrentgitsubprocesses on a large repo (a fork bomb). Workers drain a pre-filled queue and exit when empty;Thread#valuepropagates the first worker exception to the caller.lib/git/author.rb—+LOC/-LOCnow accumulate on the main thread after the parallel blocks return, fixing a latent cross-thread+=race that existed under the oldpmapusage too.bin/git_report— removed the gem-vendoring / first-rungem installmachinery that existed solely to install pmap. The launcher is now a few lines.Gemfile— removedgem 'pmap'; the project is now dependency-free.Verification
2 runs, 12 assertions, 0 failures)7 files, no offenses)