source: doc/theses/andrew_beach_MMath/performance.tex @ e4da70b

ADTast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since e4da70b was 9698690, checked in by Andrew Beach <ajbeach@…>, 3 years ago

Andrew MMath: A bit more work on the performance chapter before I stick in the results.

  • Property mode set to 100644
File size: 6.3 KB
Line 
1\chapter{Performance}
2\label{c:performance}
3
4Performance has been of secondary importance for most of this project.
5Instead, the focus has been to get the features working. The only performance
6requirements is to ensure the tests for correctness run in a reasonable
7amount of time.
8
9\section{Test Set-Up}
10Tests will be run in \CFA, C++, Java and Python.
11In addition there are two sets of tests for \CFA,
12one for termination exceptions and once with resumption exceptions.
13
14C++ is the most comparable language because both it and \CFA use the same
15framework, libunwind.
16In fact, the comparison is almost entirely a quality of implementation
17comparison. \CFA's EHM has had significantly less time to be optimized and
18does not generate its own assembly. It does have a slight advantage in that
19there are some features it does not handle, through utility functions,
20but otherwise \Cpp has a significant advantage.
21
22Java is another very popular language with similar termination semantics.
23It is implemented in a very different environment, a virtual machine with
24garbage collection.
25It also implements the finally clause on try blocks allowing for a direct
26feature-to-feature comparison.
27As with \Cpp, Java's implementation is more mature, has more optimizations
28and more extra features.
29
30Python was used as a point of comparison because of the \CFA EHM's
31current performance goals, which is not be prohibitively slow while the
32features are designed and examined. Python has similar performance goals for
33creating quick scripts and its wide use suggests it has achieved those goals.
34
35Unfortunately there are no notable modern programming languages with
36resumption exceptions. Even the older programming languages with resumptions
37seem to be notable only for having resumptions.
38So instead resumptions are compared to a less similar but much more familiar
39feature, termination exceptions.
40
41All tests are run inside a main loop which will perform the test
42repeatedly. This is to avoids start-up or tear-down time from
43affecting the timing results.
44Most test were run 1 000 000 (a million) times.
45The Java versions of the test also run this loop an extra 1000 times before
46beginning to time the results to ``warm-up" the JVM.
47
48Timing is done internally, with time measured immediately before and
49immediately after the test loop. The difference is calculated and printed.
50
51The loop structure and internal timing means it is impossible to test
52unhandled exceptions in \Cpp and Java as that would cause the process to
53terminate.
54Luckily, performance on the ``give-up and kill the process" path is not
55critical.
56
57The exceptions used in these tests will always be a exception based off of
58the base exception. This requirement minimizes performance differences based
59on the object model used to repersent the exception.
60
61All tests were designed to be as minimal as possible while still preventing
62exessive optimizations.
63For example, empty inline assembly blocks are used in \CFA and \Cpp to
64prevent excessive optimizations while adding no actual work.
65
66% We don't use catch-alls but if we did:
67% Catch-alls are done by catching the root exception type (not using \Cpp's
68% \code{C++}{catch(...)}).
69
70\section{Tests}
71The following tests were selected to test the performance of different
72components of the exception system.
73The should provide a guide as to where the EHM's costs can be found.
74
75\paragraph{Raise and Handle}
76The first group of tests involve setting up
77So there is three layers to the test. The first is set up and a loop, which
78configures the test and then runs it repeatedly to reduce the impact of
79start-up and shutdown on the results.
80Each iteration of the main loop
81\begin{itemize}[nosep]
82\item Empty Function:
83The repeating function is empty except for the necessary control code.
84\item Destructor:
85The repeating function creates an object with a destructor before calling
86itself.
87\item Finally:
88The repeating function calls itself inside a try block with a finally clause
89attached.
90\item Other Handler:
91The repeating function calls itself inside a try block with a handler that
92will not match the raised exception. (But is of the same kind of handler.)
93\end{itemize}
94
95\paragraph{Cross Try Statement}
96The next group measures the cost of a try statement when no exceptions are
97raised. The test is set-up, then there is a loop to reduce the impact of
98start-up and shutdown on the results.
99In each iteration, a try statement is executed. Entering and leaving a loop
100is all the test wants to do.
101\begin{itemize}[nosep]
102\item Handler:
103The try statement has a handler (of the matching kind).
104\item Finally:
105The try statement has a finally clause.
106\end{itemize}
107
108\paragraph{Conditional Matching}
109This group of tests checks the cost of conditional matching.
110Only \CFA implements the language level conditional match,
111the other languages must mimic with an ``unconditional" match (it still
112checks the exception's type) and conditional re-raise if it was not supposed
113to handle that exception.
114\begin{itemize}[nosep]
115\item Match All:
116The condition is always true. (Always matches or never re-raises.)
117\item Match None:
118The condition is always false. (Never matches or always re-raises.)
119\end{itemize}
120
121%\section{Cost in Size}
122%Using exceptions also has a cost in the size of the executable.
123%Although it is sometimes ignored
124%
125%There is a size cost to defining a personality function but the later problem
126%is the LSDA which will be generated for every function.
127%
128%(I haven't actually figured out how to compare this, probably using something
129%related to -fexceptions.)
130
131\section{Results}
132Each test is was run five times, the best and worst result were discarded and
133the remaining values were averaged.
134
135In cases where a feature is not supported by a language the test is skipped
136for that language. Similarly, if a test is does not change between resumption
137and termination in \CFA, then only one test is written and the result
138was put into the termination column.
139
140\begin{tabular}{|l|c c c c c|}
141\hline
142              & \CFA (Terminate) & \CFA (Resume) & \Cpp & Java & Python \\
143\hline
144Raise Empty   & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
145Raise D'tor   & 0.0 & 0.0 & 0.0 & N/A & N/A \\
146Raise Finally & 0.0 & 0.0 & N/A & 0.0 & 0.0 \\
147Raise Other   & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
148Cross Handler & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
149Cross Finally & 0.0 & N/A & N/A & 0.0 & 0.0 \\
150Match All     & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
151Match None    & 0.0 & 0.0 & 0.0 & 0.0 & 0.0 \\
152\hline
153\end{tabular}
Note: See TracBrowser for help on using the repository browser.