\chapter{Performance}
\label{c:performance}

\textbf{Just because of the stage of testing there are design notes for
the tests as well as commentary on them.}

Performance has been of secondary importance for most of this project.
The driving for has been to get the features working, the only performance
requirements were to make sure the tests for correctness rain in a reasonable
amount of time.
Still this is an implementation others could use for similar prototypes and
so the results still have some use.

\section{Test Set-Up}
Tests will be run on \CFA, C++ and Java.

C++ is the most comparable language because both it and \CFA use the same
framework, libunwind.
In fact the comparison is almost entirely a quality of implementation
comparison. \CFA's EHM has had significantly less time to be optimized and
does not generate its own assembly. It does have a slight advantage in that
there are some features it does not handle.

% Some languages I left out:
% Python: Its a scripting language, different
% uC++: Not well known and should the same results as C++, except for
%   resumption which should be the same.
\todo{Can we find a good language to compare resumptions in.}

All tests will be run inside a main loop which will perform the test
repeatedly. This is to avoid letting and start-up or tear-down time from
affecting the timing results.
This also means that tests cannot terminate the program, which does limit
how tests can be implemented. There are catch-alls to keep unhandled
exceptions from terminating the program.

The exceptions used in this test will always be a new exception based off of
the base exception. This should minimize and preformance differences based
on the object model.
Catch-alls will be done by catching the root exception type (not using \Cpp's
\code{C++}{catch(...)}).

Tests run in Java were not warmed because exception code paths should not be
hot.

\section{Tests}
\paragraph{Raise/Handle}
What is the basic cost to raise and handle an exception?

There are a number of factors that can effect this, for \CFA this includes
the type of raise,

Main loop, pass through a catch-all, call through some empty helper functions
to put frames on the stack then raise and exception.
\todo{Raise/Handle (or a similar test) could also test how much it costs to
search over things, not sure if that is a useful test.}

\paragraph{Unwinding}
Isolating the unwinding of the stack as much as possible.

This has the same set-up as the raise/handle test except the intermediate
stack frames contain either an object declaration with a destructor or a
try statement with no handlers except for a finally clause.

\paragraph{Enter/Leave}
What is the cost of entering and leaving a try block, even if no exception
is thrown?

This is the simplist pattern to test as it is a simple matter of entering
and leaving a try statement.

The only tunables here are which clauses are attached to the try block:
termination handlers, resumption handlers and finally clauses.

\paragraph{Re-throw and Conditional-Catch}
How expencive it is to run a non-exception type check for a handler?

In this case different languages approach this problem differently, either
through a re-throw or a conditional-catch.
Where \CFA uses its condition other languages will have to unconditionally
catch the exception then re-throw if the condition if the condition is false.

The set up is as follows: main loop, a catch-all exception handler,
a conditional catch and then the raise.

% We could do a Cforall test without the catch all and a new default handler
% that does a catch all.
As a point of comparison one of the raise/handle tests (which one?) has
same layout but never catches anything.

The main tunable in this test is how often the conditional-catch matches.

%\section{Cost in Size}
%Using exceptions also has a cost in the size of the executable.
%Although it is sometimes ignored
%
%There is a size cost to defining a personality function but the later problem
%is the LSDA which will be generated for every function.
%
%(I haven't actually figured out how to compare this, probably using something
%related to -fexceptions.)
