Skip to content

Improve performance of tuple operations #7689

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 32 commits into from
Dec 19, 2019
Merged

Improve performance of tuple operations #7689

merged 32 commits into from
Dec 19, 2019

Conversation

brunnerant
Copy link
Contributor

@brunnerant brunnerant commented Dec 5, 2019

In this pull request, I made some extensive benchmarks of the current tuple operations (cons, concat, tail, map, zip, ...). I analyzed their performance and tried to understand what were the bottlenecks of the current implementation, and improved them.

Not surprisingly, it turns out that the most efficient way to implement them is to avoid conversions between tuple, iterators and arrays as much as possible because this is the main source of overhead.

For Tuple1 to Tuple22, making a big match on the tuple arity is what gives the best performance (but very ugly code unfortunately).
For TupleXXL, performing the operation on the array seems to be the way to go.

See @nicolasstucki, my semester project supervisor, for more information.

@brunnerant
Copy link
Contributor Author

test performance with #tuple-runtime : 0a33ad3

@brunnerant
Copy link
Contributor Author

brunnerant commented Dec 5, 2019

dotty.tools.dotc.CompilationTests.tastyBootstrap doesn't pass, but all the other tests do. Has anyone an idea of what could be causing this (because I'm not familiar with tasty at all) ?

@nicolasstucki nicolasstucki self-requested a review December 5, 2019 17:41
@nicolasstucki
Copy link
Contributor

You may have found a bug in the compiler. I would suggest using git bisect to find the commit where it started failing.

@brunnerant
Copy link
Contributor Author

Ok, I will do this.

@brunnerant
Copy link
Contributor Author

I identified the commit where it starts failing, it is e1a01d2. It probably has something to do with polymorphic lambdas so I will try to see if I can fix it.

@brunnerant
Copy link
Contributor Author

Ok, the problem was coming from dynamicMap. I was pattern matching using existential types, and then applying the polymorphic lambda to each tuple element. Maybe the compiler cannot infer the types correctly in this case, so what I did for now is that I cast everything to Object.

@brunnerant
Copy link
Contributor Author

Should we try to test the performance using the profile tuple-runtime, comparing against master ?

@nicolasstucki
Copy link
Contributor

test performance with #tuple-runtime

@dottybot
Copy link
Member

dottybot commented Dec 9, 2019

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

@nicolasstucki
Copy link
Contributor

@liufengyun did the benchmark run?

@liufengyun
Copy link
Contributor

There is a bug report lampepfl/bench#47 . However, I couldn't find any logs. I just rescheduled the job.

@liufengyun
Copy link
Contributor

Currently, it does not support profile names with a hyphen.

unknown profile: tuple

I renamed tuple-runtime to tupleRuntime, now the job is running.

@dottybot
Copy link
Member

Performance test finished successfully:

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

Benchmarks is based on merging with master (0e761ea)

@brunnerant
Copy link
Contributor Author

Ok, thanks for fixing it, I didn't know about the hyphen limitation !
Is there a way to launch the benchmarks on the master branch ?

Copy link
Contributor

@nicolasstucki nicolasstucki left a comment

Choose a reason for hiding this comment

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

Otherwise LGTM

@nicolasstucki
Copy link
Contributor

@liufengyun could you execute these benchmarks on master?

@brunnerant
Copy link
Contributor Author

brunnerant commented Dec 15, 2019

@liufengyun could you execute these benchmarks on master?

@liufengyun Is it possible to run them on both branches, to have a comparison in the same graph ? Thanks !

@liufengyun
Copy link
Contributor

Now they are added to the default profile: lampepfl/bench@2acb4ef

@nicolasstucki
Copy link
Contributor

test performance with #tupleRuntime: master 08613cb

@dottybot
Copy link
Member

performance test scheduled for master 08613cb: 2 job(s) in queue, 1 running.

@liufengyun liufengyun removed their assignment Dec 18, 2019
@dottybot
Copy link
Member

Performance test finished successfully:

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

Benchmarks is based on merging with master (e036f46)

@nicolasstucki nicolasstucki merged commit 2bacda6 into scala:master Dec 19, 2019
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.

4 participants