Skip to content

Commit 2e83182

Browse files
ctf: improve scope creation
Speeds up trace reading by ~5-10%. The concurrent hashmap was used to avoid contention. But the function is stable A will always produce B. So we can use a normal hashmap. [Changed] speed up ctf parsing of lexical scopes Change-Id: I75f4b68de08c43f8ccb11a6fb6cc19c2e7d02f1e Signed-off-by: Matthew Khouzam <[email protected]>
1 parent e76953c commit 2e83182

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

ctf/org.eclipse.tracecompass.ctf.core/src/org/eclipse/tracecompass/ctf/core/event/scope/LexicalScope.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313

1414
package org.eclipse.tracecompass.ctf.core.event.scope;
1515

16+
import java.util.HashMap;
1617
import java.util.Map;
17-
import java.util.concurrent.ConcurrentHashMap;
1818

1919
import org.eclipse.jdt.annotation.NonNull;
2020
import org.eclipse.jdt.annotation.Nullable;
@@ -28,7 +28,7 @@ public class LexicalScope implements ILexicalScope {
2828
private int hash = 0;
2929
private final @NonNull String fName;
3030
private final @NonNull String fPath;
31-
private final Map<String, ILexicalScope> fChildren = new ConcurrentHashMap<>();
31+
private final Map<String, ILexicalScope> fChildren = new HashMap<>();
3232

3333
/**
3434
* Hidden constructor for the root node only
@@ -40,6 +40,22 @@ protected LexicalScope() {
4040
fName = ""; //$NON-NLS-1$
4141
}
4242

43+
/**
44+
* Create a scope
45+
* @param parent
46+
* The parent node, can be null, but shouldn't
47+
* @param name
48+
* the name of the field
49+
* @return the scope
50+
*/
51+
public static @NonNull ILexicalScope create(ILexicalScope parent, @NonNull String name) {
52+
ILexicalScope child = parent.getChild(name);
53+
if( child == null) {
54+
child = new LexicalScope(parent, name);
55+
}
56+
return child;
57+
}
58+
4359
/**
4460
* The scope constructor
4561
*

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

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,18 +43,10 @@ public ILexicalScope getPath(IDefinitionScope definitionScope, @NonNull String f
4343
if (definitionScope != null) {
4444
final ILexicalScope parentPath = definitionScope.getScopePath();
4545
if (parentPath != null) {
46-
ILexicalScope myScope = parentPath.getChild(fieldName);
47-
if (myScope == null) {
48-
myScope = new LexicalScope(parentPath, fieldName);
49-
}
50-
return myScope;
46+
return LexicalScope.create(parentPath, fieldName);
5147
}
5248
}
53-
ILexicalScope child = ILexicalScope.ROOT.getChild(fieldName);
54-
if (child != null) {
55-
return child;
56-
}
57-
return new LexicalScope(ILexicalScope.ROOT, fieldName);
49+
return LexicalScope.create(ILexicalScope.ROOT, fieldName);
5850
}
5951

6052
/**

0 commit comments

Comments
 (0)