Skip to content

Commit 7a5006e

Browse files
committed
better profiling (less footprint) in SetNode, add comment
1 parent 6c67f87 commit 7a5006e

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

src/main/java/org/truffleruby/core/hash/HashNodes.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ public Object construct(DynamicObject hashClass, Object[] args) {
7979
final int size = Layouts.ARRAY.getSize(array);
8080
final Object[] newStore = PackedArrayStrategy.createStore(getContext());
8181

82+
// written very carefully to allow PE
8283
for (int n = 0; n < getContext().getOptions().HASH_PACKED_ARRAY_MAX; n++) {
8384
if (n < size) {
8485
final Object pair = store[n];

src/main/java/org/truffleruby/core/hash/SetNode.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import com.oracle.truffle.api.dsl.Specialization;
1616
import com.oracle.truffle.api.nodes.ExplodeLoop;
1717
import com.oracle.truffle.api.object.DynamicObject;
18-
import com.oracle.truffle.api.profiles.BranchProfile;
1918
import com.oracle.truffle.api.profiles.ConditionProfile;
2019
import org.truffleruby.Layouts;
2120
import org.truffleruby.language.RubyBaseNode;
@@ -27,6 +26,7 @@ public abstract class SetNode extends RubyBaseNode {
2726
@Child private LookupEntryNode lookupEntryNode;
2827
@Child private CompareHashKeysNode compareHashKeysNode = new CompareHashKeysNode();
2928
@Child private FreezeHashKeyIfNeededNode freezeHashKeyIfNeededNode = FreezeHashKeyIfNeededNodeGen.create();
29+
private final ConditionProfile byIdentityProfile = ConditionProfile.createBinaryProfile();
3030

3131
public static SetNode create() {
3232
return SetNodeGen.create();
@@ -35,8 +35,7 @@ public static SetNode create() {
3535
public abstract Object executeSet(DynamicObject hash, Object key, Object value, boolean byIdentity);
3636

3737
@Specialization(guards = "isNullHash(hash)")
38-
public Object setNull(DynamicObject hash, Object originalKey, Object value, boolean byIdentity,
39-
@Cached("createBinaryProfile()") ConditionProfile byIdentityProfile) {
38+
public Object setNull(DynamicObject hash, Object originalKey, Object value, boolean byIdentity) {
4039
assert HashOperations.verifyStore(getContext(), hash);
4140
boolean compareByIdentity = byIdentityProfile.profile(byIdentity);
4241
final Object key = freezeHashKeyIfNeededNode.executeFreezeIfNeeded(originalKey, compareByIdentity);
@@ -57,9 +56,7 @@ public Object setNull(DynamicObject hash, Object originalKey, Object value, bool
5756
@ExplodeLoop
5857
@Specialization(guards = "isPackedHash(hash)")
5958
public Object setPackedArray(DynamicObject hash, Object originalKey, Object value, boolean byIdentity,
60-
@Cached("createBinaryProfile()") ConditionProfile byIdentityProfile,
61-
@Cached("createBinaryProfile()") ConditionProfile strategyProfile,
62-
@Cached("create()") BranchProfile extendProfile) {
59+
@Cached("createBinaryProfile()") ConditionProfile strategyProfile) {
6360
assert HashOperations.verifyStore(getContext(), hash);
6461
final boolean compareByIdentity = byIdentityProfile.profile(byIdentity);
6562
final Object key = freezeHashKeyIfNeededNode.executeFreezeIfNeeded(originalKey, compareByIdentity);
@@ -69,6 +66,7 @@ public Object setPackedArray(DynamicObject hash, Object originalKey, Object valu
6966
final Object[] store = (Object[]) Layouts.HASH.getStore(hash);
7067
final int size = Layouts.HASH.getSize(hash);
7168

69+
// written very carefully to allow PE
7270
for (int n = 0; n < getContext().getOptions().HASH_PACKED_ARRAY_MAX; n++) {
7371
if (n < size) {
7472
final int otherHashed = PackedArrayStrategy.getHashed(store, n);
@@ -81,9 +79,7 @@ public Object setPackedArray(DynamicObject hash, Object originalKey, Object valu
8179
}
8280
}
8381

84-
extendProfile.enter();
85-
86-
if (strategyProfile.profile(size + 1 <= getContext().getOptions().HASH_PACKED_ARRAY_MAX)) {
82+
if (strategyProfile.profile(size < getContext().getOptions().HASH_PACKED_ARRAY_MAX)) {
8783
PackedArrayStrategy.setHashedKeyValue(store, size, hashed, key, value);
8884
Layouts.HASH.setSize(hash, size + 1);
8985
return value;
@@ -99,7 +95,6 @@ public Object setPackedArray(DynamicObject hash, Object originalKey, Object valu
9995

10096
@Specialization(guards = "isBucketHash(hash)")
10197
public Object setBuckets(DynamicObject hash, Object originalKey, Object value, boolean byIdentity,
102-
@Cached("createBinaryProfile()") ConditionProfile byIdentityProfile,
10398
@Cached("createBinaryProfile()") ConditionProfile foundProfile,
10499
@Cached("createBinaryProfile()") ConditionProfile bucketCollisionProfile,
105100
@Cached("createBinaryProfile()") ConditionProfile appendingProfile,

0 commit comments

Comments
 (0)