Commit bbab019478f7a71aceceebf76e9dca80e1fad47e

Authored by Geoffrey Challen
1 parent 6372e677

Working.

.ispell_english
@@ -2,4 +2,11 @@ Android @@ -2,4 +2,11 @@ Android
2 APIs 2 APIs
3 app 3 app
4 apps 4 apps
  5 +Endgames
  6 +JSON
  7 +outsourced
  8 +pre
  9 +runtime's
  10 +smartphone
  11 +smartphones
5 Wifi 12 Wifi
certainty.tex
@@ -2,85 +2,88 @@ @@ -2,85 +2,88 @@
2 \label{sec-certainty} 2 \label{sec-certainty}
3 3
4 While \texttt{maybe} allows programmers to specify multiple alternatives, 4 While \texttt{maybe} allows programmers to specify multiple alternatives,
5 -ultimately only one alternative may be used. Either a single, globally best  
6 -alternative must be chosen, or a deterministic decision procedure must be  
7 -selected. Before discussing options for \textit{adapting} an app to its  
8 -runtime environment, we first explain our runtime's support for 5 +ultimately at runtime only one alternative can be executed. Either a single,
  6 +globally-optimal alternative must be determined, or a deterministic decision
  7 +procedure must be developed. Before discussing options for \textit{adapting}
  8 +an app to its runtime environment, we first explain our runtime's support for
9 \texttt{maybe} alternatives, including \textit{a posteriori} evaluation and 9 \texttt{maybe} alternatives, including \textit{a posteriori} evaluation and
10 -data-collection. Then, we discuss how \texttt{maybe} testing enables a 10 +data collection. Then, we discuss how \texttt{maybe} testing enables a
11 variety of different adaptation patterns. 11 variety of different adaptation patterns.
12 12
13 -\subsection{Evaluating Alternatives} The optional \texttt{evaluate} block of  
14 -a \texttt{maybe} statement allows programmers to provide app-specific  
15 -\textit{a posteriori} evaluation logic. However, in many cases, we expect  
16 -that \texttt{maybe} statements will be used to achieve common objectives such  
17 -as improving performance or saving energy. To steamline application  
18 -development, our current system assesses \texttt{maybe} statements without a  
19 -\texttt{better} block in terms of both energy and performance. In cases where  
20 -one alternative is a clear winner in terms of both energy and performance,  
21 -that alternative will be used---although note that this selection may still  
22 -need to be time-varying since it may depend on exogenous factors.  
23 -  
24 -Cases where \texttt{maybe} blocks provide an energy-performance tradeoff  
25 -require more investigation to handle. We are exploring several options,  
26 -including collapsing both metrics into a single score by computing the  
27 -energy-delay product of each alternative, or allowing users to set a single  
28 -per-app preference indicating whether energy or performance should determine  
29 -\texttt{maybe} alternative selection.  
30 -  
31 -When \texttt{maybe} statements include a \texttt{better} block, their custom  
32 -evaluation logic is expected to merge any relevant factors into a single  
33 -score, although \texttt{better} blocks can still record other relevant  
34 -information to aid in understanding app behavior. Specifically,  
35 -\texttt{better} blocks return a JSON object where the ``score'' key is used  
36 -as the score but all other keys are recorded for later analysis. Our standard  
37 -energy and performance \texttt{better} block records energy and performance 13 +\subsection{Evaluating Alternatives}
  14 +
  15 +The optional \texttt{evaluate} block of a \texttt{maybe} statement allows
  16 +programmers to provide app-specific \textit{a posteriori} evaluation logic.
  17 +However, in many cases, we expect that \texttt{maybe} statements will be used
  18 +to achieve common objectives such as improving performance or saving energy.
  19 +To streamline application development, our current system evaluates
  20 +\texttt{maybe} statements without a \texttt{evaluate} block by measuring both
  21 +energy and performance. In cases where one alternative optimizes both, that
  22 +alternative will be used---although the decision may still be time-varying
  23 +due to dependence on time-varying factors such as network availability.
  24 +
  25 +\sloppypar{Cases where \texttt{maybe} statements provide an
  26 +energy-performance tradeoff require more investigation. We are exploring
  27 +several options, including collapsing both metrics into a single score by
  28 +computing the energy-delay product (EDP) of each alternative, or allowing
  29 +users to set a per-app preference indicating whether energy or performance
  30 +should determine \texttt{maybe} alternative selection.}
  31 +
  32 +When \texttt{maybe} statements include a \texttt{evaluate} block, their
  33 +custom evaluation logic must merge any relevant factors into a single score,
  34 +although \texttt{evaluate} blocks can still record other relevant information
  35 +to aid in understanding app behavior. Specifically, while the \texttt{score}
  36 +value is used to evaluate the alternative, the entire JSON object returned by
  37 +the \texttt{evaluate} block is recorded for later analysis. Our standard
  38 +energy and performance \texttt{evaluate} block records energy and performance
