Skip to content

Commit e6ed1fb

Browse files
committed
LUCENE-10012: Improve concurrency with path distance caching.
1 parent a40d5a4 commit e6ed1fb

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

lucene/spatial3d/src/java/org/apache/lucene/spatial3d/geom/GeoStandardPath.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121
import java.io.OutputStream;
2222
import java.util.ArrayList;
2323
import java.util.Collections;
24-
import java.util.HashMap;
2524
import java.util.List;
2625
import java.util.Map;
26+
import java.util.concurrent.ConcurrentHashMap;
2727

2828
/**
2929
* GeoShape representing a path across the surface of the globe, with a specified half-width. Path
@@ -1070,7 +1070,7 @@ private static class PathSegment {
10701070
/** End point of the segment */
10711071
public final GeoPoint end;
10721072
/** Place to keep any complete segment distances we've calculated so far */
1073-
public final Map<DistanceStyle, Double> fullDistanceCache = new HashMap<>();
1073+
public final Map<DistanceStyle, Double> fullDistanceCache = new ConcurrentHashMap<>();
10741074
/** Normalized plane connecting the two points and going through world center */
10751075
public final Plane normalizedConnectingPlane;
10761076
/** Cutoff plane parallel to connecting plane representing one side of the path segment */
@@ -1175,16 +1175,14 @@ public PathSegment(
11751175
* @return the distance metric, in aggregation form.
11761176
*/
11771177
public double fullPathDistance(final DistanceStyle distanceStyle) {
1178-
synchronized (fullDistanceCache) {
1179-
Double dist = fullDistanceCache.get(distanceStyle);
1180-
if (dist == null) {
1181-
dist =
1182-
distanceStyle.toAggregationForm(
1183-
distanceStyle.computeDistance(start, end.x, end.y, end.z));
1184-
fullDistanceCache.put(distanceStyle, dist);
1185-
}
1186-
return dist.doubleValue();
1178+
Double dist = fullDistanceCache.get(distanceStyle);
1179+
if (dist == null) {
1180+
dist =
1181+
distanceStyle.toAggregationForm(
1182+
distanceStyle.computeDistance(start, end.x, end.y, end.z));
1183+
fullDistanceCache.put(distanceStyle, dist);
11871184
}
1185+
return dist.doubleValue();
11881186
}
11891187

11901188
/**

0 commit comments

Comments
 (0)