-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Optimize some application-related operations #9875
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
Conversation
test performance please |
performance test scheduled: 3 job(s) in queue, 1 running. |
Performance test finished successfully: Visit http://dotty-bench.epfl.ch/9875/ to see the changes. Benchmarks is based on merging with master (f4528ce) |
For typer/*.scala, we had 3.4M calls to widen, of which almost 3M were to the three cases that are now handled specially.
test performance please |
performance test scheduled: 3 job(s) in queue, 1 running. |
Performance test finished successfully: Visit http://dotty-bench.epfl.ch/9875/ to see the changes. Benchmarks is based on merging with master (f4528ce) |
case tp1: TypeParamRef if ctx.typerState.constraint.contains(tp1) => | ||
asContextFunctionType(TypeComparer.bounds(tp1).hiBound) | ||
case tp1 => | ||
if (isFunctionType(tp1) && tp1.typeSymbol.name.isContextFunction) tp1 | ||
if tp1.typeSymbol.name.isContextFunction && isFunctionType(tp1) then tp1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the old days, we would move the condition to pattern guard in order to avoid parens. Now we will do it to avoid then
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
This was surprisingly effective! Still not quite sure why.
I have the impression that type tests against traits are quite inefficient. Can somebody confirm or refute this? |
I did some benchmark, which seems to validate the following claim:
trait TA
trait TB extends TA
trait TC
class A
class B extends A with TC with TB
class C extends A with TC with TB
val b = new B
val c = new C
var objs: Array[A] = Array(b, c)
@Benchmark
def typeTestTrait(): Boolean = {
var res = false
var count = 0
while count < 1000 do
res = objs(count % 2).isInstanceOf[TA]
objs(0) = b
count += 1
res
}
@Benchmark
def typeTestClass(): Boolean = {
var res = false
var count = 0
while count < 1000 do
res = objs(count % 2).isInstanceOf[B]
objs(0) = b
count += 1
res
}
|
@liufengyun That's actually not so bad for the trait type tests. But there could be other variables to consider, like how many traits are inherited and in what order. I believe trait type test comes down to a linear scan through implemented traits. |
test performance please |
performance test scheduled: 1 job(s) in queue, 0 running. |
I am going to try to avoid having to widen before typeSymbol. This removes a common pitfall and should also help performance. |
Performance test finished successfully: Visit http://dotty-bench.epfl.ch/9875/ to see the changes. Benchmarks is based on merging with master (f4528ce) |
9a0199d
to
18dc149
Compare
test performance please |
performance test scheduled: 1 job(s) in queue, 0 running. |
The last performance test reverted all of the gains made for dotc (it kept some of the smaller gains in the other tests). So was this just noise? Reverting to original state and testing again. |
@liufengyun In your benchmark shouldn't you use " |
Performance test finished successfully: Visit http://dotty-bench.epfl.ch/9875/ to see the changes. Benchmarks is based on merging with master (f4528ce) |
test performance please |
performance test scheduled: 1 job(s) in queue, 0 running. |
@michelou That does not make much difference in the performance numbers. I guess JVM uses clever encoding of class tags to make class testing faster. |
Performance test finished successfully: Visit http://dotty-bench.epfl.ch/9875/ to see the changes. Benchmarks is based on merging with master (f4528ce) |
Use overrides as for stripTypeVar and stripAnnots, but combine the two in one method
fa88828
to
5396e71
Compare
test performance please |
performance test scheduled: 1 job(s) in queue, 0 running. |
Performance test finished successfully: Visit http://dotty-bench.epfl.ch/9875/ to see the changes. Benchmarks is based on merging with master (f4528ce) |
After trying many variants I conclude that the initial gain was mostly noise; but there are some small wins nevertheless |
No description provided.