38 separately in the JSON object but combines them as required into a single 39 separately in the JSON object but combines them as required into a single
39 -score. Note that because the \texttt{better} block delivers information to 40 +score. Note that because the \texttt{evaluate} block delivers information to
40 the developer through the \texttt{maybe} service, as described below, 41 the developer through the \texttt{maybe} service, as described below,
41 \texttt{maybe} statements can be connected with end-to-end app performance 42 \texttt{maybe} statements can be connected with end-to-end app performance
42 -metrics that would normally not be visible on the device. \texttt{better}  
43 -blocks may also want to query the user directly, and we are considering ways  
44 -to adjust their semantics to make this possible.  
45 -  
46 -In some cases we expect that \texttt{better} blocks may need to know which  
47 -alternative was executed in order to determine the score---for example, if  
48 -the two alternatives produce different quality output while trading off  
49 -performance or energy consumption. The simplest solution is to have each  
50 -alternative set a variable indicating that it was used, but we believe that  
51 -eventually including some form of labeling syntax for \texttt{maybe}  
52 -alternatives may be beneficial.  
53 -  
54 -As a side note, if a \texttt{maybe} alternative encounters an error, the  
55 -system will automatically both retry another alternative and give the  
56 -error-generating alternative the worst possible score. In this case any  
57 -custom evaluation logic will not be executed for the failing alternative.  
58 -While \texttt{maybe} is not designed as a way to avoid errors, the existence  
59 -of other alternatives provides our system with a way to work around  
60 -failures sometimes caused by environmental factors.  
61 -  
62 -A final question concerns when a \texttt{maybe} alternative should be assessed.  
63 -In some  
64 -cases it may be appropriate for post-mortem evaluation to happen immediately after execution.  
65 -In others, it may be necessary to execute the same alternative over a period  
66 -of time to perform a fair comparison. As described previously,  
67 -\texttt{better} blocks can indicate explicitly whether or not to continue  
68 -evaluating the alternative, and we are determining how to make a similar  
69 -choice available to \texttt{maybe} statements that do not use customized  
70 -evaluation logic. In both cases, however, the \texttt{maybe} system allows  
71 -developers continuous per-statement control over alternative evaluation and  
72 -selection as described in more detail later in this section. 43 +metrics that would normally not be visible on the device. \texttt{evaluate}
  44 +blocks may also want to query the user directly, and we are exploring ways to
  45 +make this possible.
  46 +
  47 +In some cases we expect that \texttt{evaluate} blocks may need to know which
  48 +alternative was executed to determine the score---for example, if the two
  49 +alternatives produce different quality output. The simplest solution is to
  50 +have each alternative set a variable indicating that it was used, but we
  51 +believe that eventually including some form of labeling syntax for
  52 +\texttt{maybe} alternatives may be beneficial.
  53 +
  54 +If a \texttt{maybe} alternative throws an error, the system will bypass the
  55 +\texttt{evaluate} block and give it the worst possible score. By integrating
  56 +a form of record-and-replay~\cite{FIXME}, it may also be possible to roll
  57 +back the failed alternatives changes and retry another alternative.
  58 +\texttt{maybe} is intended to enable adaptation, not avoid errors, but the
  59 +existence of other alternatives provides our system with a way to work around
  60 +failures caused by uncertainty. Resistance to errors may also encourage
  61 +developers to use \texttt{maybe} statements to prototype alternatives to
  62 +existing well-tested code.
  63 +
  64 +A final question concerns when a \texttt{maybe} alternative should be
  65 +assessed. In some cases it may be appropriate for \textit{a posteriori}
  66 +evaluation to happen immediately after execution. In others, it may be
  67 +necessary to execute the same alternative over a period of time to perform a
  68 +fair comparison. As described previously, \texttt{evaluate} blocks can
  69 +indicate explicitly whether or not to continue evaluating the alternative,
  70 +and we are determining how to make a similar choice available to
  71 +\texttt{maybe} statements that do not use customized evaluation logic. In
  72 +addition, \texttt{evaluate} blocks can store state across multiple
  73 +alternative executions allowing them to evaluate not only micro- but also
  74 +macro-level decisions. In both cases, however, the \texttt{maybe} system
  75 +allows developers continuous per-statement control over alternative
  76 +evaluation and selection as described in more detail later in this section.
