Repository navigation
Commit b70544e
authored
perf: smaller metadata, mapped instead of copied (#2112)
* refactor: remove SetMissingBaseMethods
It was meant to copy the instance methods of a base class that the
device's class hierarchy lacks onto the class being built. Since
extension functions were added to the metadata, the count it reads
right after a class value's head is the extension function count, which
is zero for every type that has none, so it has added nothing for years.
For a type that does have extension functions it would read their
entries, which are two bytes longer, as instance methods.
The list of instance method data that SetInstanceMembers returned only
fed this function, so it goes as well.
* perf: pack the metadata value stream
The value stream, half of an app's metadata, drops by about a quarter
(1,635 KB to 1,209 KB for the test app; the three streams together go
from 3.26 MB to 2.84 MB). Node ids keep their width.
- Signatures are stored once. 84,677 method records shared 18,833
distinct signatures, each written out in full every time. They now
live in a region at the head of the stream and a method refers to its
signature by offset.
- A method record is a fixed 7 bytes, the name offset and a 3-byte
signature reference whose low bit is the resolved flag, down from
7 bytes plus 2 per type. The runtime's MethodInfo is a pointer to the
record: it no longer copies each signature into a vector when a class
is materialized, and reads it only when the method is first resolved.
- A class value says which of its six member sections it has in one
byte, instead of a 2-byte count for each. 79% of those counts were 0.
- A static field names its declaring type only when that is not the
class listing it, which was the case for 15% of them.
- An interface no longer carries the offset of the "com/tns/gen/"
prefix, a constant the runtime already has.
- An array's element node no longer gets a class value that nothing
could reach.
The stream now opens with a format word, and the runtime refuses to
start on any other, naming the mismatch. The generator and the runtime
ship together, so this only fires on stale or damaged metadata, which
used to be misread.
A signature reference has 23 bits, so the signature region can be at
most 8 MB (it is 127 KB here); the generator fails the build beyond it.
* perf: map the metadata instead of reading it into the heap
The names and values streams were read into heap buffers kept for the
life of the process, each with 512 KB of slack for records appended at
run time. They are now mapped read-only, so only the pages an app
touches are loaded, and those are clean, file-backed pages the system
can drop under memory pressure instead of private heap. The node stream
is mapped only while the tree is built from it.
Nothing appends to those buffers any more. The names buffer was never
written, and a type resolved at run time put a three-byte record in the
value buffer only so its node had an offset; it now uses a fixed offset
no value can start at, and the one read that followed such an offset
(the element type of an array) goes through the node's memoized type.
The asset extractor replaces these files by renaming a new one over
them, so a live mapping keeps the contents it was made from.
* perf: read the metadata ahead and map it up front
Mapping the metadata lazily moved the cost of loading it onto the first
access of each class, as page faults, and made those accesses noisier.
Populating the mapping removes that, and asking for the whole file to be
read ahead first keeps a cold start from paying for it one read-ahead
window at a time: on the API 36 emulator with the page cache dropped,
loading the metadata takes 3.1 ms read into the heap, 3.8 ms populated
without the read-ahead and 2.2 ms with it.
* fix: log a metadata format mismatch
The exception thrown for metadata in another format is raised before
anything is set up to report it, so on its own it never reached logcat.1 parent 3c798e2 commit b70544e
9 files changed
Lines changed: 438 additions & 410 deletions
File tree
- test-app
- build-tools/android-metadata-generator/src/src/com/telerik/metadata
- runtime/src/main/cpp
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
38 | 38 | | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | 43 | | |
44 | 44 | | |
| |||
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
85 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
86 | 88 | | |
87 | 89 | | |
88 | 90 | | |
| |||
111 | 113 | | |
112 | 114 | | |
113 | 115 | | |
114 | | - | |
| 116 | + | |
115 | 117 | | |
116 | | - | |
| 118 | + | |
117 | 119 | | |
118 | 120 | | |
119 | 121 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
| 5 | + | |
4 | 6 | | |
5 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
6 | 13 | | |
7 | 14 | | |
8 | | - | |
| 15 | + | |
9 | 16 | | |
10 | 17 | | |
11 | 18 | | |
12 | 19 | | |
13 | | - | |
| 20 | + | |
14 | 21 | | |
15 | 22 | | |
16 | 23 | | |
| |||
19 | 26 | | |
20 | 27 | | |
21 | 28 | | |
| 29 | + | |
22 | 30 | | |
23 | 31 | | |
24 | 32 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
7 | 23 | | |
8 | | - | |
| 24 | + | |
9 | 25 | | |
10 | 26 | | |
11 | 27 | | |
12 | 28 | | |
13 | | - | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
14 | 39 | | |
15 | 40 | | |
16 | 41 | | |
17 | | - | |
| 42 | + | |
18 | 43 | | |
19 | 44 | | |
20 | 45 | | |
21 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
22 | 51 | | |
23 | 52 | | |
24 | | - | |
25 | | - | |
| 53 | + | |
| 54 | + | |
26 | 55 | | |
27 | 56 | | |
28 | 57 | | |
| |||
57 | 86 | | |
58 | 87 | | |
59 | 88 | | |
60 | | - | |
| 89 | + | |
61 | 90 | | |
62 | 91 | | |
63 | 92 | | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
77 | | - | |
78 | | - | |
79 | | - | |
80 | | - | |
81 | | - | |
82 | | - | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
| 93 | + | |
| 94 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
10 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
11 | 19 | | |
12 | 20 | | |
| 21 | + | |
13 | 22 | | |
14 | | - | |
15 | | - | |
16 | | - | |
17 | | - | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | | - | |
24 | | - | |
25 | | - | |
26 | | - | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
| 23 | + | |
| 24 | + | |
35 | 25 | | |
36 | 26 | | |
37 | 27 | | |
38 | 28 | | |
39 | 29 | | |
40 | 30 | | |
| 31 | + | |
41 | 32 | | |
42 | 33 | | |
43 | 34 | | |
| |||
49 | 40 | | |
50 | 41 | | |
51 | 42 | | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
62 | 46 | | |
| 47 | + | |
63 | 48 | | |
64 | 49 | | |
65 | 50 | | |
| |||
0 commit comments