|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +# Collating a parallel run's resultsets (`SimpleCov.collate`, and the merge |
| 4 | +# at the end of every parallel run), the cost that grows with a CI run's |
| 5 | +# worker count. Reading each resultset is JSON parsing, and merging it is |
| 6 | +# folding its counts into an accumulator that's updated in place, one |
| 7 | +# resultset at a time. |
| 8 | +# |
| 9 | +# The tuple combiners intern every branch key the first time they see it, |
| 10 | +# in caches that last the process's life: the first `once` of each |
| 11 | +# benchmark warms them, as the first resultset of a real collate does. |
| 12 | + |
| 13 | +require_relative "duel_helper" |
| 14 | + |
| 15 | +# What each further resultset of a run costs: its counts folded into what |
| 16 | +# the run's earlier resultsets merged. The counts grow with every |
| 17 | +# iteration, but the work doesn't. |
| 18 | +duel "collate: absorb a shard of 20 files" do |
| 19 | + once do |
| 20 | + @shards = DuelFixtures.shards(20, 3) |
| 21 | + @accumulator = SimpleCov::Combine::CoverageAccumulator.new |
| 22 | + @shards.first(2).each { |shard| @accumulator.absorb(shard) } |
| 23 | + end |
| 24 | + @accumulator.absorb(@shards.last) |
| 25 | +end |
| 26 | + |
| 27 | +duel "collate: absorb a shard of 200 files" do |
| 28 | + once do |
| 29 | + @shards = DuelFixtures.shards(200, 3) |
| 30 | + @accumulator = SimpleCov::Combine::CoverageAccumulator.new |
| 31 | + @shards.first(2).each { |shard| @accumulator.absorb(shard) } |
| 32 | + end |
| 33 | + @accumulator.absorb(@shards.last) |
| 34 | +end |
| 35 | + |
| 36 | +# A whole merge of two shards, from a fresh accumulator: each file's |
| 37 | +# first merge sets up its tables, and the merged coverage is turned back |
| 38 | +# into the shape a Result reads. The merge holds one resultset at a time, |
| 39 | +# whatever the run's size, so its memory is guarded too. |
| 40 | +duel "collate: merge two shards of 200 files", peak_memory: true do |
| 41 | + once { @shards = DuelFixtures.shards(200, 2).tap { |shards| SimpleCov::Combine::ResultsCombiner.combine(*shards) } } |
| 42 | + SimpleCov::Combine::ResultsCombiner.combine(*@shards) |
| 43 | +end |
| 44 | + |
| 45 | +# The merged coverage, from tables keyed by interned identities back to |
| 46 | +# the tuple-keyed hashes the rest of SimpleCov reads. Done once a merge. |
| 47 | +duel "collate: materialize 200 merged files" do |
| 48 | + once do |
| 49 | + @accumulator = SimpleCov::Combine::CoverageAccumulator.new |
| 50 | + DuelFixtures.shards(200, 3).each { |shard| @accumulator.absorb(shard) } |
| 51 | + end |
| 52 | + @accumulator.result |
| 53 | +end |
| 54 | + |
| 55 | +duel "collate: decode a resultset of 20 files" do |
| 56 | + once { @json = DuelFixtures.resultset_json(20) } |
| 57 | + SimpleCov::ResultMerger::ResultsetFile.decode(@json) |
| 58 | +end |
| 59 | + |
| 60 | +duel "collate: decode a resultset of 200 files" do |
| 61 | + once { @json = DuelFixtures.resultset_json(200) } |
| 62 | + SimpleCov::ResultMerger::ResultsetFile.decode(@json) |
| 63 | +end |
0 commit comments