Skip to content

Commit f76b766

Browse files
committed
Optimization on single vertex property.
Map objects take up a LOT of memory when storing just a single property, as is often the case in the LDBC social network benchmark. So in the case that we really want to fetch only a single property, we can now specify that property to fillProperties(), and then we will store this property in key/value pair member variables natively in a TorcVertex object, instead of creating a Map<Object, Object> properties object. Then when getting properties on the vertex, these variables are checked.
1 parent 60373c8 commit f76b766

File tree

2 files changed

+37
-11
lines changed

2 files changed

+37
-11
lines changed

src/main/java/net/ellitron/torc/TorcGraph.java

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ public void fillProperties(TraversalResult ... rs) {
603603
}
604604
}
605605

606-
public void fillProperties(Iterable<TorcVertex> vertices) {
606+
public void fillProperties(Iterable<TorcVertex> vertices, String ... keys) {
607607
initialize();
608608

609609
torcGraphTx.readWrite();
@@ -679,7 +679,6 @@ public void fillProperties(Iterable<TorcVertex> vertices) {
679679
if (requests[i].getStatus() != Status.STATUS_OK) {
680680
if (requests[i].getStatus() == Status.STATUS_OBJECT_DOESNT_EXIST) {
681681
// This vertex has no properties set.
682-
v.setProperties(new HashMap<>());
683682
continue;
684683
} else {
685684
throw new RuntimeException(
@@ -690,7 +689,11 @@ public void fillProperties(Iterable<TorcVertex> vertices) {
690689

691690
Map<Object, Object> properties = (Map<Object, Object>)
692691
TorcHelper.deserializeObject(requests[i].getValueBytes());
693-
v.setProperties(properties);
692+
if (keys.length == 1) {
693+
v.setProperty(keys[0], properties.get(keys[0]));
694+
} else {
695+
v.setProperties(properties);
696+
}
694697
}
695698
}
696699
}
@@ -709,7 +712,6 @@ public void fillProperties(Iterable<TorcVertex> vertices) {
709712
if (requests[i].getStatus() != Status.STATUS_OK) {
710713
if (requests[i].getStatus() == Status.STATUS_OBJECT_DOESNT_EXIST) {
711714
// This vertex has no properties set.
712-
v.setProperties(new HashMap<>());
713715
continue;
714716
} else {
715717
throw new RuntimeException(
@@ -720,7 +722,11 @@ public void fillProperties(Iterable<TorcVertex> vertices) {
720722

721723
Map<Object, Object> properties = (Map<Object, Object>)
722724
TorcHelper.deserializeObject(requests[i].getValueBytes());
723-
v.setProperties(properties);
725+
if (keys.length == 1) {
726+
v.setProperty(keys[0], properties.get(keys[0]));
727+
} else {
728+
v.setProperties(properties);
729+
}
724730
}
725731
}
726732
}

src/main/java/net/ellitron/torc/TorcVertex.java

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.Iterator;
2828
import java.util.Arrays;
2929
import java.util.Map;
30+
import java.util.HashMap;
3031
import java.util.List;
3132

3233
/**
@@ -38,6 +39,8 @@ public class TorcVertex implements Vertex, Element {
3839
private final TorcGraph graph;
3940
private UInt128 id;
4041
private String label;
42+
private String propKey1 = null;
43+
private Object propVal1 = null;
4144
private Map<Object, Object> properties = null;
4245

4346
public TorcVertex(final TorcGraph graph, final UInt128 id,
@@ -123,26 +126,43 @@ public Iterator<Vertex> vertices(Direction direction, String... edgeLabels) {
123126
throw new UnsupportedOperationException("Must specify the neighbor vertex labels when fetching vertex neighbors.");
124127
}
125128

126-
public <V> V getProperty(String key) {
129+
public Map<Object, Object> getProperties() {
127130
if (properties == null) {
128131
graph.fillProperties(this);
129132
}
130133

131-
return (V)properties.get(key);
134+
return properties;
132135
}
133136

134-
public Map<Object, Object> getProperties() {
135-
if (properties == null) {
136-
graph.fillProperties(this);
137+
public Object getProperty(String key) {
138+
if (propKey1 != null) {
139+
if (propKey1.equals(key))
140+
return propVal1;
137141
}
138142

139-
return properties;
143+
if (properties != null)
144+
return properties.get(key);
145+
else
146+
return null;
140147
}
141148

142149
public void setProperties(Map<Object, Object> properties) {
143150
this.properties = properties;
144151
}
145152

153+
public void setProperty(String key, Object value) {
154+
if (properties == null && propKey1 != null) {
155+
properties = new HashMap<>();
156+
properties.put(propKey1, propVal1);
157+
properties.put(key, value);
158+
} else if (properties != null) {
159+
properties.put(key, value);
160+
}
161+
162+
propKey1 = key;
163+
propVal1 = value;
164+
}
165+
146166
/**
147167
* {@inheritDoc}
148168
*/

0 commit comments

Comments
 (0)