[PATCH] D43892: [YAML] speed up isNumber by doing regex matching less often

Martin Pelikán via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 28 12:41:18 PST 2018


pelikan created this revision.
pelikan added a reviewer: dberris.

Processing 2 GB XRay traces with "llvm-xray convert -output-format=yaml"
currently takes 1.5+ hours on my machine.  When YAML is finally printed,
profiling shows huge amounts of time in YAML's needQuotes and isNumber,
doing regexp matching.  That shouldn't be necessary for arbitrary input
and leaving it only when there's a chance of a float appearing makes it
consume only 40 minutes instead.  More CPU savings to come.


Repository:
  rL LLVM

https://reviews.llvm.org/D43892

Files:
  include/llvm/Support/YAMLTraits.h


Index: include/llvm/Support/YAMLTraits.h
===================================================================
--- include/llvm/Support/YAMLTraits.h
+++ include/llvm/Support/YAMLTraits.h
@@ -471,11 +471,13 @@
   if (S.equals(".inf") || S.equals(".Inf") || S.equals(".INF"))
     return true;
 
-  Regex FloatMatcher("^(\\.[0-9]+|[0-9]+(\\.[0-9]*)?)([eE][-+]?[0-9]+)?$");
-  if (FloatMatcher.match(S))
-    return true;
+  // Don't waste time regex matching on anything obviously non-numeric.
+  static const char FloatChars[] = "+-0123456789.eE";
+  if (S.find_first_not_of(FloatChars) != StringRef::npos)
+    return false;
 
-  return false;
+  Regex FloatMatcher("^(\\.[0-9]+|[0-9]+(\\.[0-9]*)?)([eE][-+]?[0-9]+)?$");
+  return FloatMatcher.match(S);
 }
 
 inline bool isNumeric(StringRef S) {


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D43892.136363.patch
Type: text/x-patch
Size: 795 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180228/7b8a4d99/attachment.bin>


More information about the llvm-commits mailing list