# source:docs/Working/icGrep/evaluation.tex@4604

Last change on this file since 4604 was 4604, checked in by nmedfort, 4 years ago

Small typos and clarifications

File size: 14.4 KB
Line
1\section{Evaluation}\label{sec:evaluation}
2
3In this section, we report on the evaluation of \icGrep{} performance, looking at three aspects.
4%
5First, we discuss some performance aspects of \icGrep{} internal methods, looking at the impact of optimizations discussed previously.
6%
7Then we move on to a systematic performance study of \icGrep{} with named Unicode property searches in comparison to two contemporary competitors,
8namely, pcre2grep released in January 2015 and ugrep of the ICU 54.1 software distribution.
9%
10Finally, we examine complex expressions and the impact of multithreading \icGrep{} on an
11Intel i7-2600 (3.4GHz) and i7-4700MQ (2.4GHz) processor.
12
13\subsection{Optimizations of Bitwise Methods}
14
15In order to support evaluation of bitwise methods, as well as to support
16the teaching of those methods and ongoing research, \icGrep{} has an array
17of command-line options.   This makes it straightforward
18to report on certain performance aspects of \icGrep{}, while others require
19special builds.
20
21For example, the command-line switch \texttt{-disable-matchstar} can be used
22to eliminate the use of the MatchStar operation for handling
23Kleene-* repetition of character classes.   In this case, \icGrep{} substitutes
24a while loop that iteratively extends match results.
25Surprisingly, this
26does not change performance much in many practical cases.
27In each block,
28the maximum iteration count is the maximum length run encountered; the
29overall performance is based on the average of these maxima throughout the
30file.   But when search for XML tags using the regular expression
31\verb:<[^!?][^>]*>:, a slowdown of more than 2$\times$ may be found in files
32with many long tags.
33
34%The {\tt -disable-log2-bounded-repetition} flag allows these
35%effectiveness of the special techniques for bounded repetition of
36%byte classes to be assessed.   A slowdown of 30\% was observed
37%with the searches using the regular expression
38%\verb:(^|[ ])[a-zA-Z]{11,33}([.!? ]|$):, for example. 39 40To control the insertion of if-statements into dynamically 41generated code, the number of pattern elements between each if-test %non-nullable 42can be selected with the {\tt -if-insertion-gap=} option. 43% 44The default value in \icGrep{} is 3; setting the gap to 100 effectively 45turns off if-insertion. 46% 47Eliminating if-insertion sometimes improves performance by avoiding the extra if tests and branch mispredictions. 48% 49For patterns with long strings, however, there can be a substantial slowdown. 50 51%; searching for a pattern of length 40 slows down by more 52%than 50\% without the if-statement short-circuiting. %%% I think we'd need to show this always true to make this claim. 53 54\comment{ 55Additionally, \icGrep{} provides options that allow 56various internal representations to be printed out. 57% 58These can aid in understanding and/or debugging performance issues. 59For example, the option 60{\tt -print-REs} shows the parsed regular expression as it goes 61through various transformations. The internal \Pablo{} code generated 62may be displayed with {\tt -print-pablo}. This can be quite useful in 63helping understand the match process. It also possible to print out the 64generated LLVM IR code ({\tt -dump-generated-IR}), but this may be 65less useful as it includes many 66details of low-level carry-handling that obscures the core logic. 67} 68 69The precompiled calculations of the various Unicode properties 70are each placed in if-hierarchies as described previously. To assess the 71impact of this strategy, we built a version of icGrep without such 72if-hierarchies. In this case, when a Unicode property class is defined, 73bitwise logic equations are applied for all members of the class independent 74of the Unicode blocks represented in the input document. For the classes 75covering the largest numbers of codepoints, we observed slowdowns of up to 5$\times. 76 77\subsection{Simple Property Expressions} 78 79A key feature of Unicode level 1 support in regular expression engines 80the support that they provide for property expressions and combinations of property expressions 81using set union, intersection and difference operators. Both {\tt ugrep} 82and {\tt icgrep} provide systematic support for all property expressions 83at Unicode Level 1 as well as set union, intersection and difference. 84Unfortunately, {\tt pcre2grep} does not support the set intersection and difference operators directly. 85However, these operators can be expressed using a regular expression 86feature known as a lookbehind assertion. Set intersection involves a 87regular expression formed with a one of the property expressions and a 88positive lookbehind assertion on the other, while set difference uses 89a negative lookbehind assertion. 90 91We generated a set of regular expressions involving all Unicode values of 92the Unicode general category property ({\tt gc}) and all values of the Unicode 93script property ({\tt sc}). 94We then generated 95expressions involving random pairs of {\tt gc} and {\tt sc} 96values combined with a random set operator chosen from union, intersection and difference. 97All property values are represented at least once. 98A small number of 99expressions were removed because they involved properties not supported by pcre2grep. 100In the end 246 test expressions were constructed in this process. 101 102\begin{figure} 103\begin{center} 104\pgfplotstableread[col sep = comma]{data/icgrep-scatter.csv}\icgrep 105\pgfplotstableread[col sep = comma]{data/ugrep541-scatter.csv}\ugrep 106\pgfplotstableread[col sep = comma]{data/pcre2grep-scatter.csv}\pcre 107 108\begin{tikzpicture} 109\begin{axis}[ 110grid=both, 111x tick label style={ /pgf/number format/1000 sep=}, 112ylabel={CPU Cycles Per Byte}, 113xlabel={Percentage of Matching Lines}, 114minor y tick num={1}, 115xmax=100, 116height=0.5\textwidth, 117legend style={at={(1.05,0.5)}, 118anchor=west,legend columns=1, 119align=left,draw=none,column sep=2ex} 120] 121\addplot+[no markers,line width=2pt,color=blue!60,solid] table {\icgrep}; 122\addplot+[no markers,line width=2pt,color=red!60,solid] table {\ugrep}; 123\addplot+[no markers,line width=2pt,color=brown!60,solid] table {\pcre}; 124\legend{icGrep,ugrep541,pcre2grep} 125\end{axis} 126 127 128\end{tikzpicture} 129\end{center} 130\caption{Matching Performance for Simple Property Expressions}\label{fig:property_test} 131\end{figure} 132 133We selected a set of Wikimedia XML files in several major languages representing 134most of the world's major language families as a test corpus. 135% 136For each program under test, we performed searches for each regular expression against each XML document. 137% 138Performance is reported in CPU cycles per byte on an Intel i7-2600 machine. 139% 140The results are presented in Figure~\ref{fig:property_test}. 141% 142They were ranked by the percentage of matching lines found in the XML document and grouped in 5\% increments. 143% 144When comparing the three programs, \icGrep{} exhibits dramatically better performance, particularly when searching for rare items. 145% 146The performance of both pcre2grep and ugrep improves (has a reduction in CPU cycles per byte) as the percentage of matching lines increases. 147% 148This occurs because each match allows them to bypass processing the rest of the line. 149% 150On the other hand, \icGrep{} shows a slight drop-off in performance with the number of matches found. 151% 152This is primarily due to property classes that include large numbers of codepoints. 153% 154These classes require more bitstream equations for calculation and also have a greater probability of matching. 155% 156Nevertheless, the performance of \icGrep{} in matching the defined property expressions is stable and well ahead of the competitors in all cases. 157 158 159\subsection{Complex Expressions} 160 161\begin{table}\centering % requires booktabs 162\small\vspace{-2em} 163\begin{tabular}{@{}p{2.7cm}p{10.8cm}@{}} 164\textbf{Name}&\textbf{Regular Expression}\\ 165\toprule 166Alphanumeric \#1&\verb^[\p{L}\p{N}]*((\p{L}\p{N})|(\p{N}\p{L}))[\p{L}\p{N}]*\\
167\midrule
168Alphanumeric \#2&\verb[\p{L}\p{N}]*((\p{L}\p{N})|(\p{N}\p{L}))[\p{L}\p{N}]*\\
169\midrule
170Arabic&\verb^[\p{Arabic}\p{Common}]*\p{Arabic}[\p{Arabic}\p{Common}]*$\\ 171\midrule 172Currency&\verb(\p{Sc}\s*(\d*|(\d{1,3}([,.]\d{3})*))([,.]\d{2}?)?)|\newline\verb((\d*|(\d{1,3}([,.]\d{3})*))([,.]\d{2}?)?\s*\p{Sc})\\ 173\midrule 174Cyrillic&\verb[\p{Pi}\p{Po}]\p{Cyrillic}{6,}[\p{Pf}\p{Pe}]\\ 175\midrule 176Email &\verb([^\p{Z}<]+@[\p{L}\p{M}\p{N}.-]+\.(\p{L}\p{M}*){2,6})(>|\p{Z}|$)\\
177\bottomrule
178\end{tabular}
179\caption{Regular Expressions}\label{table:regularexpr}
180\vspace{-2em}
181\end{table}
182
183This study evaluates the comparative performance of the matching engines on a
184series of more complex expressions, shown in Table \ref{table:regularexpr}.
185%
186The first two are alphanumeric expressions, differing only in that the first
187one is anchored to match the entire line.
188%
189The third searches for lines consisting of text in Arabic script.
190%
191The fourth expression is a published currency expression taken from
192Stewart and Uckelman~\cite{stewart2013unicode}.
193%
194An expression matching runs of six or more Cyrillic script characters enclosed
195in initial/opening and final/ending punctuation is fifth in the list.
196%
197The final expression is an email expression that allows internationalized names.
198%
199In Table \ref{table:complexexpr}, we show the performance results obtained
200from an Intel i7-2600 using generic 64-bit binaries for each engine.
201We limit the SIMD ISA within \icGrep{} to SSE2 which is available
202on all Intel/AMD 64-bit machines.
203%
204In each case, we report seconds taken per GB of input averaged over 10
205runs each on our Wikimedia document collection.
206
207\begin{table}[ht]\centering % requires booktabs
208\newcolumntype{T}{c}
209\small\vspace{-2em}
210\begin{tabular}{@{}p{3cm}r@{~--~}rp{4pt}r@{~--~}rp{4pt}r@{~--~}rp{4pt}r@{~--~}rp{4pt}@{}}
211&\multicolumn{6}{c}{\textbf{\icGrep{}}}\\
212\cmidrule[1pt](lr){2-7}
213\cmidrule[1pt](lr){8-10}
214\cmidrule[1pt](lr){11-13}
215\textbf{Expression}&\multicolumn{3}{T}{\textbf{SEQ}}&\multicolumn{3}{T}{\textbf{MT}}&\multicolumn{3}{T}{\textbf{pcre2grep}}&\multicolumn{3}{T}{\textbf{ugrep541}}\\
216\toprule
217Alphanumeric \#1&2.4&5.0&&2.1&4.4&&8.2&11.3&&8.8&11.3&\\
218Alphanumeric \#2&2.3&4.9&&2.0&4.1&&209.9&563.5&&182.3&457.9&\\
219Arabic&1.5&3.4&&1.2&2.6&&7.5&270.8&&8.9&327.8&\\
220Currency&0.7&2.1&&0.4&1.4&&188.4&352.3&&52.8&152.8&\\
221Cyrillic&1.6&3.9&&1.3&2.8&&30.5&49.7&&11.2&20.1&\\
222Email&3.0&6.9&&2.7&6.4&&67.2&1442.0&&108.8&1022.3&\\
223\bottomrule
224\end{tabular}
225\caption{Matching Times for Complex Expressions (s/GB)}\label{table:complexexpr}
226\vspace{-2em}
227\end{table}
228
229
230The most striking aspect of Table \ref{table:complexexpr} is that both ugrep and pcregrep
231show dramatic slowdowns with ambiguities in regular expressions.
232%
233This is most clearly illustrated in the different performance figures
234for the two Alphanumeric test expressions but is also evident in the
235Arabic, Currency and Email expressions.
236%
237Contrastingly, \icGrep{} maintains consistently fast performance in all test scenarios.
238%
239The multithreaded \icGrep{} shows speedup in every case but balancing
240of the workload across multiple cores is clearly an area for further work.
241%
242Nevertheless, our three-thread system shows up to a 40\% speedup. %  over the single threaded version
243
244
245
246%
247Table \ref{table:relperf} shows the speedups obtained with \icGrep{}
248on a newer Intel i7-4700MQ machine, considering three SIMD ISA alternatives
250All speedups are relative to the base single-threaded SSE2 performance on this machine,
251which is given in seconds per GB in the first column.
252%
253The SSE2 results are again using the generic binaries compiled for compatibility
254with all 64-bit processors.
255%
256The AVX1 results are for Intel AVX instructions
257in 128-bit mode.  The main advantage of AVX1 over SSE2 is its support for 3-operand form,
258which helps reduce register pressure.   The AVX2 results are for \icGrep{}
259compiled to use the 256-bit AVX2 instructions, processing blocks of 256 bytes at a time.
260
261\begin{table}[h]\centering % requires booktabs,siunitx
262\small
263\vspace{-2em}
264\begin{tabular}{@{}p{3cm}l@{~}r@{~~}l@{~}r@{~~}l@{~}r@{~~}l@{~}r@{~~}l@{~}r@{~~}l@{~}r@{~~}@{}}
265&\multicolumn{2}{c}{\textbf{Base}}&\multicolumn{4}{c}{\textbf{SEQ}}&\multicolumn{6}{c}{\textbf{MT}}\\
266\cmidrule[1pt](lr){2-3}
267\cmidrule[1pt](lr){4-7}
268\cmidrule[1pt](lr){8-13}
269\textbf{Expression}&\multicolumn{2}{c}{\textbf{s/GB}}&\multicolumn{2}{c}{\textbf{AVX1}}&\multicolumn{2}{c}{\textbf{AVX2}}&\multicolumn{2}{c}{\textbf{SSE2}}&\multicolumn{2}{c}{\textbf{AVX1}}&\multicolumn{2}{c}{\textbf{AVX2}}\\
270\toprule
271Alphanumeric \#1&2.76&(.65)&1.05&(.03)&1.25&(.08)&1.18&(.02)&1.19&(.03)&1.59&(.10)\\
272Alphanumeric \#2&2.69&(.66)&1.05&(.02)&1.36&(.09)&1.20&(.03)&1.19&(.04)&1.80&(.11)\\
273Arabic&1.82&(.39)&1.05&(.03)&1.15&(.08)&1.37&(.03)&1.37&(.04)&1.66&(.10)\\
274Currency&1.04&(.30)&1.03&(.02)&1.04&(.06)&1.59&(.15)&1.61&(.14)&1.78&(.21)\\
275Cyrillic&2.10&(.44)&1.06&(.02)&0.96&(.06)&1.27&(.02)&1.33&(.04)&1.23&(.09)\\
276Email&3.57&(.87)&1.05&(.03)&1.37&(.14)&1.13&(.03)&1.16&(.04)&1.67&(.18)\\
277\midrule
278\textit{Geomean}&\multicolumn{2}{c}{--}&1.04&&1.18&&1.28&&1.30&&1.61&\\
279\bottomrule
280\end{tabular}
281\caption{Speedup of Complex Expressions on i7-4700MQ $(\sigma)$}\label{table:relperf}
282\vspace{-2em}
283\end{table}
284
285In each case, the use of three-operand form with AVX1 confers a slight
286speedup.  The change to use 256 bits with AVX2 gives a further overall improvement,
287but some mixed results due to the limitations of 256 bit addition.   Combining
288the AVX2 ISA with multithreading gives and average overall 61\% speedup compared to base.
289
290
291
292
293
294
295
296
297
299%
300%
301% \begin{figure}
302% \begin{center}
307% \begin{tikzpicture}
308% \begin{axis}[
309% grid=both,
310% x tick label style={ /pgf/number format/1000 sep=},
311% ylabel={Seconds Per GB ($1000^3$)},
312% xlabel={Percentage of Matching Lines},
313% minor y tick num={1},
314% ymin=0,ymax=3,
315% xmax=100,
316% height=0.5\textwidth,
317% legend style={at={(1.05,0.5)},
318% anchor=west,legend columns=1,
319% align=left,draw=none,column sep=2ex}
320% ]
321% \addplot+[sharp plot, no markers,line width=2pt,color=blue!60,solid] table {\base};
322% \addplot+[sharp plot, no markers,line width=2pt,color=red!60,solid] table {\mt};
323% \addplot+[sharp plot, no markers,line width=2pt,color=brown!60,solid] table {\mtt};
324% %\addplot+[no markers,line width=2pt,color=green!60,solid] table {\flat};
325% \legend{icGrep (Base),icGrep (MT2),icGrep (MT3), icGrep (Flat)}
326% \end{axis}
327%
328%
329% \end{tikzpicture}
330% \end{center}