Skip to content

Commit f28d4a5

Browse files
jensjohaCommit Queue
authored and
Commit Queue
committed
[analyzer] Slimmer _StringTable
_StringTable had 2 Uint32Lists for offsets and lengths in order to be able to read strings lazily. As offsets[x+1] = offsets[x]+length[x] we don't really need the lengths one though. Analyzing (82 contexts in) flutter/flutter (without a cache) this reduces memory load by something like 22-27 MB (see below). Note that it doesn't actually reduce the heap capacity or the process RSS in this instance though. Statistics on 5 runs of each: ``` _Uint32List (dart:typed_data) (bytes): Difference at 95.0% confidence -23842069.33 +/- 986160.19 -5.15% +/- 0.21% heapUsage: Difference at 95.0% confidence -28619536.00 +/- 8755493.42 -0.79% +/- 0.24% ``` Change-Id: Ia71bac2233fcef2d9e930c8b78f1aee58e1af78f Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/320801 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Jens Johansen <jensj@google.com>
1 parent 4bddf8a commit f28d4a5

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

pkg/analyzer/lib/src/summary2/data_reader.dart

+6-5
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,6 @@ class _StringTable {
195195
int _byteOffset;
196196

197197
late final Uint32List _offsets;
198-
late final Uint32List _lengths;
199198
late final List<String?> _strings;
200199

201200
/// The structure of the table:
@@ -211,14 +210,13 @@ class _StringTable {
211210
var offset = startOffset - _readUInt30();
212211
var length = _readUInt30();
213212

214-
_offsets = Uint32List(length);
215-
_lengths = Uint32List(length);
213+
_offsets = Uint32List(length + 1);
216214
for (var i = 0; i < length; i++) {
217215
var stringLength = _readUInt30();
218216
_offsets[i] = offset;
219-
_lengths[i] = stringLength;
220217
offset += stringLength;
221218
}
219+
_offsets[length] = offset;
222220

223221
_strings = List.filled(length, null, growable: false);
224222
}
@@ -227,7 +225,10 @@ class _StringTable {
227225
var result = _strings[index];
228226

229227
if (result == null) {
230-
result = _readStringEntry(_offsets[index], _lengths[index]);
228+
int start = _offsets[index];
229+
int end = _offsets[index + 1];
230+
int length = end - start;
231+
result = _readStringEntry(_offsets[index], length);
231232
result = considerCanonicalizeString(result);
232233
_strings[index] = result;
233234
}

0 commit comments

Comments
 (0)