Skip to content

Commit

Permalink
address reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
onebox-li committed Nov 10, 2023
1 parent 05fce43 commit 16151ac
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class WorkerInfo(
else null
var endpoint: RpcEndpointRef = null
// Cache the hash code for WorkerInfo
var hash = 0
private var hash = 0

def this(host: String, rpcPort: Int, pushPort: Int, fetchPort: Int, replicatePort: Int) {
this(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -312,25 +312,16 @@ class WorkerInfoSuite extends CelebornFunSuite {
val replicatePort = 9094
val workerInfo = new WorkerInfo(host, rpcPort, pushPort, fetchPort, replicatePort)

// origin hashCode()
var now = System.nanoTime()
// origin hashCode() logic
val state = Seq(host, rpcPort, pushPort, fetchPort, replicatePort)
val originHash = state.map(_.hashCode()).foldLeft(0)((a, b) => 31 * a + b)
var after = System.nanoTime()
println("WorkerInfo origin hash result = " + originHash + ", costs " + (after - now))

// hashCode() with while loop
now = System.nanoTime()
val hashCode1 = workerInfo.hashCode()
after = System.nanoTime()
println("WorkerInfo hashCode1 hash result = " + hashCode1 + ", costs " + (after - now))
assert(originHash === hashCode1)

// hashCode() with cache
now = System.nanoTime()
val hashCode2 = workerInfo.hashCode()
after = System.nanoTime()
println("WorkerInfo hashCode2 hash result = " + hashCode2 + ", costs " + (after - now))
assert(hashCode1 === hashCode2)
}
}

0 comments on commit 16151ac

Please sign in to comment.