73 77
74 \subsection{\texttt{\large maybe} Alternative Testing} 78 \subsection{\texttt{\large maybe} Alternative Testing}
75 79
76 -We next describe the pre- and post-deployment testing that helps developers to  
77 -design an \textit{adaptation} policy, a strategy for ultimately selecting  
78 -between alternatives. While the \texttt{maybe} system  
79 -automates many of the tedious tasks normally associated with large-scale  
80 -testing, we still provide ways for the developer to guide and even override  
81 -any step in the process. 80 +We next describe the pre- and post-deployment testing that helps developers
  81 +to design an \textit{adaptation} policy, a strategy for ultimately selecting
  82 +between alternatives. While the \texttt{maybe} system automates many of the
  83 +tedious tasks normally associated with large-scale testing, we still provide
  84 +ways for the developer to guide and control any step in the process.
82 85
83 -\subsubsection{Runtime Control} 86 +\subsubsection{Runtime control}
84 87
85 To begin, we briefly outline how our Android prototype system implements the 88 To begin, we briefly outline how our Android prototype system implements the
86 \texttt{maybe} construct. We (1) rewrite each \texttt{maybe} code block to an 89 \texttt{maybe} construct. We (1) rewrite each \texttt{maybe} code block to an
@@ -108,7 +111,7 @@ so by periodically resetting the value using another \texttt{maybe} @@ -108,7 +111,7 @@ so by periodically resetting the value using another \texttt{maybe}
108 statement. This ensures that \texttt{maybe} variables only change when the 111 statement. This ensures that \texttt{maybe} variables only change when the
109 developer expects them to. 112 developer expects them to.
110 113
111 -\subsubsection{Simulation or Emulation} 114 +\subsubsection{Simulation or emulation}
112 115
113 Pre-deployment simulation or emulation may provide a way to efficiently 116 Pre-deployment simulation or emulation may provide a way to efficiently
114 assess \texttt{maybe} blocks without involving users. Building simulation 117 assess \texttt{maybe} blocks without involving users. Building simulation
@@ -127,7 +130,7 @@ choices of which \texttt{maybe} statements may have a significant impact on @@ -127,7 +130,7 @@ choices of which \texttt{maybe} statements may have a significant impact on
127 performance and should be assessed first. Other \texttt{maybe} statements 130 performance and should be assessed first. Other \texttt{maybe} statements
128 can be assessed later or eliminated altogether. 131 can be assessed later or eliminated altogether.
129 132
130 -\subsubsection{Split Testing} 133 +\subsubsection{Split testing}
131 134
132 Eventually code containing a number of \texttt{maybe} statements will be 135 Eventually code containing a number of \texttt{maybe} statements will be
133 deployed on thousands or millions of devices. At this point, large-scale 136 deployed on thousands or millions of devices. At this point, large-scale
@@ -150,10 +153,10 @@ set, the \texttt{maybe} system records: @@ -150,10 +153,10 @@ set, the \texttt{maybe} system records:
150 \item what \texttt{maybe} was reached; 153 \item what \texttt{maybe} was reached;
151 154
152 \item what alternative was used and why. This includes all environmental 155 \item what alternative was used and why. This includes all environmental
153 -features used to make the selection, as well as any other available 156 +features used to make the decision, as well as any other available
154 provenance information; 157 provenance information;
155 158
156 -\item what \texttt{better} block evaluated the alternative, and the entire 159 +\item what \texttt{evaluate} block evaluated the alternative, and the entire
157 JSON object it returned, including the score; 160 JSON object it returned, including the score;
158 161
159 \item and a variety of other environmental and configuration parameters 162 \item and a variety of other environmental and configuration parameters
@@ -167,7 +170,7 @@ This dataset is periodically uploaded to the \texttt{maybe} server by the @@ -167,7 +170,7 @@ This dataset is periodically uploaded to the \texttt{maybe} server by the
167 \texttt{maybe} service and used to drive the adaptation approaches discussed 170 \texttt{maybe} service and used to drive the adaptation approaches discussed
168 next. 171 next.
169 172
170 -\subsubsection{Simultaneous Split Testing} 173 +\subsubsection{Simultaneous split testing}
171 174
172 While large-scale split testing is intended to provide good coverage over all 175 While large-scale split testing is intended to provide good coverage over all
173 possible sources of uncertainty we have discussed, it still normally requires 176 possible sources of uncertainty we have discussed, it still normally requires
@@ -193,7 +196,7 @@ factors and uncertainties. We continue by discussing how the dataset @@ -193,7 +196,7 @@ factors and uncertainties. We continue by discussing how the dataset
193 generated by post-deployment testing can be consumed to determine how to 196 generated by post-deployment testing can be consumed to determine how to
194 correctly choose \texttt{maybe} alternatives at runtime. 197 correctly choose \texttt{maybe} alternatives at runtime.
195 198
196 -\subsubsection{Simple Cases} 199 +\subsubsection{Simple cases}
197 200
198 In the simplest case, testing may reveal that a single alternative performs 201 In the simplest case, testing may reveal that a single alternative performs
199 the best on all devices, for all users, at all times. In this situation, the 202 the best on all devices, for all users, at all times. In this situation, the
@@ -202,8 +205,8 @@ testing of that alternative and even automatically rewrite that portion of @@ -202,8 +205,8 @@ testing of that alternative and even automatically rewrite that portion of
202 code to remove the \texttt{maybe} statement. However, it is also possible 205 code to remove the \texttt{maybe} statement. However, it is also possible
203 that the situation may change in the future when a new device, or Android 206 that the situation may change in the future when a new device, or Android
204 version, or battery technology is introduced, and so the programmer may also 207 version, or battery technology is introduced, and so the programmer may also
205 -choose to preserve the alternatives to enable later retesting and possible  
206 -adaptation. 208 +choose to preserve the alternatives to enable continuous adaptation as
  209 +described in Section~\ref{subsec-continuous}.
