add trace logging and make set of proposals synchronized
I checked if computing the proposals with a parallel stream would be beneficial. Turns out the stream uses several threads, but the overall computation is not faster, because each individual computation is slower.
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package org.lucares.pdb.datastore.lang;
|
package org.lucares.pdb.datastore.lang;
|
||||||
|
|
||||||
import java.util.BitSet;
|
import java.util.BitSet;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.SortedSet;
|
import java.util.SortedSet;
|
||||||
import java.util.TreeSet;
|
import java.util.TreeSet;
|
||||||
@@ -19,14 +20,18 @@ import org.antlr.v4.runtime.tree.TerminalNode;
|
|||||||
import org.lucares.pdb.datastore.Proposal;
|
import org.lucares.pdb.datastore.Proposal;
|
||||||
import org.lucares.pdb.datastore.internal.DataStore;
|
import org.lucares.pdb.datastore.internal.DataStore;
|
||||||
import org.lucares.utils.CollectionUtils;
|
import org.lucares.utils.CollectionUtils;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
public class QueryCompletionPdbLangParser extends PdbLangParser {
|
public class QueryCompletionPdbLangParser extends PdbLangParser {
|
||||||
|
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(QueryCompletionPdbLangParser.class);
|
||||||
|
|
||||||
public class Listener implements PdbLangListener, ANTLRErrorListener {
|
public class Listener implements PdbLangListener, ANTLRErrorListener {
|
||||||
|
|
||||||
private final int caretPosition;
|
private final int caretPosition;
|
||||||
private final DataStore dataStore;
|
private final DataStore dataStore;
|
||||||
private final SortedSet<Proposal> proposals = new TreeSet<>();
|
private final SortedSet<Proposal> proposals = Collections.synchronizedSortedSet(new TreeSet<>());
|
||||||
private final String query;
|
private final String query;
|
||||||
|
|
||||||
public Listener(final String query, final DataStore dataStore, final int caretPosition) {
|
public Listener(final String query, final DataStore dataStore, final int caretPosition) {
|
||||||
@@ -51,6 +56,7 @@ public class QueryCompletionPdbLangParser extends PdbLangParser {
|
|||||||
final SortedSet<String> proposedValues = getPropertyValuesByPrefix(propertyKey,
|
final SortedSet<String> proposedValues = getPropertyValuesByPrefix(propertyKey,
|
||||||
propertyValuePrefix);
|
propertyValuePrefix);
|
||||||
|
|
||||||
|
final long startTime = System.nanoTime();
|
||||||
proposedValues.stream()//
|
proposedValues.stream()//
|
||||||
.map(v -> {
|
.map(v -> {
|
||||||
final StringBuilder newQuery = new StringBuilder(query);
|
final StringBuilder newQuery = new StringBuilder(query);
|
||||||
@@ -63,13 +69,17 @@ public class QueryCompletionPdbLangParser extends PdbLangParser {
|
|||||||
return new Proposal(p, count> 0);
|
return new Proposal(p, count> 0);
|
||||||
}).forEach(proposals::add);
|
}).forEach(proposals::add);
|
||||||
|
|
||||||
|
LOGGER.trace("proposals for property value {} took {} ms", propertyValuePrefix, (System.nanoTime() - startTime) / 1_000_000.0);
|
||||||
} else if (_ctx instanceof IdentifierExpressionContext) {
|
} else if (_ctx instanceof IdentifierExpressionContext) {
|
||||||
|
final long startTime = System.nanoTime();
|
||||||
final String propertyKeyPrefix = node.getText().substring(0, caretPosition - start);
|
final String propertyKeyPrefix = node.getText().substring(0, caretPosition - start);
|
||||||
|
|
||||||
final StringBuilder newQueryPattern = new StringBuilder(query);
|
final StringBuilder newQueryPattern = new StringBuilder(query);
|
||||||
newQueryPattern.replace(start, end + 1, "%s");
|
newQueryPattern.replace(start, end + 1, "%s");
|
||||||
|
|
||||||
addProposalsForKeys(propertyKeyPrefix, newQueryPattern.toString());
|
addProposalsForKeys(propertyKeyPrefix, newQueryPattern.toString());
|
||||||
|
|
||||||
|
LOGGER.trace("proposals for property key {} took {} ms", propertyKeyPrefix, (System.nanoTime() - startTime) / 1_000_000.0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user