From 4fb8426cc96d05a723dc0ffa8a390b20e4a41d58 Mon Sep 17 00:00:00 2001 From: Jens Wille Date: Fri, 13 Oct 2023 12:29:18 +0200 Subject: [PATCH] Cache resolved Fix file path to improve `include()` performance. (#287) - 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 --- metafix/src/main/java/org/metafacture/metafix/Metafix.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/metafix/src/main/java/org/metafacture/metafix/Metafix.java b/metafix/src/main/java/org/metafacture/metafix/Metafix.java index d4e360e7..f335e94d 100644 --- a/metafix/src/main/java/org/metafacture/metafix/Metafix.java +++ b/metafix/src/main/java/org/metafacture/metafix/Metafix.java @@ -79,6 +79,7 @@ public class Metafix implements StreamPipe, Maps { // checkstyle private final Map> maps = new HashMap<>(); private final Map fixCache = new HashMap<>(); private final Map macros = new HashMap<>(); + private final Map pathCache = new HashMap<>(); private final Map vars = new HashMap<>(); private final RecordTransformer recordTransformer; private final StreamFlattener flattener = new StreamFlattener(); @@ -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)) {