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

Performance optimization: only compute stack traces when needed #16616

Merged
merged 2 commits into from
Jan 6, 2023

Conversation

smarter
Copy link
Member

@smarter smarter commented Jan 4, 2023

I noticed that Throwable#fillInStackTrace (which is called from the constructor of Throwable) showed up while profiling the compiler. This is because several data structures we use (Diagnostic and TypeError) extend Exception. Since the stack trace is only used for debugging in some rare cases and is expensive to compute, it's worth avoiding it whenever possible. This can be done either by passing false to the writableStackTrace constructor parameter, by overriding Throwable#fillInStackTrace or by extending scala.util.control.NoStackTrace.

I ended up not touching Diagnostic in this PR because it will be changed in #16566 to not extend Exception.

@smarter
Copy link
Member Author

smarter commented Jan 4, 2023

test performance please

@dottybot
Copy link
Member

dottybot commented Jan 4, 2023

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

@smarter
Copy link
Member Author

smarter commented Jan 4, 2023

test performance please

@dottybot
Copy link
Member

dottybot commented Jan 4, 2023

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

@dottybot
Copy link
Member

dottybot commented Jan 4, 2023

Performance test finished successfully:

Visit https://dotty-bench.epfl.ch/16616/ to see the changes.

Benchmarks is based on merging with main (4a11252)

@smarter
Copy link
Member Author

smarter commented Jan 4, 2023

test performance please: 263eada b26878c

@dottybot
Copy link
Member

dottybot commented Jan 4, 2023

performance test scheduled for 263eada b26878c: 1 job(s) in queue, 1 running.

@dottybot
Copy link
Member

dottybot commented Jan 4, 2023

Performance test finished successfully:

Visit https://dotty-bench.epfl.ch/16616/ to see the changes.

Benchmarks is based on merging with main (4a11252)

1 similar comment
@dottybot
Copy link
Member

dottybot commented Jan 5, 2023

Performance test finished successfully:

Visit https://dotty-bench.epfl.ch/16616/ to see the changes.

Benchmarks is based on merging with main (4a11252)

Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

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

#16566 addresses the problem in a different way, by making Diagnostic not extend Exception anymore. I think that is cleaner, overall. There's no good reason why Diagnostic should be an exception. So I'd leave aside for now all changes to Diagnostic in order not to cause conflicts with that PR. The changes to TypeError LGTM.

Copy link
Contributor

@odersky odersky left a comment

Choose a reason for hiding this comment

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

#16566 addresses this problem in a different way, by not making Diagnostic extend Exception. I think that's cleaner overall. So I'd leave out changes to Diagnostic in order not to cause conflicts with #16566. The changes to TypeError LGTM. The changes to SuspendException seem unnecessary but won't hurt.

@odersky odersky assigned odersky and smarter and unassigned odersky Jan 5, 2023
TypeError extends Exception, but the stack trace is only needed for debugging
purposes, either when using -Ydebug or when investigating cyclic errors.
@smarter smarter enabled auto-merge January 6, 2023 18:31
@smarter smarter disabled auto-merge January 6, 2023 18:32
@smarter smarter merged commit d49c2d9 into scala:main Jan 6, 2023
@smarter smarter deleted the nostacktrace2 branch January 6, 2023 18:32
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.

None yet

4 participants