Here are two definitions both achieving the same result:
def sendTrigger(teamId:Long, data:String) {
EngineSync.browserSockets.collect{ case ((i,(u,t)),s) => if(t==teamId) { s.send(data) } }
}
def sendTrigger(teamId:Long, data:String) {
EngineSync.browserSockets.foreach{ case ((i,(u,t)),s) => if(t==teamId) { s.send(data) } }
}
What’s happening is I am looping through a list of sockets and filtering them to send data. Being a newbie to Scala, I am concerned about performance when this begins to scale. From what I understand foreach performance is poor compared to other methods, does anyone know if collect would fare better or if this is the wrong approach entirely?
Looping through a fair sized collection vs. performing network IO (at least when blocking) are entirely different scale operations, therefore I would not worry about performance issures at this phase.
If you really care about performance when scaling massively:
Actor(and maybe useFutures in clients to hide the Actors)