Skip to content

Commit

Permalink
GH-2998 improve performance of Changeset and reduce memory load of Li…
Browse files Browse the repository at this point in the history
…nkedHashModel
  • Loading branch information
hmottestad committed May 18, 2024
1 parent 179c43f commit 668975a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -341,13 +341,13 @@ private static class ModelNode<V extends Value> implements Serializable {

private static final long serialVersionUID = -1205676084606998540L;

Set<ModelStatement> subjects = new LinkedHashSet<>();
Set<ModelStatement> subjects = new LinkedHashSet<>(1);

Set<ModelStatement> predicates = new LinkedHashSet<>();
Set<ModelStatement> predicates = new LinkedHashSet<>(1);

Set<ModelStatement> objects = new LinkedHashSet<>();
Set<ModelStatement> objects = new LinkedHashSet<>(1);

Set<ModelStatement> contexts = new LinkedHashSet<>();
Set<ModelStatement> contexts = new LinkedHashSet<>(1);

private final V value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.ConcurrentModificationException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.IdentityHashMap;
Expand Down Expand Up @@ -806,6 +807,25 @@ Iterable<Triple> getApprovedTriples(Resource subj, IRI pred, Value obj) {

void removeApproved(Statement next) {
assert !closed;

try {
Model localApproved = approved;
if (localApproved != null && !readWriteLock.writeLock.isWriteLocked() && !localApproved.contains(next)) {
boolean readLock = readWriteLock.readLock();
try {
if (approved != null && !approvedEmpty) {
if (!approved.contains(next)) {
return;
}
}
} finally {
readWriteLock.unlockReader(readLock);
}
}

} catch (ConcurrentModificationException ignored) {
}

long writeLock = readWriteLock.writeLock();
try {
if (approved != null) {
Expand Down

0 comments on commit 668975a

Please sign in to comment.