aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGravatar Bruce Dawson <brucedawson@google.com>2016-11-18 15:08:45 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2016-11-21 22:48:12 +0000
commit759ae5639b0dfe5a0d5491aa0e0b9855aa42ab73 (patch)
tree72cc24f11129c6f2420cefdf410296dfce2bd867
parentc59034145862bf6dc0c503cb1e47eecd321ffa8c (diff)
Avoid runtime initialization of FLT_EPSILON_SQRT
FLT_EPSILON_SQRT is initialized with a call to sqrt which, in release builds on Windows, results in an initializer call (on official release builds this is optimized away). On Windows release (all flavors) builds this also triggers duplicate instantiations of the variable (always a risk with non-integral const variables defined in header files) with 32 copies ending up in both chrome.dll and chrome_child.dll. This change avoids the run-time initializer and as a side effect it also avoids most or all of the duplication. Section size savings in a Windows 32-bit release official build are: chrome.dll .text: -64 bytes change .rdata: -16 bytes change .data: -256 bytes change .reloc: -116 bytes change Total change: -452 bytes chrome_child.dll .text: 160 bytes change .rdata: -144 bytes change .data: -256 bytes change .reloc: -60 bytes change Total change: -300 bytes A more complete fix would include using extern const to declare these constants in the header file but define them once in a .cc file, but it's not clear that this is necessary. The size savings on non-official builds are greater. The increase in the .text segment is odd, but harmless since those bytes are shared. BUG=630755 GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=5061 Change-Id: I53d0cdc38e022039646df491d824a1aaf11def80 Reviewed-on: https://skia-review.googlesource.com/5061 Reviewed-by: Cary Clark <caryclark@google.com> Reviewed-by: Bruce Dawson <brucedawson@google.com> Commit-Queue: Cary Clark <caryclark@google.com>
-rw-r--r--src/pathops/SkPathOpsTypes.h4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/pathops/SkPathOpsTypes.h b/src/pathops/SkPathOpsTypes.h
index 08e1791ad3..87291f76a7 100644
--- a/src/pathops/SkPathOpsTypes.h
+++ b/src/pathops/SkPathOpsTypes.h
@@ -310,7 +310,9 @@ const double FLT_EPSILON_HALF = FLT_EPSILON / 2;
const double FLT_EPSILON_DOUBLE = FLT_EPSILON * 2;
const double FLT_EPSILON_ORDERABLE_ERR = FLT_EPSILON * 16;
const double FLT_EPSILON_SQUARED = FLT_EPSILON * FLT_EPSILON;
-const double FLT_EPSILON_SQRT = sqrt(FLT_EPSILON);
+// Use a compile-time constant for FLT_EPSILON_SQRT to avoid initializers.
+// A 17 digit constant guarantees exact results.
+const double FLT_EPSILON_SQRT = 0.00034526697709225118; // sqrt(FLT_EPSILON);
const double FLT_EPSILON_INVERSE = 1 / FLT_EPSILON;
const double DBL_EPSILON_ERR = DBL_EPSILON * 4; // FIXME: tune -- allow a few bits of error
const double DBL_EPSILON_SUBDIVIDE_ERR = DBL_EPSILON * 16;