Skip to content

Commit 933af82

Browse files
ctf: cache enums for non-overlapping values under 4096
Yields a major performance boost on wide enum systems. Change-Id: Ic65433ee8f7165fc610312681553f355879f3e67 Signed-off-by: Matthew Khouzam <[email protected]>
1 parent 1f64997 commit 933af82

File tree

1 file changed

+20
-0
lines changed
  • ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types

1 file changed

+20
-0
lines changed

ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/types/EnumDeclaration.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
*/
4747
public final class EnumDeclaration extends Declaration implements ISimpleDatatypeDeclaration {
4848

49+
private static final int CACHE_SIZE = 4096;
4950
/**
5051
* A pair of longs class
5152
*
@@ -111,6 +112,7 @@ public String toString() {
111112
private final Multimap<Pair, String> fEnumMap = LinkedHashMultimap.create();
112113
private final IntegerDeclaration fContainerType;
113114
private Pair fLastAdded = new Pair(-1, -1);
115+
private @Nullable String[] fCache = new String[CACHE_SIZE];
114116

115117
// ------------------------------------------------------------------------
116118
// Constructors
@@ -212,6 +214,18 @@ public boolean add(long low, long high, @Nullable String label) {
212214
if (high < low) {
213215
return false;
214216
}
217+
if(low < 0 || low >= CACHE_SIZE-1 || high < 0 || high >= CACHE_SIZE-1) {
218+
fCache = null;
219+
}
220+
for (int i = (int) low; i < high; i++) { // high is inclusive
221+
if(fCache != null) {
222+
if (fCache[i]== null) {
223+
fCache[i]= label;
224+
} else {
225+
fCache = null;
226+
}
227+
}
228+
}
215229
Pair key = new Pair(low, high);
216230
fEnumMap.put(key, label);
217231
fLastAdded = key;
@@ -241,6 +255,12 @@ public boolean add(@Nullable String label) {
241255
* @return the label of that value, can be null
242256
*/
243257
public @Nullable String query(long value) {
258+
if (fCache != null) {
259+
if (value < 0 || value >= CACHE_SIZE) {
260+
return null;
261+
}
262+
return fCache[(int) value];
263+
}
244264
List<String> strValues = new ArrayList<>();
245265
fEnumMap.forEach((k, v) -> {
246266
if (value >= k.getFirst() && value <= k.getSecond()) {

0 commit comments

Comments
 (0)