Skip to content

Commit

Permalink
Don't recreate example groups for mutation except when necessary
Browse files Browse the repository at this point in the history
If data hasn't changed since the last iteration of the mutator loop,
then the example groups can be reused, and don't need to be
recalculated.

This restores a noticeable chunk of the performance lost in HypothesisWorks#2308.
  • Loading branch information
Zalathar committed Feb 13, 2020
1 parent f781f78 commit 3db0b6f
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions hypothesis-python/src/hypothesis/internal/conjecture/engine.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,6 +687,7 @@ def should_generate_more():
):
initial_calls = self.call_count
failed_mutations = 0
groups = None
while (
should_generate_more()
# We implement fairly conservative checks for how long we
Expand All @@ -695,11 +696,12 @@ def should_generate_more():
and self.call_count <= initial_calls + 5
and failed_mutations <= 5
):
groups = defaultdict(list)
for ex in data.examples:
groups[ex.label, ex.depth].append(ex)
if groups is None:
groups = defaultdict(list)
for ex in data.examples:
groups[ex.label, ex.depth].append(ex)

groups = [v for v in groups.values() if len(v) > 1]
groups = [v for v in groups.values() if len(v) > 1]

if not groups:
break
Expand Down Expand Up @@ -750,6 +752,7 @@ def should_generate_more():
)
):
data = new_data
groups = None
failed_mutations = 0
else:
failed_mutations += 1
Expand Down

0 comments on commit 3db0b6f

Please sign in to comment.