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;
|
||||
|
||||
import java.util.BitSet;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.SortedSet;
|
||||
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.internal.DataStore;
|
||||
import org.lucares.utils.CollectionUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class QueryCompletionPdbLangParser extends PdbLangParser {
|
||||
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(QueryCompletionPdbLangParser.class);
|
||||
|
||||
public class Listener implements PdbLangListener, ANTLRErrorListener {
|
||||
|
||||
private final int caretPosition;
|
||||
private final DataStore dataStore;
|
||||
private final SortedSet<Proposal> proposals = new TreeSet<>();
|
||||
private final SortedSet<Proposal> proposals = Collections.synchronizedSortedSet(new TreeSet<>());
|
||||
private final String query;
|
||||
|
||||
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,
|
||||
propertyValuePrefix);
|
||||
|
||||
final long startTime = System.nanoTime();
|
||||
proposedValues.stream()//
|
||||
.map(v -> {
|
||||
final StringBuilder newQuery = new StringBuilder(query);
|
||||
@@ -63,13 +69,17 @@ public class QueryCompletionPdbLangParser extends PdbLangParser {
|
||||
return new Proposal(p, count> 0);
|
||||
}).forEach(proposals::add);
|
||||
|
||||
LOGGER.trace("proposals for property value {} took {} ms", propertyValuePrefix, (System.nanoTime() - startTime) / 1_000_000.0);
|
||||
} else if (_ctx instanceof IdentifierExpressionContext) {
|
||||
final long startTime = System.nanoTime();
|
||||
final String propertyKeyPrefix = node.getText().substring(0, caretPosition - start);
|
||||
|
||||
final StringBuilder newQueryPattern = new StringBuilder(query);
|
||||
newQueryPattern.replace(start, end + 1, "%s");
|
||||
|
||||
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