Skip to content

Commit

Permalink
Cache resolved Fix file path to improve include() performance. (#287)
Browse files Browse the repository at this point in the history
- includeBenchmarkBase1:      3.3080 +/- 0.0558
- includeBenchmarkBase1000:   3.4018 +/- 0.0212
- includeBenchmarkBase100000: 5.4032 +/- 0.0494
- includeBenchmarkSome1:      3.7932 +/- 0.1135
- includeBenchmarkSome1000:   3.8172 +/- 0.0428
- includeBenchmarkSome100000: 6.1055 +/- 0.1947
- includeBenchmarkMany1:      5.2958 +/- 0.2262
- includeBenchmarkMany1000:   5.3335 +/- 0.3680
- includeBenchmarkMany100000: 7.7365 +/- 0.1504
  • Loading branch information
blackwinter committed Oct 16, 2023
1 parent 4ddfcac commit 4fb8426
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions metafix/src/main/java/org/metafacture/metafix/Metafix.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ public class Metafix implements StreamPipe<StreamReceiver>, Maps { // checkstyle
private final Map<String, Map<String, String>> maps = new HashMap<>();
private final Map<String, RecordTransformer> fixCache = new HashMap<>();
private final Map<String, RecordTransformer> macros = new HashMap<>();
private final Map<String, String> pathCache = new HashMap<>();
private final Map<String, String> vars = new HashMap<>();
private final RecordTransformer recordTransformer;
private final StreamFlattener flattener = new StreamFlattener();
Expand Down Expand Up @@ -149,6 +150,10 @@ public void literal(final String name, final String value) {
}

public String resolvePath(final String path) {
return pathCache.computeIfAbsent(path, this::resolvePathInternal);
}

private String resolvePathInternal(final String path) {
final String resolvedPath;

if (isValidUrl(path)) {
Expand Down

0 comments on commit 4fb8426

Please sign in to comment.