-
Notifications
You must be signed in to change notification settings - Fork 27
Backport trafo optimization #201
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
Open
jra-se
wants to merge
24
commits into
dev
Choose a base branch
from
backport-trafo-optimization
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
0e258b3
use LinkedList instead of ArrayList for temporary candidate lists
jra-se 9cb3ff2
use LinkedList instead of ArrayList for temporary candidate lists
jra-se f9f63f2
use comments to store parents instead of hashmap
jra-se 57f4426
use FastLookupList to prevent List copies
jra-se 5f4e694
add searchplan optimization
jra-se 4a8f21b
add missing candidate resets
jra-se 431e314
deepClone on move: monticore/monticore#4671
jra-se 9fd4c08
add dirty flag to the search graph to prevent unnecessary traversals …
jra-se 5734b6a
add error code
jra-se b4b48e7
add option to disable search plan optimization
jra-se 4bc3cc3
add todo
jra-se c11815a
Merge branch 'dev' into backport-trafo-optimization
jra-se d20dda5
Merge branch 'refs/heads/dev' into backport-trafo-optimization
jra-se f847cee
Merge branch 'dev' into backport-trafo-optimization
jra-se 49e9355
generate reset methods for all optionals instead of lists of Runnables
jra-se e07cbd2
generate reset methods for all optionals instead of lists of Runnables
jra-se 3c25e51
try to add missing optional resets in handles
jra-se 4d177bf
Merge branch 'dev' into backport-trafo-optimization
jra-se a0ae26c
added todo
jra-se 1947415
made optimizeSearchplan method protected
jra-se abb94d9
added more comments
jra-se 154de79
minor doc fix
jra-se 3b3cd49
added even more comments
luepges b7ee83e
Merge branch 'dev' into backport-trafo-optimization
luepges File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
monticore-runtime/src/main/java/de/monticore/tf/runtime/FastLookupList.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| /* (c) https://github.com/MontiCore/monticore */ | ||
| package de.monticore.tf.runtime; | ||
|
|
||
| import java.util.AbstractList; | ||
| import java.util.ConcurrentModificationException; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * A sliding range, read-only window of list. | ||
| * Alternative to myList = new ArrayList(list); | ||
| * myList.remove(0); | ||
| * Calling {@link #remove(int)} of this class instead moves the read-window ahead. | ||
| * Does not support updates to the underlying list. | ||
| * | ||
| * @param <T> type of the list | ||
| */ | ||
|
|
||
| public class FastLookupList<T> extends AbstractList<T> { | ||
|
|
||
| protected List<T> list; | ||
|
|
||
| public FastLookupList(List<T> list) { | ||
| this.list = list; | ||
| this.size = list.size(); | ||
| } | ||
|
|
||
| public FastLookupList(List<T> list, int removalCounter) { | ||
| this(list); | ||
| this.removalCounter = removalCounter; | ||
| } | ||
|
|
||
| protected int removalCounter = 0; | ||
| protected int size; | ||
|
|
||
| public void reset() { | ||
| removalCounter = 0; | ||
| } | ||
|
|
||
| @Override | ||
| public T get(int index) { | ||
| if (list.size() != size) { | ||
| throw new ConcurrentModificationException("FastLookupList size changed"); | ||
| } | ||
| return this.list.get(index + removalCounter); | ||
| } | ||
|
|
||
| @Override | ||
| public T remove(int index) { | ||
| if (index != 0) { | ||
| throw new IllegalArgumentException("You may only remove index 0"); | ||
| } | ||
| removalCounter++; | ||
| return null; | ||
| } | ||
|
|
||
| @Override | ||
| public int size() { | ||
| return size - removalCounter; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isEmpty() { | ||
| if (list.size() != size) { | ||
| throw new ConcurrentModificationException("FastLookupList size changed"); | ||
| } | ||
| return removalCounter == size; | ||
| } | ||
|
|
||
| public FastLookupList<T> matchCopy() { | ||
| return new FastLookupList<>(this.list, this.removalCounter); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "FastLookupList{" + removalCounter + "/ " + size + ": " + list.subList(removalCounter, | ||
| size) + "}"; | ||
| } | ||
| } |
2 changes: 0 additions & 2 deletions
2
monticore-runtime/src/main/java/de/monticore/tf/runtime/ODRule.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 0 additions & 5 deletions
5
monticore-runtime/src/main/java/de/monticore/tf/runtime/SuccessfulReporter.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...re-runtime/src/main/java/de/monticore/tf/runtime/matching/CommentBasedModelTraversal.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| /* (c) https://github.com/MontiCore/monticore */ | ||
| package de.monticore.tf.runtime.matching; | ||
|
|
||
| import de.monticore.ast.ASTNode; | ||
| import de.monticore.ast.Comment; | ||
| import de.monticore.visitor.ITraverser; | ||
|
|
||
| import java.util.*; | ||
|
|
||
| /** | ||
| * This CommentBasedModelTraversal is a more efficient implementation of the default | ||
| * ModelTraversal. Instead of using a HashMap to store node parents, which showed unexpected | ||
| * performance issues due to the suboptimal hash function of ASTNodes, this Traversal stores | ||
| * node parents as Comment objects in the respective child nodes. | ||
| * Thereby map lookups are prevented and replaced by efficient direct lookups. | ||
| * | ||
| * @param <E> a language traverser type | ||
| */ | ||
| public class CommentBasedModelTraversal<E extends ITraverser> extends ModelTraversal<E> { | ||
|
|
||
| protected CommentBasedModelTraversal(E traverser) { | ||
| super(traverser); | ||
| } | ||
|
|
||
| @Override | ||
| public ASTNode getParent(ASTNode node) { | ||
| return ((WComment) node.get_PostCommentList().get(0)).getParent(); | ||
| } | ||
|
|
||
| public void init() { | ||
| for (Map.Entry<ASTNode, ASTNode> node : this.getParents().entrySet()) { | ||
| if (node.getKey().get_PostCommentList().isEmpty()) { | ||
| node.getKey().get_PostCommentList().add(new WComment("", node.getValue())); | ||
| } | ||
| else { | ||
| node.getKey().get_PostCommentList() | ||
| .set(0, new WComment(node.getKey().get_PostCommentList().get(0), node.getValue())); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| static class WComment extends Comment { | ||
|
|
||
| protected ASTNode parent; | ||
|
|
||
| public WComment(String text, ASTNode parent) { | ||
| super(text); | ||
| this.parent = parent; | ||
| } | ||
|
|
||
| public WComment(Comment c, ASTNode parent) { | ||
| this(c.getText(), parent); | ||
| this.set_SourcePositionStart(c.get_SourcePositionStart()); | ||
| this.set_SourcePositionEnd(c.get_SourcePositionEnd()); | ||
| } | ||
|
|
||
| public ASTNode getParent() { | ||
| return parent; | ||
| } | ||
| } | ||
|
|
||
| } | ||
33 changes: 33 additions & 0 deletions
33
...ime/src/main/java/de/monticore/tf/runtime/matching/CommentBasedModelTraversalFactory.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| /* (c) https://github.com/MontiCore/monticore */ | ||
| package de.monticore.tf.runtime.matching; | ||
|
|
||
| import de.monticore.visitor.ITraverser; | ||
|
|
||
| public class CommentBasedModelTraversalFactory extends ModelTraversalFactory { | ||
|
|
||
| private static CommentBasedModelTraversalFactory instance; | ||
|
|
||
| public static CommentBasedModelTraversalFactory getInstance() { | ||
| if (instance == null) { | ||
| instance = new CommentBasedModelTraversalFactory(); | ||
| } | ||
| return instance; | ||
| } | ||
|
|
||
| /** | ||
| * @return a {@link ModelTraversal} for the given model | ||
| */ | ||
| public ModelTraversalVisitor createVisitor(ModelTraversal<?> modelTraversal) { | ||
| return new CommentBasedModelTraversalVisitor(modelTraversal); | ||
| } | ||
|
|
||
| public <E extends ITraverser> ModelTraversal<E> create(java.util.function.Supplier<E> traverserSupplier){ | ||
| return this.create(traverserSupplier.get()); | ||
| } | ||
|
|
||
| public <E extends ITraverser> ModelTraversal<E> create(E traverser){ | ||
| ModelTraversal<E> modelTraversal = new CommentBasedModelTraversal<>(traverser); | ||
| traverser.add4IVisitor(createVisitor(modelTraversal)); | ||
| return modelTraversal; | ||
| } | ||
| } |
11 changes: 11 additions & 0 deletions
11
...ime/src/main/java/de/monticore/tf/runtime/matching/CommentBasedModelTraversalVisitor.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| /* (c) https://github.com/MontiCore/monticore */ | ||
| package de.monticore.tf.runtime.matching; | ||
|
|
||
| import de.monticore.visitor.IVisitor; | ||
|
|
||
| public class CommentBasedModelTraversalVisitor extends ModelTraversalVisitor implements IVisitor { | ||
|
|
||
| protected CommentBasedModelTraversalVisitor(ModelTraversal<?> modelTraversal) { | ||
| super(modelTraversal); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.