Skip to content
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

Some results from profiling #1385

Open
jrudolph opened this issue Mar 14, 2019 · 3 comments
Open

Some results from profiling #1385

jrudolph opened this issue Mar 14, 2019 · 3 comments

Comments

@jrudolph
Copy link
Contributor

jrudolph commented Mar 14, 2019

Hi @olafurpg,

I spent a bit of time looking into the performance of scalafmt. See the
flame-graph below. I found a few things:

VirtualFile.value

That one was a mystery to me first, it amounts to 8% of total time. I guess the problem here is that Input is used as a key to many of the Maps. For some reason, scalafmt creates VirtualFiles in Scalafmt.format which means that every Map access with the VirtualFile as the key has to hash the complete code again?

TreeOps.getOwners

Removing the recursion seems to help and using a java.util.HashMap instead of a mutable.Map builder.

FormatOps.iter

Basically the same as TreeOps.getOwners.

getSplits

Screenshot from 2019-03-14 11-17-25

That red "Interpreter" frame is getSplits. It seems to mean that the JIT-compiler gave up on that method completely... It may be as you say:

* NOTE(olafurpg). The pattern match in this file has gotten out of hand. It's

Not sure how the pattern match could be restructured to make it easier for the JIT and for performance.

I'll open a PR for ideas about to improve the first three things. That will probably already improve performance somewhat.

flame-graph

@olafurpg
Copy link
Member

@jrudolph Thank you so much for this thorough investigation. I believe the Scalamt codebase is ripe for microoptimizations 👍 The code was written when I was just starting Scala a few years ago and hasn't changed so much since then 😅

I have also investigated several low-hanging opportunities to speed up Scalameta

I personally don't have much time to pursue these ideas but if somebody is interesting in making a contribution I will be happy to provide feedback and review.

@kitbellew
Copy link
Collaborator

@jrudolph can you share the steps how you generated this flame graph (and how you read it)?

@olafurpg
Copy link
Member

You can generate flame graphs with https://github.com/jvm-profiling-tools/async-profiler

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

No branches or pull requests

3 participants