Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(493)

Issue 2949803002: New growth strategy for growable arrays (Closed)

Created:
3 years, 6 months ago by Aske Simon Christensen
Modified:
3 years, 6 months ago
CC:
reviews_dartlang.org, vm-dev_dartlang.org
Target Ref:
refs/heads/master
Visibility:
Public.

Description

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

Patch Set 1 #

Total comments: 18

Patch Set 2 : Branch-free grow size computation. Renamed function names to be clearer. #

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

Messages

Total messages: 13 (6 generated)
Aske Simon Christensen
3 years, 6 months ago (2017-06-20 14:39:35 UTC) #6
Lasse Reichstein Nielsen
SGTM, but I'm not a VM engineer :) https://codereview.chromium.org/2949803002/diff/1/runtime/lib/growable_array.dart File runtime/lib/growable_array.dart (right): https://codereview.chromium.org/2949803002/diff/1/runtime/lib/growable_array.dart#newcode91 runtime/lib/growable_array.dart:91: var ...
3 years, 6 months ago (2017-06-21 07:36:22 UTC) #7
erikcorry
https://codereview.chromium.org/2949803002/diff/1/runtime/vm/object.cc File runtime/vm/object.cc (right): https://codereview.chromium.org/2949803002/diff/1/runtime/vm/object.cc#newcode22085 runtime/vm/object.cc:22085: // The backing array may be a shared instance, ...
3 years, 6 months ago (2017-06-21 07:58:31 UTC) #8
erikcorry
What Lasse said and LGTM https://codereview.chromium.org/2949803002/diff/1/runtime/lib/growable_array.cc File runtime/lib/growable_array.cc (right): https://codereview.chromium.org/2949803002/diff/1/runtime/lib/growable_array.cc#newcode94 runtime/lib/growable_array.cc:94: return Array::MakeArray(array, true); Boolean ...
3 years, 6 months ago (2017-06-21 09:06:01 UTC) #9
Lasse Reichstein Nielsen
https://codereview.chromium.org/2949803002/diff/1/runtime/vm/object.cc File runtime/vm/object.cc (right): https://codereview.chromium.org/2949803002/diff/1/runtime/vm/object.cc#newcode22069 runtime/vm/object.cc:22069: RawArray* Array::MakeArray(const GrowableObjectArray& growable_array, Or MakeArrayNongrowable, which doesn't sound ...
3 years, 6 months ago (2017-06-21 09:14:15 UTC) #10
Aske Simon Christensen
https://codereview.chromium.org/2949803002/diff/1/runtime/lib/growable_array.dart File runtime/lib/growable_array.dart (right): https://codereview.chromium.org/2949803002/diff/1/runtime/lib/growable_array.dart#newcode222 runtime/lib/growable_array.dart:222: static _List _new_data(int capacity) { On 2017/06/21 07:36:21, Lasse ...
3 years, 6 months ago (2017-06-21 12:19:33 UTC) #11
Aske Simon Christensen
3 years, 6 months ago (2017-06-22 08:52:16 UTC) #13
Message was sent while issue was closed.
Committed patchset #2 (id:20001) manually as
cec963f028198ec5871840491ba78b096ad0b819 (presubmit successful).

Powered by Google App Engine
This is Rietveld 408576698