Commit d49c2d9
authored
Performance optimization: only compute stack traces when needed (#16616)
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`.File tree
2 files changed
+16
-3
lines changed- compiler/src/dotty/tools/dotc
- core
2 files changed
+16
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
| 19 | + | |
19 | 20 | | |
20 | 21 | | |
21 | 22 | | |
| |||
105 | 106 | | |
106 | 107 | | |
107 | 108 | | |
108 | | - | |
| 109 | + | |
109 | 110 | | |
110 | 111 | | |
111 | 112 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
15 | | - | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
18 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
19 | 31 | | |
20 | 32 | | |
21 | 33 | | |
| |||
164 | 176 | | |
165 | 177 | | |
166 | 178 | | |
167 | | - | |
| 179 | + | |
168 | 180 | | |
169 | 181 | | |
170 | 182 | | |
| |||
0 commit comments