Bug 1109407 - Give SegmentedVector a default segment size. r=froydnj.
authorNicholas Nethercote <nnethercote@mozilla.com>
Thu, 11 Dec 2014 14:11:43 -0800
changeset 245181 76b604c4556cef4c0fdc475e19a7f938390822b2
parent 245152 5288b15d22de803f6405b37c57cc2b08296d115e
child 245182 ca68c68e483560323b7da86e1d3a9cb594cc2365
push id4489
push userraliiev@mozilla.com
push dateMon, 23 Feb 2015 15:17:55 +0000
treeherdermozilla-beta@fd7c3dc24146 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1109407
milestone37.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1109407 - Give SegmentedVector a default segment size. r=froydnj.
mfbt/SegmentedVector.h
mfbt/tests/TestSegmentedVector.cpp
--- a/mfbt/SegmentedVector.h
+++ b/mfbt/SegmentedVector.h
@@ -27,22 +27,34 @@
 #include "mozilla/MemoryReporting.h"
 #include "mozilla/Move.h"
 #include "mozilla/TypeTraits.h"
 
 #include <new>  // for placement new
 
 namespace mozilla {
 
-// IdealSegmentSize is how big each segment will be in bytes (or as close as is
-// possible). It's best to choose a size that's a power-of-two (to avoid slop)
-// and moderately large (not too small so segment allocations are infrequent,
-// and not too large so that not too much space is wasted when the final
-// segment is not full). Something like 4096 or 8192 is probably good.
-template<typename T, size_t IdealSegmentSize,
+// |IdealSegmentSize| specifies how big each segment will be in bytes (or as
+// close as is possible). Use the following guidelines to choose a size.
+//
+// - It should be a power-of-two, to avoid slop.
+//
+// - It should not be too small, so that segment allocations are infrequent,
+//   and so that per-segment bookkeeping overhead is low. Typically each
+//   segment should be able to hold hundreds of elements, at least.
+//
+// - It should not be too large, so that OOMs are unlikely when allocating
+//   segments, and so that not too much space is wasted when the final segment
+//   is not full.
+//
+// The ideal size depends on how the SegmentedVector is used and the size of
+// |T|, but reasonable sizes include 1024, 4096 (the default), 8192, and 16384.
+//
+template<typename T,
+         size_t IdealSegmentSize = 4096,
          typename AllocPolicy = MallocAllocPolicy>
 class SegmentedVector : private AllocPolicy
 {
   template<size_t SegmentCapacity>
   struct SegmentImpl
     : public mozilla::LinkedListElement<SegmentImpl<SegmentCapacity>>
   {
     SegmentImpl() : mLength(0) {}
--- a/mfbt/tests/TestSegmentedVector.cpp
+++ b/mfbt/tests/TestSegmentedVector.cpp
@@ -142,17 +142,17 @@ void TestSegmentCapacitiesAndAlignments(
   //
   // Also, SegmentedVector has a static assertion that elements are
   // appropriately aligned.
   SegmentedVector<double, 512> v1(512);
   SegmentedVector<A, 1024> v2(1024);
   SegmentedVector<B, 999> v3(999);
   SegmentedVector<C, 10> v4(10);
   SegmentedVector<D, 1234> v5(1234);
-  SegmentedVector<E, 4096> v6(4096);
+  SegmentedVector<E> v6(4096);  // 4096 is the default segment size
   SegmentedVector<mozilla::AlignedElem<16>, 100> v7(100);
 }
 
 int main(void)
 {
   TestBasics();
   TestConstructorsAndDestructors();
   TestSegmentCapacitiesAndAlignments();