Skip to content

Commit 716d5ce

Browse files
committed
[SYSTEMDS-3805] Minor performance improvement scalar right indexing
For operations like as.scalar(data[i,1]), we now use a fast path which improved the performance for 10M iterations as follows: 1 rightIndex 5.513 10000000 (old) 1 rightIndex 4.717 10000000 (new) This is generally useful also for cases where there is no as.scalar. However, for the case as.scalar(data[i,1]) we should directly compile a new rixScalar instruction which look up the value, avoids matrixblock allocation, and gets rid of unnecessary createvar, cast, and rmvar instructions.
1 parent 0242557 commit 716d5ce

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/main/java/org/apache/sysds/runtime/instructions/cp/MatrixIndexingCPInstruction.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,16 @@ public void processInstruction(ExecutionContext ec) {
6262

6363
if( mo.isPartitioned() ) //via data partitioning
6464
resultBlock = mo.readMatrixPartition(ixrange.add(1));
65+
else if( ixrange.isScalar() ){
66+
MatrixBlock matBlock = mo.acquireReadAndRelease();
67+
resultBlock = new MatrixBlock(
68+
matBlock.get((int)ixrange.rowStart, (int)ixrange.colStart));
69+
}
6570
else //via slicing the in-memory matrix
6671
{
6772
//execute right indexing operation (with shallow row copies for range
6873
//of entire sparse rows, which is safe due to copy on update)
69-
MatrixBlock matBlock = ec.getMatrixInput(input1.getName());
74+
MatrixBlock matBlock = mo.acquireRead();
7075
resultBlock = matBlock.slice((int)ixrange.rowStart, (int)ixrange.rowEnd,
7176
(int)ixrange.colStart, (int)ixrange.colEnd, false, new MatrixBlock());
7277

0 commit comments

Comments
 (0)