207 210
208 The slightly more complicated case is when testing reveals that alternatives 211 The slightly more complicated case is when testing reveals that alternatives
209 provide stable tradeoffs between energy and performance---one block always 212 provide stable tradeoffs between energy and performance---one block always
@@ -215,7 +218,7 @@ each user. However, the stability of the alternatives' outcomes means that @@ -215,7 +218,7 @@ each user. However, the stability of the alternatives' outcomes means that
215 once an energy or performance policy decision has been made, the choice of 218 once an energy or performance policy decision has been made, the choice of
216 alternative has also been made. 219 alternative has also been made.
217 220
218 -\subsubsection{Static Adaptation} 221 +\subsubsection{Static adaptation}
219 222
220 In the more complicated cases, testing reveals that the choice of alternative 223 In the more complicated cases, testing reveals that the choice of alternative
221 depends on some subset of the factors driving uncertainty in mobile systems 224 depends on some subset of the factors driving uncertainty in mobile systems
@@ -233,7 +236,7 @@ possible that the correct alternative can be determined through some @@ -233,7 +236,7 @@ possible that the correct alternative can be determined through some
233 clustering based on these features, and once determined will remain the best 236 clustering based on these features, and once determined will remain the best
234 choice over long time intervals. 237 choice over long time intervals.
235 238
236 -\subsubsection{Dynamic Adaptation} 239 +\subsubsection{Dynamic adaptation}
237 240
238 If the choice of alternative depends on dynamic factors such as the accuracy 241 If the choice of alternative depends on dynamic factors such as the accuracy
239 of location services, the amount of energy left in the battery, or the type 242 of location services, the amount of energy left in the battery, or the type
@@ -242,7 +245,7 @@ single alternative can be chosen even for a single user. Instead, the @@ -242,7 +245,7 @@ single alternative can be chosen even for a single user. Instead, the
242 \texttt{maybe} system allows developers to evaluate one or more strategies to 245 \texttt{maybe} system allows developers to evaluate one or more strategies to
243 drive the runtime alternative selection process. 246 drive the runtime alternative selection process.
244 247
245 -Note that \texttt{better} blocks are \textit{not} intended to accomplish this 248 +Note that \texttt{evaluate} blocks are \textit{not} intended to accomplish this
246 kind of adaptation. First, they run after the \texttt{maybe} block has been 249 kind of adaptation. First, they run after the \texttt{maybe} block has been
247 executed, not before. Second, a single strategy defeats the flexibility 250 executed, not before. Second, a single strategy defeats the flexibility
248 inherent to the \texttt{maybe} approach and would devolve into the same 251 inherent to the \texttt{maybe} approach and would devolve into the same
@@ -274,7 +277,7 @@ that time, they can connect that \texttt{maybe} statement to a sophisticated @@ -274,7 +277,7 @@ that time, they can connect that \texttt{maybe} statement to a sophisticated
274 machine learning algorithm written by an expert in energy adaptation, instead 277 machine learning algorithm written by an expert in energy adaptation, instead
275 of being forced to implement their own simplistic approach. 278 of being forced to implement their own simplistic approach.
276 279
277 -\subsubsection{Manual Adaptation} 280 +\subsubsection{Manual adaptation}
278 281
279 In some cases even our best efforts to automatically adapt may fail, and it 282 In some cases even our best efforts to automatically adapt may fail, and it
280 may be impossible to predict which alternative is best for a particular user 283 may be impossible to predict which alternative is best for a particular user
@@ -285,3 +288,17 @@ are significant then the \texttt{maybe} alternatives may need to be exposed @@ -285,3 +288,17 @@ are significant then the \texttt{maybe} alternatives may need to be exposed
285 to the user through a settings menu. Fortunately, information obtained 288 to the user through a settings menu. Fortunately, information obtained
286 through testing can still be presented to the user to guide their decision. 289 through testing can still be presented to the user to guide their decision.
287 Note that this requires labeling alternatives in a human-readable way. 290 Note that this requires labeling alternatives in a human-readable way.
  291 +
  292 +\subsection{Continuous Adaptation}
  293 +\label{subsec-continuous}
  294 +
  295 +Finally, even once a decision process for a particular \texttt{maybe}
  296 +alternative has been developed, it should be periodically revisited as users,
  297 +devices, networks, batteries, and other factors affecting mobile apps
  298 +continue to change. To enable continuous adaptation, developers can configure
  299 +\texttt{maybe} statements to continue to periodically experiment with
  300 +alternatives other than the one selected by the alternative testing process.
  301 +Changes in alternative performance relative to the expectations established
  302 +during the last round of alternative testing may trigger a large-scale
  303 +reexamination of that \texttt{maybe} statement using the same process
  304 +described above.
