Skip to content

Commit

Permalink
Fixed #1375 - removed memoization of string value pattern matches, as…
Browse files Browse the repository at this point in the history
… this is severly detrimental to performance for some workloads and causes unbounded heap growth
  • Loading branch information
tomakehurst committed Sep 8, 2020
1 parent 1b48c42 commit 278ab58
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import static com.google.common.collect.Iterables.getLast;
import static org.apache.commons.lang3.math.NumberUtils.isNumber;

public class EqualToJsonPattern extends MemoizingStringValuePattern {
public class EqualToJsonPattern extends StringValuePattern {

private final JsonNode expected;
private final Boolean ignoreArrayOrder;
Expand Down Expand Up @@ -94,7 +94,7 @@ public String getExpected() {
}

@Override
protected MatchResult calculateMatch(String value) {
public MatchResult match(String value) {
try {
final JsonNode actual = Json.read(value, JsonNode.class);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

import static org.apache.commons.lang3.StringUtils.getLevenshteinDistance;

public class EqualToPattern extends MemoizingStringValuePattern {
public class EqualToPattern extends StringValuePattern {

private final Boolean caseInsensitive;

Expand All @@ -46,7 +46,7 @@ public Boolean getCaseInsensitive() {
}

@Override
protected MatchResult calculateMatch(final String value) {
public MatchResult match(final String value) {
return new MatchResult() {
@Override
public boolean isExactMatch() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
import static com.google.common.base.Strings.isNullOrEmpty;
import static org.xmlunit.diff.ComparisonType.*;

public class EqualToXmlPattern extends MemoizingStringValuePattern {
public class EqualToXmlPattern extends StringValuePattern {

private static Set<ComparisonType> COUNTED_COMPARISONS = ImmutableSet.of(
ELEMENT_TAG_NAME,
Expand Down Expand Up @@ -115,7 +115,7 @@ public Set<ComparisonType> getExemptedComparisons() {
}

@Override
protected MatchResult calculateMatch(final String value) {
public MatchResult match(final String value) {
return new MatchResult() {
@Override
public boolean isExactMatch() {
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

import java.util.Objects;

public abstract class PathPattern extends MemoizingStringValuePattern {
public abstract class PathPattern extends StringValuePattern {

protected final StringValuePattern valuePattern;

Expand All @@ -38,7 +38,7 @@ public boolean isSimple() {
}

@Override
protected MatchResult calculateMatch(String value) {
public MatchResult match(String value) {
if (isSimple()) {
return isSimpleMatch(value);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
package com.github.tomakehurst.wiremock.verification;

import com.github.tomakehurst.wiremock.matching.MatchResult;
import com.github.tomakehurst.wiremock.matching.MemoizingMatchResult;
import com.github.tomakehurst.wiremock.matching.RequestPattern;
import com.github.tomakehurst.wiremock.stubbing.*;
import com.google.common.base.Function;
Expand Down Expand Up @@ -52,7 +53,7 @@ public List<NearMiss> findNearestTo(final LoggedRequest request) {

return sortAndTruncate(from(allMappings).transform(new Function<StubMapping, NearMiss>() {
public NearMiss apply(StubMapping stubMapping) {
MatchResult matchResult = stubMapping.getRequest().match(request);
MatchResult matchResult = new MemoizingMatchResult(stubMapping.getRequest().match(request));
String actualScenarioState = getScenarioStateOrNull(stubMapping);
return new NearMiss(request, stubMapping, matchResult, actualScenarioState);
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/ignored/MassiveNearMissTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,12 @@ public void timeToCalculateBigNearMissDiffXml() {
}

final int drop = 2;
final int reps = 30;
final int reps = 10;
List<Long> times = new ArrayList<>(reps);
long sum = 0;
for (int i = 0; i < reps; i++) {
Stopwatch stopwatch = Stopwatch.createStarted();
client.postXml("/things/blah123/" + (stubs / 2), "<?xml version=\"1.0\"?><things />");
client.postXml("/things/blah123/" + (stubs / 2), "<?xml version=\"1.0\"?><things id=\"" + i + "\"/>");
stopwatch.stop();
long time = stopwatch.elapsed(MILLISECONDS);
times.add(time);
Expand Down

0 comments on commit 278ab58

Please sign in to comment.