Skip to content

Commit

Permalink
[Truffle] Backed out concat rope depth limiting specializations.
Browse files Browse the repository at this point in the history
These specializations made compiled code much slower and had meager memory savings. The larger idea is sound, but we need to rethink the approach.
nirvdrum committed Mar 23, 2016
1 parent 8d8640d commit 079efd4
Showing 1 changed file with 1 addition and 70 deletions.
71 changes: 1 addition & 70 deletions truffle/src/main/java/org/jruby/truffle/core/rope/RopeNodes.java
Original file line number Diff line number Diff line change
@@ -226,26 +226,6 @@ public MakeConcatNode(RubyContext context, SourceSection sourceSection) {

public abstract Rope executeMake(Rope left, Rope right, Encoding encoding);

@Specialization(guards = { "left.isEmpty()", "!isMutableRope(left)", "right.getEncoding() == encoding" })
public Rope concatEmptyLeftSameEncoding(Rope left, Rope right, Encoding encoding) {
return right;
}

@Specialization(guards = { "left.isEmpty()", "!isMutableRope(left)", "right.getEncoding() != encoding" })
public Rope concatEmptyLeftDifferentEncoding(Rope left, Rope right, Encoding encoding) {
return RopeOperations.withEncoding(right, encoding);
}

@Specialization(guards = { "right.isEmpty()", "left.getEncoding() == encoding" })
public Rope concatEmptyRightSameEncoding(Rope left, Rope right, Encoding encoding) {
return left;
}

@Specialization(guards = { "right.isEmpty()", "left.getEncoding() != encoding" })
public Rope concatEmptyRightDifferentEncoding(Rope left, Rope right, Encoding encoding) {
return RopeOperations.withEncoding(left, encoding);
}

@Specialization(guards = "isMutableRope(left)")
public Rope concatMutableRope(MutableRope left, Rope right, Encoding encoding,
@Cached("createBinaryProfile()") ConditionProfile differentEncodingProfile) {
@@ -260,56 +240,7 @@ public Rope concatMutableRope(MutableRope left, Rope right, Encoding encoding,
return left;
}

@Specialization(guards = { "!left.isEmpty()", "!right.isEmpty()", "!isMutableRope(left)", "left.byteLength() < SHORT_LEAF_BYTESIZE_THRESHOLD", "right.byteLength() < SHORT_LEAF_BYTESIZE_THRESHOLD" })
public Rope concatLeaves(LeafRope left, LeafRope right, Encoding encoding,
@Cached("createBinaryProfile()") ConditionProfile sameCodeRangeProfile,
@Cached("createBinaryProfile()") ConditionProfile brokenCodeRangeProfile) {
if (makeLeafRopeNode == null) {
CompilerDirectives.transferToInterpreter();
makeLeafRopeNode = insert(RopeNodesFactory.MakeLeafRopeNodeGen.create(getContext(), getSourceSection(), null, null, null, null));
}

final byte[] bytes = new byte[left.byteLength() + right.byteLength()];
System.arraycopy(left.getRawBytes(), 0, bytes, 0, left.byteLength());
System.arraycopy(right.getRawBytes(), 0, bytes, left.byteLength(), right.byteLength());

final CodeRange codeRange = commonCodeRange(left.getCodeRange(), right.getCodeRange(), sameCodeRangeProfile, brokenCodeRangeProfile);

return makeLeafRopeNode.executeMake(bytes, encoding, codeRange, left.characterLength() + right.characterLength());
}

@Specialization(guards = { "!right.isEmpty()", "!isMutableRope(left)", "left.byteLength() >= SHORT_LEAF_BYTESIZE_THRESHOLD", "right.byteLength() < SHORT_LEAF_BYTESIZE_THRESHOLD" })
public Rope concatLeavesGeneral(LeafRope left, LeafRope right, Encoding encoding,
@Cached("createBinaryProfile()") ConditionProfile sameCodeRangeProfile,
@Cached("createBinaryProfile()") ConditionProfile brokenCodeRangeProfile,
@Cached("createBinaryProfile()") ConditionProfile isLeftSingleByteOptimizableProfile) {
return concat(left, right, encoding, sameCodeRangeProfile, brokenCodeRangeProfile, isLeftSingleByteOptimizableProfile);
}

@Specialization(guards = { "!left.isEmpty()", "!right.isEmpty()", "right.byteLength() < SHORT_LEAF_BYTESIZE_THRESHOLD" })
public Rope concatWithReduce(ConcatRope left, LeafRope right, Encoding encoding,
@Cached("createBinaryProfile()") ConditionProfile sameCodeRangeProfile,
@Cached("createBinaryProfile()") ConditionProfile brokenCodeRangeProfile,
@Cached("createBinaryProfile()") ConditionProfile isLeftSingleByteOptimizableProfile,
@Cached("createBinaryProfile()") ConditionProfile shouldCompactProfile) {

if (shouldCompactProfile.profile((left.getRight().byteLength() < SHORT_LEAF_BYTESIZE_THRESHOLD) && (left.getRight() instanceof LeafRope))) {
final Rope compacted = concatLeaves((LeafRope) left.getRight(), right, encoding, sameCodeRangeProfile, brokenCodeRangeProfile);
return concat(left.getLeft(), compacted, encoding, sameCodeRangeProfile, brokenCodeRangeProfile, isLeftSingleByteOptimizableProfile);
}

return concat(left, right, encoding, sameCodeRangeProfile, brokenCodeRangeProfile, isLeftSingleByteOptimizableProfile);
}

@Specialization(guards = { "!left.isEmpty()", "!right.isEmpty()", "right.byteLength() < SHORT_LEAF_BYTESIZE_THRESHOLD" })
public Rope concatSubstringLeaf(SubstringRope left, LeafRope right, Encoding encoding,
@Cached("createBinaryProfile()") ConditionProfile sameCodeRangeProfile,
@Cached("createBinaryProfile()") ConditionProfile brokenCodeRangeProfile,
@Cached("createBinaryProfile()") ConditionProfile isLeftSingleByteOptimizableProfile) {
return concat(left, right, encoding, sameCodeRangeProfile, brokenCodeRangeProfile, isLeftSingleByteOptimizableProfile);
}

@Specialization(guards = { "!left.isEmpty()", "!right.isEmpty()", "!isMutableRope(left)" })
@Specialization(guards = { "!isMutableRope(left)" })
public Rope concat(Rope left, Rope right, Encoding encoding,
@Cached("createBinaryProfile()") ConditionProfile sameCodeRangeProfile,
@Cached("createBinaryProfile()") ConditionProfile brokenCodeRangeProfile,

0 comments on commit 079efd4

Please sign in to comment.