discussion.tex 0 โ†’ 100644
  1 +\section{Discussion}
  2 +\label{sec-discussion}
  3 +
  4 +We have yet to determine how well programmers will be able to use the
  5 +\texttt{maybe} statement. Structurally \texttt{maybe} statements are similar
  6 +to the ubiquitous \texttt{if-else} construct in that at the bottom of the
  7 +statement the programmer may not be sure which block was executed. However,
  8 +while with \texttt{if-else} blocks it can be determined which block was
  9 +executed by examining the branch conditions, \texttt{maybe} statements
  10 +require developers to record which alternative was executed if downstream
  11 +code depends on the decision. To coordinate the adaptation of multiple code
  12 +paths a single \texttt{maybe} variable---such as the policy string in
  13 +Figure~\ref{fig-maybeexamples}---can be used to control multiple
  14 +\texttt{if-else} statements.
  15 +
  16 +While \texttt{maybe} is a powerful programming tool, it is important that it
  17 +be used sparingly. If objective dependencies exist between \texttt{maybe}
  18 +statements, the overall configuration space may expand exponentially,
  19 +complicating the process of determining the best alternatives described in
  20 +Section~\ref{sec-certainty}. Compile-time analysis may be required to detect
  21 +dependencies between \texttt{maybe} statements and ensure that downstream
  22 +optimization remains feasible.
  23 +
  24 +One important place where \texttt{maybe} should not be used is when
  25 +adaptation is not app-specific and can be refactored into a library serving
  26 +multiple apps. As an example, an app should not use \texttt{maybe} to decide
  27 +which network interface to use when attempting to achieve a common objective,
  28 +such as maximizing throughput. This choice would be better refactored into a
  29 +dedicated library, which might use its own internal \texttt{maybe}
  30 +statements. Not only is the resulting codebase smaller, but the total number
  31 +of \texttt{maybe} statements that the system has to determine how to handle
  32 +is reduced.
  33 +
  34 +However, the \texttt{maybe} statement represents a fundamentally different
  35 +approach from previously attempts to enable runtime adaptation that relied on
  36 +libraries. First, libraries
  37 +
  38 +Finally, note that structured uncertainty is not randomness. The
  39 +\texttt{maybe} statement indicates that during any given execution one
  40 +alternative may be better than the others---even if the developer or system
  41 +are not sure which alternative to use.
