Skip to content

Fix #1619: Reduce collision rate in NameTable #3768

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

Merged
merged 1 commit into from
Apr 9, 2018

Conversation

allanrenucci
Copy link
Contributor

Rebased #1727

@allanrenucci
Copy link
Contributor Author

test performance please

@dottybot
Copy link
Member

dottybot commented Jan 5, 2018

performance test scheduled: 4 job(s) in queue, 1 running.

private def hashValue(cs: Array[Char], offset: Int, len: Int): Int = {
var i = offset
var hash = 0
while (i < len + offset) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Compute len+offset only once.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pretty sure the jvm should figure it out :).

@dottybot
Copy link
Member

dottybot commented Jan 5, 2018

Performance test finished successfully:

Visit http://dotty-bench.epfl.ch/3768/ to see the changes.

Benchmarks is based on merging with master (5b9dfe5)

@@ -549,7 +549,8 @@ object Names {
private def hashValue(cs: Array[Char], offset: Int, len: Int): Int = {
var i = offset
var hash = 0
while (i < len + offset) {
val until = offset + len
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I doubt this has any effect. Hoisting constant expressions out of loops is among the easiest optimizations of a JIT compiler. So I think it's better to revert this commit.

Otherwise LGTM.

@smarter
Copy link
Member

smarter commented Jan 7, 2018

Not sure if we should merge this. It seems to have negligible effects on our benchmarks, but the corresponding scalac PR (scala/scala#5474) hasn't been merged because of a %2 slowdown on scalap. Unless someone can find a benchmark where we actually do better with this PR in, what's the point anyway?

@odersky
Copy link
Contributor

odersky commented Jan 7, 2018

The situation between dotc and scalac is a bit different because with semantic names we have on average much shorter names in the NameTable. So the fix is likely less costly (and potentially also less useful) than for scalac. I think it would be good to benchmark scalap and if that does not show a slow-down we can go ahead and merge.

I believe the benefit of this fix is not so much a speedup on average but avoiding outliers.

@smarter
Copy link
Member

smarter commented Jan 8, 2018

@retronym How come scala/scala#5474 changes the magic prime used in the hashcode from 41 to 31?

@retronym
Copy link
Member

retronym commented Jan 8, 2018

I wanted to use the same values as java.lang.String. I think it makes sense to go ahead with this change, even if you're seeing flat benchmark results.

@retronym
Copy link
Member

retronym commented Jan 8, 2018

For reference, we ended up merging scala/scala#5506 instead, which avoids needlessly creating new names for fresh type symbols created during overload resolution.

@allanrenucci
Copy link
Contributor Author

test performance please

@dottybot
Copy link
Member

dottybot commented Apr 1, 2018

performance test scheduled: 2 job(s) in queue, 1 running.

@dottybot
Copy link
Member

dottybot commented Apr 1, 2018

Performance test finished successfully:

Visit http://dotty-bench.epfl.ch/3768-1/ to see the changes.

Benchmarks is based on merging with master (14187e2)

@allanrenucci
Copy link
Contributor Author

test performance please

@dottybot
Copy link
Member

dottybot commented Apr 1, 2018

performance test scheduled: 1 job(s) in queue, 1 running.

@dottybot
Copy link
Member

dottybot commented Apr 2, 2018

Performance test finished successfully:

Visit http://dotty-bench.epfl.ch/3768-2/ to see the changes.

Benchmarks is based on merging with master (14187e2)

@allanrenucci
Copy link
Contributor Author

test performance please

@dottybot
Copy link
Member

dottybot commented Apr 9, 2018

performance test scheduled: 1 job(s) in queue, 0 running.

@dottybot
Copy link
Member

dottybot commented Apr 9, 2018

Performance test finished successfully:

Visit http://dotty-bench.epfl.ch/3768-3/ to see the changes.

Benchmarks is based on merging with master (962b4bf)

@allanrenucci allanrenucci merged commit 1f67c00 into scala:master Apr 9, 2018
@allanrenucci allanrenucci deleted the fix-#1619 branch April 9, 2018 16:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants