Skip to content

Instantly share code, notes, and snippets.

@srawlins
Last active May 3, 2016 21:58
Show Gist options
  • Save srawlins/13edfecd9deea6149c8b3ac004e47dc1 to your computer and use it in GitHub Desktop.
Save srawlins/13edfecd9deea6149c8b3ac004e47dc1 to your computer and use it in GitHub Desktop.
Performance of new DEAD_CODE analyses

Performance of new DEAD_CODE analyses

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 the thenStatement and the elseStatement 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?

Analysis

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 an elseStatement.
  • each of the 4 thenStatements and elseStatements consists of 2 inner if statements, each with a thenStatement and an elseStatement.
  • each inner thenStatement and elseStatement has 2 inner statements.

Each if statement has an elseStatement, so that ExitDetector runs a lot. The resultant file is 96,201 lines long.

Summary

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.

# Many imports; 2 shows per import; few shown used
###############################################################################
file1=deep-functions.dart
function_count=200
first_level_for_count=2
second_level_if_count=4
third_level_if_count=2
innermost_statement_count=2
echo '' > $file1
function add_innermost_statements () {
for l in `seq 1 $innermost_statement_count`; do
echo " a += $k + $l;" >> $file1
done
}
function add_third_level_ifs () {
for k in `seq 1 $second_level_if_count`; do
echo " if (a > $k) {" >> $file1
add_innermost_statements
echo " } else {" >> $file1
add_innermost_statements
echo " }" >> $file1
done
}
function add_second_level_ifs () {
for j in `seq 1 $second_level_if_count`; do
echo " if (a < $j) {" >> $file1
add_third_level_ifs
echo " } else {" >> $file1
add_third_level_ifs
echo " }" >> $file1
done
}
function add_first_level_fors () {
for f in `seq 1 $first_level_for_count`; do
echo " for (int f = 0; f < $f; f++) {" >> $file1
add_second_level_ifs
echo " }" >> $file1
done
}
for i in `seq 1 $function_count`; do
echo "void fn$i(int a, String s) {" >> $file1
add_first_level_fors
echo " print(s);" >> $file1
echo " fn$(($i % 2 + 1))(a + 7, s + 'X');" >> $file1
echo "}" >> $file1
echo "" >> $file1
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment