aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2010-09-30 16:18:28 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2010-09-30 16:18:28 +0000
commit82d96cccbc40f53c28dd8288b475e535ef017c3a (patch)
tree6bec1ea584046caa24277512c197b6ac61eb26cb
parent2f24c4ece09f1157c5cb29357d91d2a0d77eb57c (diff)
downloadexternal_llvm-82d96cccbc40f53c28dd8288b475e535ef017c3a.zip
external_llvm-82d96cccbc40f53c28dd8288b475e535ef017c3a.tar.gz
external_llvm-82d96cccbc40f53c28dd8288b475e535ef017c3a.tar.bz2
Grow BumpPtrAllocator's slab size dynamically if we allocated many slabs. This
reduces the amount of malloc calls and may reduce memory overhead. Some numbers: ASTContext stats, clang -cc1 -disable-free -fsyntax-only Cocoa_h.m without dynamic growth | with dynamic growth Number of memory regions: 3158 | Number of memory regions: 432 Bytes used: 12333185 | Bytes used: 12333185 Bytes allocated: 12935168 | Bytes allocated: 12800000 Bytes wasted: 601983 (includes alignment, etc) | Bytes wasted: 466815 (includes alignment, etc) ASTContext stats, clang -cc1 -disable-free -fsyntax-only on clang's ASTReader.cpp without dynamic growth | with dynamic growth Number of memory regions: 10987 | Number of memory regions: 551 Bytes used: 42910356 | Bytes used: 42910356 Bytes allocated: 45002752 | Bytes allocated: 44711936 Bytes wasted: 2092396 (includes alignment, etc) | Bytes wasted: 1801580 (includes alignment, etc) git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@115151 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Support/Allocator.cpp6
1 files changed, 6 insertions, 0 deletions
diff --git a/lib/Support/Allocator.cpp b/lib/Support/Allocator.cpp
index 90df262..02b45d8 100644
--- a/lib/Support/Allocator.cpp
+++ b/lib/Support/Allocator.cpp
@@ -44,6 +44,12 @@ char *BumpPtrAllocator::AlignPtr(char *Ptr, size_t Alignment) {
/// StartNewSlab - Allocate a new slab and move the bump pointers over into
/// the new slab. Modifies CurPtr and End.
void BumpPtrAllocator::StartNewSlab() {
+ // If we allocated a big number of slabs already it's likely that we're going
+ // to allocate more. Increase slab size to reduce mallocs and possibly memory
+ // overhead. The factors are chosen conservatively to avoid overallocation.
+ if (BytesAllocated >= SlabSize * 128)
+ SlabSize *= 2;
+
MemSlab *NewSlab = Allocator.Allocate(SlabSize);
NewSlab->NextPtr = CurSlab;
CurSlab = NewSlab;