Commit 45a80015 authored by Michael Banken's avatar Michael Banken

added performance analysis

parent 05ead1d4
@misc{scaladoccolperf, title={{Scala Documentation} {Collections} Performance Characteristics}, howpublished = {\url{https://docs.scala-lang.org/overviews/collections/performance-characteristics.html}}, journal={Scala Documentation}, publisher={scala-lang.org}, note={Accessed: 2018-06-14}}
\ No newline at end of file
\documentclass[a4paper,11pt,twopage,numbers=noenddot]{scrbook}
\documentclass[a4paper,11pt,twopage,numbers=noenddot, openany]{scrbook}
\usepackage[top=2cm,lmargin=1in,rmargin=1in,bottom=3cm,hmarginratio=1:1]{geometry}
\usepackage[utf8]{inputenc}
......
......@@ -125,10 +125,10 @@ The following code applies the optimizations to the entire theory graph.
theoryGraph := sort(theoryGraph)\;
theoryGraphRev := reverse(theoryGraph)\;
\For{theory $\leftarrow$ theoryGraph}{
add include $\rightarrow$ usedTheories(theory) $\cup$ futureUses(theory) to futureUses\;
add theory $\rightarrow$ usedTheories(theory) $\cup$ futureUses(theory) to futureUses\;
add theory $\rightarrow$ optimize(theory, futureUses(theory)) to replacements\;
\For{include $\leftarrow$ includes(theory)}{
replace include $\rightarrow$ futureUses(include)$\cup$usedTheories(include)$\cup$futureUses(theory) in futureUses\;
add include $\rightarrow$ futureUses(include)$\cup$usedTheories(include)$\cup$futureUses(theory) to futureUses\;
}
\KwRet replacements \;
}
......@@ -190,7 +190,7 @@ The following pseudo code is for finding simply redundant inclusions (see: \auto
pass changes that were already applied to the graph}
\KwResult{$redundantIncludes$ = set of simply redundant inclusions}
\Begin{
$subIncludes := \emptyset$\
$subIncludes := \emptyset$\;
$redundantIncludes := \emptyset$\;
\For{$i \leftarrow directIncludes(theory)$}{
$subIncludes := subIncludes \cup includes(i)$\;
......@@ -202,12 +202,167 @@ The following pseudo code is for finding simply redundant inclusions (see: \auto
}
\KwRet $redundantIncludes$\;
}
\caption{simplyRedundantIncludes(theory, futureUse)}
\caption{simplyRedundantIncludes(theory)}
\end{algorithm}
\section{Complexity analysis}
\section{Performance analysis}
Since the performance will be heavily dependent on the size of the graph to be optimized, we will measure runtime and memory requirements depending on the variable t, which denotes the number of theories in the graph.
\subsection{Runtime}
\label{sec:runtime}
Exact runtime is specific to the library implementations of used functions, but after looking at the relevant Scala documentation we can make a few helpful assumptions \cite{scaladoccolperf}.
With effective constant time to lookup, add and remove in a hashset, we can deduce that likely runtimes for the set-operations $\cup$, $\cap$ and $\setminus$ are O(n), where n is the number of elements in the sets involved.
\subsubsection{First pass}
\begin{algorithm}[H]
\Begin{
replacements := empty map \tcp*{1}
futureUsedTheories := usedTheories(theory) $\cup$ futureUse \tcp*{t}
candidates := DirectInludes(theory) $\setminus$ futureUsedTheories \tcp*{t}
\For{candidate $\leftarrow$ candidates\tcp*{$\times t$}}{
neededCandidateIncludes := Includes(candidate) $\cap$ futureUsedTheories \tcp*{t}
remainingIncludes := Includes((directIncludes(theory) $\cap$ futureUsedTheories))$\cup$ (directIncludes(theory) $\cap$ futureUsedTheories) \tcp*{5$\cdot{}$t}
neededCandidateIncludes := neededCandidateIncludes $\setminus$ remainingIncludes\tcp*{t}
add candidate $\rightarrow$ neededCandidateIncludes to replacements\tcp{1}
}
\KwRet superfluousIncludes\tcp{1}
\caption{superfluousIncludes(theory, futureUse) - runtime}
}
\end{algorithm}
The loop runs up to $t$ times over up to $7 \cdot t+1$.\\
This results in an overall worst case performance of $7\cdot t^2+t+3 = O(t^2)$.
\subsubsection{Second pass}
\begin{algorithm}[H]
\Begin{
$subIncludes := \emptyset$\tcp*{1}
$redundantIncludes := \emptyset$\tcp*{1}
\For{$i \leftarrow directIncludes(theory)$\tcp*{$\times t +t$}}{
$subIncludes := subIncludes \cup includes(i)$\tcp*{t}
}
\For{$i \leftarrow directIncludes(theory)$\tcp*{$\times t +t$}}{
\If{$i \in subIncludes$\tcp*{1}} {
$redundantIncludes := redundantIncludes \cup \{i\}$\tcp*{t}
}
}
\KwRet $redundantIncludes$\tcp*{1}
\caption{simplyredundantIncludes(theory) - runtime}
}
\end{algorithm}
The first loop runs up to $t$ times over up to $t$.\\
The second loop runs up to $t$ times over up to $t+1$.\\
This results in an overall worst case performance of $2\cdot t^2+t+3 = O(t^2)$.
\subsubsection{Theory optimization}
\begin{algorithm}[H]
\Begin{
replacements = superfluousIncludes(theory, futureUse)\tcp*{$t^2$}
\For{removal $\leftarrow$ redundantIncludes(theory, futureUse)\tcp*{$\times t + t^2$}}{
add removal $\rightarrow$ $\emptyset$ to replacements\tcp*{$1$}
}
\KwRet replacements\tcp*{$1$}
}
\caption{optimize(theory, futureUse)}
\end{algorithm}
The loop runs up to $t$ times over 1.\\
This results in an overall worst case performance of $2\cdot O(t^2)+t+1 = O(t^2)$.
\subsubsection{Graph optimization}
\begin{algorithm}[H]
\Begin{
futureUses := empty map\tcp*{1}
replacements := empty map\tcp*{1}
theoryGraph := sort(theoryGraph)\tcp*{$t^2$}
theoryGraphRev := reverse(theoryGraph)\tcp*{$t$}
\For{theory $\leftarrow$ theoryGraph\tcp*{$\times t$}}{
add theory $\rightarrow$ usedTheories(theory) $\cup$ futureUses(theory) to futureUses\tcp*{$t$}
add theory $\rightarrow$ optimize(theory, futureUses(theory)) to replacements\tcp*{$O(t^2)$}
\For{include $\leftarrow$ includes(theory)\tcp*{$\times t$}}{
add include $\rightarrow$ futureUses(include)$\cup$usedTheories(include)$\cup$futureUses(theory) to futureUses\tcp*{$t$}
}
\KwRet replacements \tcp*{1}
}
}
\caption{optimizeGraph(theorygraph) - runtime}
\end{algorithm}
The inner loop runs up to $t$ times over up to $t$.\\
The outer loop runs up to $t$ times over up to $t+O(t^2+)+t^2$.\\
This results in an overall worst case performance of $t^2+t+t\cdot (t+O(t^2)+t^2) +3= O(t^3)$.
Since the total number of theories can be quite large a cubic runtime is hardly ideal. However it should be noted that the worst case requires the average theory to include most of the other theories.
In graphs where no theory includes more than the square root of the number of theories, the runtime should remain within quadratic bounds.
\subsection{Memory}
Making precise assumptions about the memory usage is even harder, as the documentation is insufficiently specific. We will therefore assume that the memory required by a HashSet or HashMap is in the same order of magnitude as it's elements.
\subsubsection{First pass}
\begin{algorithm}[H]
\KwData{\\
theory = O(1)\\
futureUse = O(t)\\
replacements = O($t^2$)\\
futureUsedTheories = O(t)\\
candidates = O(t)\\
neededCandidateIncludes = O(t)\\
remainingIncludes = O(t)\\
neededCandidateIncludes = O(t)
}
\caption{superfluousIncludes(theory, futureUse) - memory}
\end{algorithm}
Assuming none of the library functions need larger memory, the overall memory usage lies in O($t^2$).
\subsubsection{Second pass}
\begin{algorithm}[H]
\KwData{\\
theory = O(1)\\
subIncludes = O(t)\\
redundantIncludes = O(t)\\
$i_{first\ loop}$ = O(1)\\
$i_{second\ loop}$ = O(1)
}
\caption{simplyredundantIncludes(theory) - memory}
\end{algorithm}
Assuming none of the library functions need larger memory, the overall memory usage lies in O(t).
\subsubsection{Theory optimization}
\begin{algorithm}[H]
\KwData{theory = theory from our theory graph\\
futureUse = set of theories used by theories including $theory$ in future lite code\\
pass changes that were already applied to the graph}
\KwResult{\\
replacements = O($t^2$)\\
superfluousIncludes(theory, futureUse) = O($t^2$)\\
removal = O(t)\\
redundantIncludes(theory, futureUse) = O(t)
}
\caption{optimize(theory, futureUse) - memory}
\end{algorithm}
Assuming none of the library functions need larger memory, the overall memory usage lies in O($t^2$).
\subsubsection{Graph optimization}
\begin{algorithm}[H]
\label{alg:graph}
\KwData{\\
theoryGraph = O(t)\\
futureUses = O($t^2$)\\
replacements = O($t^2$)\\
theoryGraphRev = O(t)\\
theory = O(1)\\
optimize(theory, futureUse) = O($t^2$)
}
\caption{optimizeGraph(theorygraph) - memory}
\end{algorithm}
Assuming none of the library functions need larger memory, the overall memory usage lies in O($t^2$).
\ No newline at end of file
\chapter{Introduction}
\section{Motivation}
\section{Goal}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment