aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorGravatar Herb Derby <herb@google.com>2017-03-03 15:09:43 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-03-03 21:11:08 +0000
commit01254bcf222a7806afbfbcb9c7fe13cc522448b3 (patch)
tree81fec54923285d851307d8f5ee91af8866243fac /src
parentbaf06bc89a0ee2ac4033281e7310f6c727faab79 (diff)
Use an exponential growth strategy for extra blocks.
Change-Id: I4137cb60b79184456aa71d18cb31a52c27bd8792 Reviewed-on: https://skia-review.googlesource.com/9260 Reviewed-by: Mike Klein <mtklein@chromium.org> Commit-Queue: Herb Derby <herb@google.com>
Diffstat (limited to 'src')
-rw-r--r--src/core/SkArenaAlloc.cpp3
-rw-r--r--src/core/SkArenaAlloc.h7
2 files changed, 9 insertions, 1 deletions
diff --git a/src/core/SkArenaAlloc.cpp b/src/core/SkArenaAlloc.cpp
index dee152ae20..779eaff0f1 100644
--- a/src/core/SkArenaAlloc.cpp
+++ b/src/core/SkArenaAlloc.cpp
@@ -100,7 +100,8 @@ void SkArenaAlloc::ensureSpace(uint32_t size, uint32_t alignment) {
objSizeAndOverhead += alignment - 1;
}
- uint32_t allocationSize = std::max(objSizeAndOverhead, fExtraSize);
+ uint32_t allocationSize = std::max(objSizeAndOverhead, fExtraSize << fLogGrowth);
+ fLogGrowth++;
// Round up to a nice size. If > 32K align to 4K boundary else up to max_align_t. The > 32K
// heuristic is from the JEMalloc behavior.
diff --git a/src/core/SkArenaAlloc.h b/src/core/SkArenaAlloc.h
index 3a6fd7d345..04f929181c 100644
--- a/src/core/SkArenaAlloc.h
+++ b/src/core/SkArenaAlloc.h
@@ -52,6 +52,10 @@
// typical block overhead of 8 bytes. For non-POD objects there is a per item overhead of 4 bytes.
// For arrays of non-POD objects there is a per array overhead of typically 8 bytes. There is an
// addition overhead when switching from POD data to non-POD data of typically 8 bytes.
+//
+// If additional blocks are needed they are increased exponentially. This strategy bounds the
+// recursion of the RunDtorsOnBlock to be limited to O(ln size-of-memory). In practical terms, this
+// is a maximum recursion depth of 33 for an 8GB machine but usually much less.
class SkArenaAlloc {
public:
SkArenaAlloc(char* block, size_t size, size_t extraSize = 0);
@@ -192,6 +196,9 @@ private:
char* const fFirstBlock;
const uint32_t fFirstSize;
const uint32_t fExtraSize;
+ // The extra size allocations grow exponentially:
+ // size-allocated = extraSize * 2 ^ fLogGrowth.
+ uint8_t fLogGrowth {0};
};
#endif//SkFixedAlloc_DEFINED