New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Reduce frequency of checkcast in bytecode #1377
Comments
Imported From: https://issues.scala-lang.org/browse/SI-1377?orig=1 |
@ijuma said: Here's an improved version. Still, given how optimized casts are, it's perfectly possible that the code in the benchmark to prevent HotSpot from optimising the method call completely dominates the benchmark. Also, there's the risk that the f call could be optimised completely. def f(i: Iterator[_]) = i.hasNext
def main(args: Array[String]) {
test()
}
def test() {
var i = 0
while (i < 10) {
val time = System.currentTimeMillis
val result = inner()
i += 1
println("Time: " + (System.currentTimeMillis - time))
println("Value: " + result)
}
}
def inner() = {
//val empty = Iterator.empty // checkcast occurs within loop
val empty: Iterator[_] = Iterator.empty // checkcast outside loop
var i = 0L
while (i < 10000000000L) {
f(empty)
i += 1
}
i
}
} Using the version with the cast and without took the same time in my machine. Interestingly, both versions take about 4.8s after the initial JIT of the inner method, but from the 3rd iteration onwards (when the JIT recompiles the inner method) they both take 7.1s. Seems like HotSpot tries to optimise the code a bit more, but makes it worse. At any rate, both versions perform the same. |
@ijuma said: http://www.nabble.com/FYI:-Scala-2.7.2.RC1-regression-td19080798.html |
@ijuma said: |
@lrytz said: |
Ricky Clarkson (ricky_clarkson) said: |
@ijuma said: http://www.nabble.com/Is-there-a-memory-leak-in-2.7.2-Actors--td20949656i20.html#a20985898 |
@odersky said: |
When we use "def = new { ... }",
the generated bytecode appears to have too little type information, and too many casts. Same for "val", and for "new with { ... }"
Here's a minimal example:-
A real-world example is the trait Iterator, and the Iterator members
None of these explicitly declare the return type, so java.lang.Object and checkcast occur.
Here's an informal benchmark that shows the impact this can have on performance:
The text was updated successfully, but these errors were encountered: