Before this change, the DEAD_CODE analysis only alerted on statements that follow:
- a return
- an unlabeled break
- an unlabeled continue
My change adds the following to that list:
- an IfStatement with an
elseStatement
, where both thethenStatement
and theelseStatement
are guaranteed to exit. - a DoStatement that is guaranteed to exit.
This could be pretty expensive, as the ExitDetector does a lot of work to detect if a block is guaranteed to exit.
How expensive?
I used mk-deep-functions-tests.sh
to generate a file with:
- 200 top-level functions
- each function consists of 2 for loops
- each for loop consists of 4 if statements, each with a
thenStatement
and anelseStatement
. - each of the 4
thenStatement
s andelseStatement
s consists of 2 inner if statements, each with athenStatement
and anelseStatement
. - each inner
thenStatement
andelseStatement
has 2 inner statements.
Each if statement has an elseStatement
, so that ExitDetector runs a lot. The resultant file is 96,201 lines long.
I measured analyzer times with time
. The following are the user
column numbers.
| run | current | new | | 1 | 6.519 | 6.042 | | 2 | 6.154 | 6.031 | | 3 | 6.080 | 6.069 | | 4 | 6.040 | 6.018 | | 5 | 6.080 | 6.015 | | avg* | 6.105 | 6.030 |
(average is of middle 3)
The new analyzer appears to actually just be within 1% faster than the current analyzer, which must just be within the margin of error. The new functionality seems to not hurt performance.