introduction.tex
@@ -88,7 +88,9 @@ maybe { @@ -88,7 +88,9 @@ maybe {
88 \vspace*{-0.1in} 88 \vspace*{-0.1in}
89 89
90 \caption{\textbf{Example \texttt{maybe} Statement.} The programmer provides 90 \caption{\textbf{Example \texttt{maybe} Statement.} The programmer provides
91 -multiple equivalent alternatives.} 91 +multiple equivalent alternatives. The system determines how to choose between
  92 +them at runtime.}
  93 +
92 \label{fig-example-maybe} 94 \label{fig-example-maybe}
93 95
94 \vspace*{-0.1in} 96 \vspace*{-0.1in}
maybe.tex
1 \section{\texttt{\large maybe} Statement Semantics} 1 \section{\texttt{\large maybe} Statement Semantics}
2 \label{sec-maybe} 2 \label{sec-maybe}
3 3
4 -To begin we provide an overview of the \texttt{maybe} statements semantics,  
5 -describing how it structures uncertainty in variable values and runtime  
6 -execution. We refer to each of the values or code paths a \texttt{maybe}  
7 -statement can choose from as an \textit{alternative}. 4 +To begin we provide an overview of the \texttt{maybe} statement's semantics
  5 +describing how it allows developers to structure uncertainty. We refer to
  6 +each of the values or code paths a \texttt{maybe} statement can choose from
  7 +as an \textit{alternative}.
8 8
9 \begin{figure}[t] 9 \begin{figure}[t]
10 \begin{minted}[fontsize=\footnotesize]{java} 10 \begin{minted}[fontsize=\footnotesize]{java}
@@ -15,7 +15,6 @@ String policy = maybe "auto", "quality", "perf"; @@ -15,7 +15,6 @@ String policy = maybe "auto", "quality", "perf";
15 // Function alternatives 15 // Function alternatives
16 @maybe 16 @maybe
17 int myFunction(int a) { /* First alternative */ } 17 int myFunction(int a) { /* First alternative */ }
18 -  
19 @maybe 18 @maybe
20 int myFunction(int a) { /* Second alternative */ } 19 int myFunction(int a) { /* Second alternative */ }
21 20
@@ -46,74 +45,34 @@ maybe { @@ -46,74 +45,34 @@ maybe {
46 Variables can be used to represent uncertainty. Examples include an integer 45 Variables can be used to represent uncertainty. Examples include an integer
47 storing how often a timer should trigger communication with a remote server, 46 storing how often a timer should trigger communication with a remote server,
48 or a string containing the name of a policy used to coordinate multiple code 47 or a string containing the name of a policy used to coordinate multiple code
49 -blocks through the app. Figure~\ref{fig-maybeexamples} shows examples of an  
50 -integer that can take on values between 1 and 16, and a string that be set to  
51 -either ``auto'', ``quality'', or ``perf''. 48 +blocks throughout the app. Figure~\ref{fig-maybeexamples} shows examples of
  49 +an integer that can take on values between 1 and 16, and a string that be set
  50 +to either ``auto'', ``quality'', or ``perf''.
52 51
53 \subsection{Controlling Code Flow} 52 \subsection{Controlling Code Flow}
54 53
55 -Code flow can also represent uncertainty, and we expect this to be the most  
56 -common use of \texttt{maybe} statements. Examples include evaluating  
57 -multiple algorithms to compute the same result or code paths that represent  
58 -different energy-performance or energy-quality tradeoffs. 54 +Code flow can also represent uncertainty. Examples include using multiple
  55 +algorithms to compute the same result or multiple code paths representing
  56 +different tradeoffs between performance, energy, and quality.
59 Figure~\ref{fig-example-maybe} shows the \texttt{maybe} statement in its 57 Figure~\ref{fig-example-maybe} shows the \texttt{maybe} statement in its
60 simplest form controlling execution of multiple code blocks. If multiple 58 simplest form controlling execution of multiple code blocks. If multiple
61 alternatives are specified, the system chooses one to execute; if only one 59 alternatives are specified, the system chooses one to execute; if only one
62 alternative is specified, the system chooses whether or not to execute it. 60 alternative is specified, the system chooses whether or not to execute it.
63 -Single-alternative \texttt{maybe} statements can encapsulate  
64 -or reorganize logic that does not affect correctness, but may (or  
65 -may not) improve performance if executed. 61 +Single-alternative \texttt{maybe} statements can encapsulate or reorganize
  62 +logic that does not affect correctness, but may (or may not) produce some
  63 +desirable objective.
66 64
67 Figure~\ref{fig-maybeexamples} shows several extensions of the \texttt{maybe} 65 Figure~\ref{fig-maybeexamples} shows several extensions of the \texttt{maybe}
68 statement providing syntactic sugar. \texttt{maybe} function annotations 66 statement providing syntactic sugar. \texttt{maybe} function annotations
69 allow uncertainty to be expressed at the function level, with the 67 allow uncertainty to be expressed at the function level, with the
70 alternatives consisting of multiple function definitions with identical 68 alternatives consisting of multiple function definitions with identical
71 -signatures. Finally, \texttt{maybe} blocks that require special performance  
72 -evaluation logic can include that in the form of a \texttt{evaluate}  
73 -statement following the main \texttt{maybe} block, as shown in the final  
74 -example. \texttt{evaluate} blocks provide app-specific \textit{a posteriori}  
75 -logic to evaluate the selected alternative. The \texttt{evaluate} block must  
76 -return a single JSON object that includes two components: A score, with  
77 -smaller being interpreted as better; and a boolean indicating whether the  
78 -system should use the same branch next time, or if it is free to try another.  
79 -Note that hints and dedicated evaluation logic can also be applied to  
80 -variable and function-level \texttt{maybe} statements through annotations. We  
81 -will return to \textit{a posteriori} evaluation in  
82 -Section~\ref{sec-certainty}.  
83 -  
84 -\subsection{Discussion}  
85 -  
86 -We have yet to determine how well programmers will be able to use the  
87 -\texttt{maybe} statement. Structurally \texttt{maybe} statements are similar  
88 -to the common \texttt{if-else} construct in that at the bottom of the  
89 -statement the programmer may not be sure which block was executed. However,  
90 -while with \texttt{if-else} blocks it can be determined which block was  
91 -executed by examining the branch conditions, \texttt{maybe} statements  
92 -require developers record which alternative was executed if downstream code  
93 -depends on the decision. To coordinate the adaptation of multiple code paths  
94 -a single \texttt{maybe} variable can be used to control multiple  
95 -\texttt{if-else} statements.  
96 -  
97 -While \texttt{maybe} is a powerful programming tool, it is important that it  
98 -be used sparingly. In the case where dependencies exist between the  
99 -alternatives expressed by separate \texttt{maybe} statements, each  
100 -\texttt{maybe} may expand the overall configuration space exponentially which  
101 -makes the resulting process of determining the best alternative much more  
102 -complicated. Compile-time analysis may be required to ensure that downstream  
103 -optimization remains feasible.  
104 -  
105 -The most important guideline for when \textit{not} to use \texttt{maybe}  
106 -usage is when a decision is not app-specific, and should instead be  
107 -refactored into a library or service. As an example, \texttt{maybe} should  
108 -not be used to decide which networking interface to use to send a packet.  
109 -To the degree that  
110 -one app shares the same objectives as others---say, to minimize latency---a  
111 -service should be performing adaptation on behalf of all apps using the  
112 -merged network interfaces, possibly through the use of its own internal  
113 -\texttt{maybe} statements.  
114 -  
115 -Finally, note that structured uncertainty is not randomness. The  
116 -\texttt{maybe} statement indicates that during any given execution one  
117 -alternative may be better than the others---even if the developer or system  
118 -are not sure which alternative to use.  
119 - 69 +signatures. Finally, \texttt{maybe} blocks that require custom evaluation
  70 +logic can include an \texttt{evaluate} statement following the main
  71 +\texttt{maybe} block, as shown in the final example. \texttt{evaluate} blocks
  72 +provide app-specific \textit{a posteriori} logic to evaluate the selected
  73 +alternative. The \texttt{evaluate} block must return a single JSON object
  74 +with two components: (1) a positive integer \texttt{score}, with smaller
  75 +being better; (2) and a boolean \texttt{repeat} indicating whether the system
  76 +must use the same alternative next time. Hints and custom evaluation logic
  77 +can also be applied to other types of \texttt{maybe} statements through
  78 +annotations.
paper.tex
@@ -76,6 +76,7 @@ Jinghao Shi, Guru Prasad Srinivasa, and Lukasz Ziarek} @@ -76,6 +76,7 @@ Jinghao Shi, Guru Prasad Srinivasa, and Lukasz Ziarek}
76 \input{maybe.tex} 76 \input{maybe.tex}
77 \input{certainty.tex} 77 \input{certainty.tex}
78 \input{usage.tex} 78 \input{usage.tex}
  79 +\input{discussion.tex}
79 80
80 \input{related.tex} 81 \input{related.tex}
81 \input{conclusion.tex} 82 \input{conclusion.tex}