|
The current growth strategy for growable arrays allocates a backing array of size 2 at (empty) creation and doubles the size whenever the capacity is insufficient while adding elements.
I collected statistics for the sizes and capacities of growable arrays which are promoted to old-space or survive an old-space gc when running dart2js and Fasta. For these applications, the vast majority of arrays stay empty. More than half of the total object size of promoted backing arrays is backing for empty growable arrays.
Furthermore, since the overhead for an array is 3 words (header, type parameters and length), and object sizes are rounded up to an even number of words, we waste one word for all even-sized arrays.
This CL changes the growth strategy so that empty growable arrays are created with a shared, zero-sized array as backing, avoiding the allocation of a backing array if no elements are added. When the array needs to grow, it starts out at 3 and grows to double size plus one each time: 7, 15, 31, ...
A few places in the VM code need to handle these shared, zero-sized arrays specially. In particular, the Array::MakeArray function needs to allocate a new, empty array if its result is to be returned to Dart code.
Benchmarks suggest that the change improves memory usage by a few percent overall and does not significantly affect run time.
BUG=
R=erikcorry@google.com
Committed: https://github.com/dart-lang/sdk/commit/cec963f028198ec5871840491ba78b096ad0b819
Total comments: 18
|
Unified diffs |
Side-by-side diffs |
Delta from patch set |
Stats (+124 lines, -126 lines) |
Patch |
|
M |
runtime/lib/array_patch.dart
|
View
|
|
1 chunk |
+0 lines, -4 lines |
0 comments
|
Download
|
|
M |
runtime/lib/growable_array.cc
|
View
|
1
|
3 chunks |
+3 lines, -3 lines |
0 comments
|
Download
|
|
M |
runtime/lib/growable_array.dart
|
View
|
1
|
7 chunks |
+27 lines, -27 lines |
0 comments
|
Download
|
|
M |
runtime/lib/stacktrace.cc
|
View
|
1
|
1 chunk |
+2 lines, -2 lines |
0 comments
|
Download
|
|
M |
runtime/vm/class_finalizer.cc
|
View
|
1
|
2 chunks |
+3 lines, -2 lines |
0 comments
|
Download
|
|
M |
runtime/vm/clustered_snapshot.cc
|
View
|
1
|
1 chunk |
+1 line, -1 line |
0 comments
|
Download
|
|
M |
runtime/vm/code_descriptors.cc
|
View
|
1
|
2 chunks |
+2 lines, -2 lines |
0 comments
|
Download
|
|
M |
runtime/vm/dart_api_impl.cc
|
View
|
1
|
1 chunk |
+1 line, -1 line |
0 comments
|
Download
|
|
M |
runtime/vm/debugger.cc
|
View
|
1
|
6 chunks |
+9 lines, -8 lines |
0 comments
|
Download
|
|
M |
runtime/vm/debugger_api_impl.cc
|
View
|
1
|
2 chunks |
+2 lines, -2 lines |
0 comments
|
Download
|
|
M |
runtime/vm/exceptions.cc
|
View
|
1
|
1 chunk |
+1 line, -1 line |
0 comments
|
Download
|
|
M |
runtime/vm/gc_sweeper.cc
|
View
|
1
|
1 chunk |
+2 lines, -2 lines |
0 comments
|
Download
|
|
M |
runtime/vm/method_recognizer.h
|
View
|
1
|
3 chunks |
+3 lines, -3 lines |
0 comments
|
Download
|
|
M |
runtime/vm/mirrors_api_impl.cc
|
View
|
1
|
2 chunks |
+2 lines, -2 lines |
0 comments
|
Download
|
|
M |
runtime/vm/object.h
|
View
|
1
|
3 chunks |
+5 lines, -4 lines |
0 comments
|
Download
|
|
M |
runtime/vm/object.cc
|
View
|
1
|
8 chunks |
+27 lines, -14 lines |
0 comments
|
Download
|
|
M |
runtime/vm/object_test.cc
|
View
|
1
|
5 chunks |
+5 lines, -5 lines |
0 comments
|
Download
|
|
M |
runtime/vm/pages.cc
|
View
|
1
|
1 chunk |
+1 line, -1 line |
0 comments
|
Download
|
|
M |
runtime/vm/parser.cc
|
View
|
1
|
8 chunks |
+10 lines, -10 lines |
0 comments
|
Download
|
|
M |
runtime/vm/precompiler.cc
|
View
|
1
|
3 chunks |
+3 lines, -3 lines |
0 comments
|
Download
|
|
M |
runtime/vm/profiler_test.cc
|
View
|
|
1 chunk |
+3 lines, -18 lines |
0 comments
|
Download
|
|
M |
runtime/vm/raw_object.h
|
View
|
1
|
1 chunk |
+5 lines, -5 lines |
0 comments
|
Download
|
|
M |
runtime/vm/raw_object.cc
|
View
|
1
|
1 chunk |
+1 line, -1 line |
0 comments
|
Download
|
|
M |
runtime/vm/service.cc
|
View
|
1
|
1 chunk |
+3 lines, -2 lines |
0 comments
|
Download
|
|
M |
runtime/vm/service_test.cc
|
View
|
1
|
1 chunk |
+3 lines, -3 lines |
0 comments
|
Download
|
Total messages: 13 (6 generated)
|