Skip to content
This repository has been archived by the owner on Jun 18, 2022. It is now read-only.

Commit

Permalink
Implement the 'trivially retained size' metric.
Browse files Browse the repository at this point in the history
The trivially retained size is the size of an element
plus the sizes of all the elements that are guaranteed
to only be reachable from that function.  This algorithm
should not give any false-positives, but it may choose not
to account for elements that should actually be added.
  • Loading branch information
Ty Overby committed Aug 28, 2014
1 parent 4ef2ebb commit b1f8d63
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 23 deletions.
35 changes: 27 additions & 8 deletions web/format_versions/version1.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,21 @@ class ViewVersion1 {
}

void display() {
treeTable.columnTitles = ['Kind', 'Name', 'Bytes', '%', 'Type'];
treeTable.columnInfo(
// Names
['Kind', 'Name', 'Bytes', 'Bytes R', '%', 'Type'],
// Help Info
[
'',
'The given name of the element',
'The direct size attributed to the element',
'The sum of the sizes of all the elements that can '
'only be reached from this element',
'The percentage of the direct size compared to the program size',
'The given type of the element'
],
// Sizes
["200px", null, "100px", "100px", "70px", null]);

_setupProgramwideInfo();

Expand Down Expand Up @@ -110,7 +124,8 @@ class ViewVersion1 {
int level, Function fetch) {

// A helper method for generating a row-generating function.
GenerateRowFunction renderSelfWith(Function renderFn, {int sortPriority: 0}) {
GenerateRowFunction renderSelfWith(Function renderFn,
{int sortPriority: 0}) {
void render(TreeTableRow row, LogicalRow lRow) {
row.data = renderFn();
}
Expand All @@ -130,13 +145,13 @@ class ViewVersion1 {
case 'method':
// Side Effects
row.addChild(renderSelfWith(() =>
[_cell('side effects'), _cell(node['sideEffects'], colspan: '4')]));
[_cell('side effects'), _cell(node['sideEffects'], colspan: '5')]));
// Modifiers
if (node.containsKey('modifiers')) {
(node['modifiers'] as Map<String, bool>).forEach((k, v) {
if (v) {
row.addChild(renderSelfWith(() =>
[_cell('modifier'), _cell(k, colspan: '4')]));
[_cell('modifier'), _cell(k, colspan: '5')]));
}
});
}
Expand All @@ -145,7 +160,7 @@ class ViewVersion1 {
[_cell('return type'), _verticalCell(
'inferred: ${node['inferredReturnType']},',
' declared: ${node['returnType']}',
colspan: '4')
colspan: '5')
]));
// Parameters
if (node.containsKey('parameters')) {
Expand All @@ -165,15 +180,15 @@ class ViewVersion1 {
// Code
if (node['code'] != null && node['code'].length != 0) {
row.addChild(renderSelfWith(() =>
[_cell('code'), _cell(node['code'], colspan: '4', pre: true)],
[_cell('code'), _cell(node['code'], colspan: '5', pre: true)],
sortPriority: -1));
}
break;
case 'field':
// Code
if (node['code'] != null && node['code'].length != 0) {
row.addChild(renderSelfWith(() =>
[_cell('code'), _cell(node['code'], colspan: '4', pre: true)],
[_cell('code'), _cell(node['code'], colspan: '5', pre: true)],
sortPriority: -1));
}
// Types
Expand All @@ -183,7 +198,7 @@ class ViewVersion1 {
_verticalCell(
'inferred: ${node['inferredType']}',
'declared: ${node['type']}',
colspan: '4', pre: true)]));
colspan: '5', pre: true)]));
}
break;
case 'class':
Expand Down Expand Up @@ -223,6 +238,7 @@ class ViewVersion1 {
new ImageElement(src: 'deps_icon.svg')..style.float = 'right'),
]),
_cell(props['size'], align: 'right'),
_cell(model.triviallyOwnedSize(props['id']), align: 'right'),
_cell(props['size_percent'], align: 'right'),
_cell(props['type'], pre: true)
]);
Expand All @@ -231,6 +247,7 @@ class ViewVersion1 {
cells.addAll([
_cell(props['name']),
_cell(props['size'], align: 'right'),
_cell(''),
_cell(props['size_percent'], align: 'right'),
_cell('')
]);
Expand All @@ -239,13 +256,15 @@ class ViewVersion1 {
cells.addAll([
_cell(props['name']),
_cell('0', align: 'right'),
_cell('0', align: 'right'),
_cell('0.00%', align:'right')
]);
break;
case 'class':
cells.addAll([
_cell(props['name']),
_cell(props['size'], align: 'right'),
_cell(''),
_cell(props['size_percent'], align:'right'),
_cell(props['name'], pre: true)
]);
Expand Down
29 changes: 29 additions & 0 deletions web/infohelper.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:collection' show Queue;

class Selection {
String elementId;
String mask;
Expand Down Expand Up @@ -116,4 +118,31 @@ class InfoHelper {
traverseNames(node, []);
}
}

bool _parentsAllContained(String id, Set<String> container) =>
reverseDependencies(id).every((a) => container.contains(a.elementId));

Set<String> _triviallyReachedFrom(String id) {
Queue<String> queue = new Queue<String>();
Set<String> owns = new Set<String>();

queue.add(id);
owns.add(id);

while (queue.isNotEmpty) {
String next = queue.removeFirst();
for (String child in dependencies(next).map((a) => a.elementId)) {
if (!owns.contains(child) && _parentsAllContained(child, owns)) {
queue.add(child);
owns.add(child);
}
}
}
return owns;
}

int triviallyOwnedSize(String id) =>
_triviallyReachedFrom(id)
.map((a) => properties(a)['size'])
.reduce((a, b) => a + b);
}
26 changes: 11 additions & 15 deletions web/polymer_lib/tree_table.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,18 @@ class TreeTable extends PolymerElement {
/**
* Sets the titles for the columns of the table.
*/
void set columnTitles(List<String> names) {
this.$['inner_table_head'].children.addAll(names.map((name) {
var tableCell = new TableCellElement()..text = name;
// TODO(tyoverby): special cases are bad

if (name == 'Bytes' || name == '%') {
tableCell.style.width = '70px';
}
if (name == 'Kind') {
tableCell.style.width = '160px';
void columnInfo(List<String> names, List<String> helps, List<String> sizes) {
for (int i = 0; i < names.length; i ++) {
TableCellElement cell = new TableCellElement();
cell.style.textAlign = 'center';
cell.text = names[i];
cell.title = helps[i];
int size = sizes[i];
if (size != null) {
cell.style.width = size;
}
if (name == 'Name') {
tableCell.style.width = '300px';
}
return tableCell;
}));
this.$['inner_table_head'].children.add(cell);
}
}

/**
Expand Down

0 comments on commit b1f8d63

Please sign in to comment.