Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache resolved Fix file path to improve include() performance. #327

Merged
merged 2 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ editorconfig {
'**/.*',
'**/bin',
'**/generated',
'**/includeBenchmark*100000/expected.json',
'**/node_modules',
'**/out',
'**/output-*',
Expand Down
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"a":"1","b":"2","c":"3","d":"4","e":"5","f":"6","m":"1","n":"2","o":"3","p":"4","q":"5","r":"6","s":"1","t":"2","u":"3","v":"4","w":"5","x":"6"}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
add_field("a", "1")
add_field("b", "2")
add_field("c", "3")
add_field("d", "4")
add_field("e", "5")
add_field("f", "6")

copy_field("a", "g")
copy_field("b", "h")
copy_field("c", "i")
copy_field("d", "j")
copy_field("e", "k")
copy_field("f", "l")

move_field("g", "m")
move_field("h", "n")
move_field("i", "o")
move_field("j", "p")
move_field("k", "q")
move_field("l", "r")

copy_field("m", "s")
copy_field("n", "t")
copy_field("o", "u")
copy_field("p", "v")
copy_field("q", "w")
copy_field("r", "x")
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FLUX_DIR + "input.json"
|open-file
|as-lines
|decode-json
|fix(FLUX_DIR + "test.fix")
|encode-json
|write(FLUX_DIR + "output-metafix.json")
;

Large diffs are not rendered by default.

Loading