You can simplify this code as 

    taskEnd.taskMetrics.shuffleReadMetrics.foreach { shuffleRead =>
      y.shuffleRead => shuffleRead.remoteBytesRead
    }

And similarly for shuffle writes.