[dac16a0] | 1 | \chapter{Performance} |
---|
| 2 | \label{c:performance} |
---|
| 3 | |
---|
| 4 | \textbf{Just because of the stage of testing there are design notes for |
---|
| 5 | the tests as well as commentary on them.} |
---|
| 6 | |
---|
| 7 | Performance has been of secondary importance for most of this project. |
---|
[b6749fd] | 8 | Instead, the goal has been to get the features working. |
---|
| 9 | The only performance |
---|
| 10 | requirements is to ensure the exception tests for correctness ran in a reasonable |
---|
[dac16a0] | 11 | amount of time. |
---|
[b6749fd] | 12 | Much of the implementation is still reasonable and could be used for similar prototypes. |
---|
| 13 | Hence, |
---|
| 14 | the work still has some use. |
---|
| 15 | To get a rough idea about the \CFA implementation, tests are run on \CFA, C++ and Java, which have similar termination-handling exceptions. |
---|
| 16 | Tests are also run on \CFA and uC++, which has similar resumption-handling exceptions. |
---|
[dac16a0] | 17 | |
---|
[b6749fd] | 18 | \section{Termination Comparison} |
---|
[dac16a0] | 19 | C++ is the most comparable language because both it and \CFA use the same |
---|
| 20 | framework, libunwind. |
---|
[b6749fd] | 21 | In fact, the comparison is almost entirely a quality of implementation |
---|
[dac16a0] | 22 | comparison. \CFA's EHM has had significantly less time to be optimized and |
---|
| 23 | does not generate its own assembly. It does have a slight advantage in that |
---|
| 24 | there are some features it does not handle. |
---|
| 25 | |
---|
[b6749fd] | 26 | The Java comparison is an opportunity to compare a managed memory model with unmanaged, |
---|
| 27 | to see if there are any effects related to the exception model. |
---|
[dac16a0] | 28 | |
---|
[b6749fd] | 29 | \subsection{Test Set-Up} |
---|
| 30 | All tests are run inside a main loop that performs the test |
---|
| 31 | repeatedly. This design avoids start-up or tear-down time from |
---|
[dac16a0] | 32 | affecting the timing results. |
---|
[b6749fd] | 33 | A consequence is that tests cannot terminate the program, which does limit |
---|
[dac16a0] | 34 | how tests can be implemented. There are catch-alls to keep unhandled |
---|
[b6749fd] | 35 | exceptions from terminating tests. |
---|
[dac16a0] | 36 | |
---|
[b6749fd] | 37 | The exceptions used in this test are always a new exception based off of |
---|
| 38 | the base exception. This requirement minimizes performance differences based |
---|
[dac16a0] | 39 | on the object model. |
---|
[b6749fd] | 40 | Catch-alls are done by catching the root exception type (not using \Cpp's |
---|
[dac16a0] | 41 | \code{C++}{catch(...)}). |
---|
| 42 | |
---|
| 43 | Tests run in Java were not warmed because exception code paths should not be |
---|
| 44 | hot. |
---|
| 45 | |
---|
[b6749fd] | 46 | \subsection{Tests} |
---|
| 47 | The following tests capture the most important aspects of exception handling and should provide |
---|
| 48 | a reasonable guide to programmers of where EHM costs occur. |
---|
| 49 | |
---|
[dac16a0] | 50 | \paragraph{Raise/Handle} |
---|
| 51 | What is the basic cost to raise and handle an exception? |
---|
| 52 | |
---|
[b6749fd] | 53 | There are a number of factors that can effect this. |
---|
| 54 | For \CFA this includes |
---|
[dac16a0] | 55 | the type of raise, |
---|
| 56 | |
---|
| 57 | Main loop, pass through a catch-all, call through some empty helper functions |
---|
| 58 | to put frames on the stack then raise and exception. |
---|
| 59 | \todo{Raise/Handle (or a similar test) could also test how much it costs to |
---|
| 60 | search over things, not sure if that is a useful test.} |
---|
| 61 | |
---|
| 62 | \paragraph{Unwinding} |
---|
| 63 | Isolating the unwinding of the stack as much as possible. |
---|
| 64 | |
---|
| 65 | This has the same set-up as the raise/handle test except the intermediate |
---|
| 66 | stack frames contain either an object declaration with a destructor or a |
---|
[b6749fd] | 67 | @try@ statement with no handlers except and a @finally@ clause. |
---|
[dac16a0] | 68 | |
---|
| 69 | \paragraph{Enter/Leave} |
---|
| 70 | What is the cost of entering and leaving a try block, even if no exception |
---|
| 71 | is thrown? |
---|
| 72 | |
---|
[b6749fd] | 73 | The test is a simple matter of entering |
---|
[dac16a0] | 74 | and leaving a try statement. |
---|
| 75 | |
---|
| 76 | The only tunables here are which clauses are attached to the try block: |
---|
| 77 | termination handlers, resumption handlers and finally clauses. |
---|
| 78 | |
---|
| 79 | \paragraph{Re-throw and Conditional-Catch} |
---|
[b6749fd] | 80 | How expensive it is to run a non-exception type check for a handler? |
---|
[dac16a0] | 81 | |
---|
| 82 | In this case different languages approach this problem differently, either |
---|
| 83 | through a re-throw or a conditional-catch. |
---|
[b6749fd] | 84 | Where \CFA uses its condition, other languages must unconditionally |
---|
[dac16a0] | 85 | catch the exception then re-throw if the condition if the condition is false. |
---|
| 86 | |
---|
| 87 | The set up is as follows: main loop, a catch-all exception handler, |
---|
| 88 | a conditional catch and then the raise. |
---|
| 89 | |
---|
| 90 | % We could do a Cforall test without the catch all and a new default handler |
---|
| 91 | % that does a catch all. |
---|
[b6749fd] | 92 | As a point of comparison, one of the raise/handle tests (which one?) has |
---|
[dac16a0] | 93 | same layout but never catches anything. |
---|
| 94 | |
---|
| 95 | The main tunable in this test is how often the conditional-catch matches. |
---|
| 96 | |
---|
| 97 | %\section{Cost in Size} |
---|
| 98 | %Using exceptions also has a cost in the size of the executable. |
---|
| 99 | %Although it is sometimes ignored |
---|
| 100 | % |
---|
| 101 | %There is a size cost to defining a personality function but the later problem |
---|
| 102 | %is the LSDA which will be generated for every function. |
---|
| 103 | % |
---|
| 104 | %(I haven't actually figured out how to compare this, probably using something |
---|
| 105 | %related to -fexceptions.) |
---|
[b6749fd] | 106 | |
---|
| 107 | |
---|
| 108 | \section{Resumption Comparison} |
---|
| 109 | % Some languages I left out: |
---|
| 110 | % Python: Its a scripting language, different |
---|
| 111 | % uC++: Not well known and should the same results as C++, except for |
---|
| 112 | % resumption which should be the same. |
---|
| 113 | \todo{Can we find a good language to compare resumptions in.} |
---|