Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Root table items; reverse table/elem edge directions #153

Merged
merged 4 commits into from
Sep 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ out to us in a GitHub issue, or ping `fitzgen` in [`#rust-wasm` on

- [Code of Conduct](#code-of-conduct)
- [Building and Testing](#building-and-testing)
- [Building](#building)
- [Building for the Native Target](#building-for-the-native-target)
- [Building for the `wasm32-unknown-unknown` Target](#building-for-the-wasm32-unknown-unknown-target)
- [Testing](#testing)
- [Authoring New Tests](#authoring-new-tests)
- [Updating Test Expectations](#updating-test-expectations)
- [Automatic Code Formatting](#automatic-code-formatting)
- [Pull Requests](#pull-requests)
- [Contributions We Want](#contributions-we-want)
Expand Down Expand Up @@ -64,6 +66,12 @@ twiggy/tests
* The `twiggy/tests/expectations` directory contains the expected output of test
commands.

#### Updating Test Expectations

To automatically update all test expectations, you can run the tests with the
`TWIGGY_UPDATE_TEST_EXPECTATIONS=1` environment variable set. Make sure that you
look at the changes before committing them, and that they match your intentions!

## Automatic Code Formatting

We use [`rustfmt`](https://github.com/rust-lang-nursery/rustfmt) to enforce a
Expand Down
4 changes: 2 additions & 2 deletions parser/wasm_parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ impl<'a> Parse<'a> for elements::TableSection {
let size = serialized_size(entry.clone())?;
let mut name = String::with_capacity("table[]".len() + 4);
write!(&mut name, "table[{}]", i)?;
items.add_item(ir::Item::new(id, name, size, ir::Misc::new()));
items.add_root(ir::Item::new(id, name, size, ir::Misc::new()));
}
Ok(())
}
Expand Down Expand Up @@ -559,7 +559,7 @@ impl<'a> Parse<'a> for elements::ElementSection {
let elem_id = Id::entry(idx, i);
if let Some(table_section_idx) = table_section_idx {
let entry_id = Id::entry(table_section_idx, elem.index() as usize);
items.add_edge(elem_id, entry_id);
items.add_edge(entry_id, elem_id);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logically it is the table that owns its
elements. It gives us much more useful data this way: we can see when the table
is heavy in the dominators tree, because a bunch of dynamic indirect calls that
the linker couldn't remove got entrenched in the binary.

It took a second for me to understand this, but ❗ omg! ❗

Would not have thought of this, ! This is so cool :)

}
for &func_idx in elem.members() {
// A table element's initializer function can be an imported
Expand Down
2 changes: 1 addition & 1 deletion twiggy/tests/all/expectations/diff_wee_alloc_json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"delta_bytes":-1034,"name":"data[3]"},{"delta_bytes":-593,"name":"\"function names\" subsection"},{"delta_bytes":395,"name":"wee_alloc::alloc_first_fit::he2a4ddf96981c0ce"},{"delta_bytes":243,"name":"goodbye"},{"delta_bytes":-225,"name":"wee_alloc::alloc_first_fit::h9a72de3af77ef93f"},{"delta_bytes":-152,"name":"wee_alloc::alloc_with_refill::hb32c1bbce9ebda8e"},{"delta_bytes":145,"name":"<wee_alloc::neighbors::Neighbors<'a, T>>::remove::hc9e5d4284e8233b8"},{"delta_bytes":-136,"name":"<wee_alloc::size_classes::SizeClassAllocPolicy<'a> as wee_alloc::AllocPolicy>::new_cell_for_free_list::h3987e3054b8224e6"},{"delta_bytes":-76,"name":"<wee_alloc::LargeAllocPolicy as wee_alloc::AllocPolicy>::new_cell_for_free_list::h8f071b7bce0301ba"},{"delta_bytes":-25,"name":"data[1]"},{"delta_bytes":-25,"name":"data[2]"},{"delta_bytes":15,"name":"hello"},{"delta_bytes":15,"name":"import env::rust_oom"},{"delta_bytes":12,"name":"custom section 'linking'"},{"delta_bytes":-12,"name":"elem[0]"},{"delta_bytes":8,"name":"global[0]"},{"delta_bytes":-8,"name":"type[4]"},{"delta_bytes":-6,"name":"<wee_alloc::LargeAllocPolicy as wee_alloc::AllocPolicy>::min_cell_size::hc7cee2a550987099"},{"delta_bytes":6,"name":"alloc::alloc::oom::h45ae3f22a516fb04"},{"delta_bytes":-5,"name":"<wee_alloc::size_classes::SizeClassAllocPolicy<'a> as wee_alloc::AllocPolicy>::min_cell_size::h6f746be886573355"},{"delta_bytes":-21,"name":"... and 13 more."},{"delta_bytes":-1476,"name":"Σ [33 Total Rows]"}]
[{"delta_bytes":-1034,"name":"data[3]"},{"delta_bytes":-593,"name":"\"function names\" subsection"},{"delta_bytes":395,"name":"wee_alloc::alloc_first_fit::he2a4ddf96981c0ce"},{"delta_bytes":243,"name":"goodbye"},{"delta_bytes":-225,"name":"wee_alloc::alloc_first_fit::h9a72de3af77ef93f"},{"delta_bytes":-152,"name":"wee_alloc::alloc_with_refill::hb32c1bbce9ebda8e"},{"delta_bytes":145,"name":"<wee_alloc::neighbors::Neighbors<'a, T>>::remove::hc9e5d4284e8233b8"},{"delta_bytes":-136,"name":"<wee_alloc::size_classes::SizeClassAllocPolicy<'a> as wee_alloc::AllocPolicy>::new_cell_for_free_list::h3987e3054b8224e6"},{"delta_bytes":-76,"name":"<wee_alloc::LargeAllocPolicy as wee_alloc::AllocPolicy>::new_cell_for_free_list::h8f071b7bce0301ba"},{"delta_bytes":-25,"name":"data[1]"},{"delta_bytes":-25,"name":"data[2]"},{"delta_bytes":15,"name":"hello"},{"delta_bytes":15,"name":"import env::rust_oom"},{"delta_bytes":12,"name":"custom section 'linking'"},{"delta_bytes":-12,"name":"elem[0]"},{"delta_bytes":8,"name":"global[0]"},{"delta_bytes":-8,"name":"type[4]"},{"delta_bytes":-6,"name":"<wee_alloc::LargeAllocPolicy as wee_alloc::AllocPolicy>::min_cell_size::hc7cee2a550987099"},{"delta_bytes":6,"name":"alloc::alloc::oom::h45ae3f22a516fb04"},{"delta_bytes":-5,"name":"<wee_alloc::size_classes::SizeClassAllocPolicy<'a> as wee_alloc::AllocPolicy>::min_cell_size::h6f746be886573355"},{"delta_bytes":-21,"name":"... and 13 more."},{"delta_bytes":-1476,"name":"Σ [33 Total Rows]"}]
2 changes: 1 addition & 1 deletion twiggy/tests/all/expectations/diff_wee_alloc_json_top_5
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"delta_bytes":-1034,"name":"data[3]"},{"delta_bytes":-593,"name":"\"function names\" subsection"},{"delta_bytes":395,"name":"wee_alloc::alloc_first_fit::he2a4ddf96981c0ce"},{"delta_bytes":243,"name":"goodbye"},{"delta_bytes":-225,"name":"wee_alloc::alloc_first_fit::h9a72de3af77ef93f"},{"delta_bytes":-265,"name":"... and 28 more."},{"delta_bytes":-1476,"name":"Σ [33 Total Rows]"}]
[{"delta_bytes":-1034,"name":"data[3]"},{"delta_bytes":-593,"name":"\"function names\" subsection"},{"delta_bytes":395,"name":"wee_alloc::alloc_first_fit::he2a4ddf96981c0ce"},{"delta_bytes":243,"name":"goodbye"},{"delta_bytes":-225,"name":"wee_alloc::alloc_first_fit::h9a72de3af77ef93f"},{"delta_bytes":-265,"name":"... and 28 more."},{"delta_bytes":-1476,"name":"Σ [33 Total Rows]"}]
45 changes: 32 additions & 13 deletions twiggy/tests/all/expectations/dominators_wee_alloc
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
Retained Bytes │ Retained % │ Dominator Tree
────────────────┼────────────┼────────────────────────────────────────────────────────────────────────
────────────────┼────────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
774 ┊ 27.48% ┊ "function names" subsection
573 ┊ 20.34% ┊ export "hello"
565 ┊ 20.06% ┊ ⤷ func[8]
560 ┊ 19.88% ┊ ⤷ hello
387 ┊ 13.74% ┊ ⤷ func[2]
378 ┊ 13.42% ┊ ⤷ wee_alloc::alloc_with_refill::hb32c1bbce9ebda8e
226 ┊ 8.02% ┊ ⤷ func[3]
225 ┊ 7.99% ┊ ⤷ wee_alloc::alloc_first_fit::h9a72de3af77ef93f
8 ┊ 0.28% ┊ ⤷ type[4]
9 ┊ 0.32% ┊ ⤷ data[0]
387 ┊ 13.74% ┊ func[2]
378 ┊ 13.42% ┊ ⤷ wee_alloc::alloc_with_refill::hb32c1bbce9ebda8e
226 ┊ 8.02% ┊ ⤷ func[3]
225 ┊ 7.99% ┊ ⤷ wee_alloc::alloc_first_fit::h9a72de3af77ef93f
8 ┊ 0.28% ┊ ⤷ type[4]
271 ┊ 9.62% ┊ table[0]
267 ┊ 9.48% ┊ ⤷ elem[0]
137 ┊ 4.86% ┊ ⤷ func[5]
136 ┊ 4.83% ┊ ⤷ <wee_alloc::size_classes::SizeClassAllocPolicy<'a> as wee_alloc::AllocPolicy>::new_cell_for_free_list::h3987e3054b8224e6
77 ┊ 2.73% ┊ ⤷ func[0]
76 ┊ 2.70% ┊ ⤷ <wee_alloc::LargeAllocPolicy as wee_alloc::AllocPolicy>::new_cell_for_free_list::h8f071b7bce0301ba
8 ┊ 0.28% ┊ ⤷ func[10]
4 ┊ 0.14% ┊ ⤷ __wasm_nullptr
3 ┊ 0.11% ┊ ⤷ type[2]
7 ┊ 0.25% ┊ ⤷ func[1]
6 ┊ 0.21% ┊ ⤷ <wee_alloc::LargeAllocPolicy as wee_alloc::AllocPolicy>::min_cell_size::hc7cee2a550987099
6 ┊ 0.21% ┊ ⤷ type[0]
6 ┊ 0.21% ┊ ⤷ type[1]
6 ┊ 0.21% ┊ ⤷ func[7]
5 ┊ 0.18% ┊ ⤷ <wee_alloc::size_classes::SizeClassAllocPolicy<'a> as wee_alloc::AllocPolicy>::min_cell_size::h6f746be886573355
4 ┊ 0.14% ┊ ⤷ func[4]
3 ┊ 0.11% ┊ ⤷ core::ptr::drop_in_place::h8e9fdc2437d43666
4 ┊ 0.14% ┊ ⤷ func[6]
3 ┊ 0.11% ┊ ⤷ core::ptr::drop_in_place::h4e5cdfd7b9310648.18
177 ┊ 6.28% ┊ export "hello"
169 ┊ 6.00% ┊ ⤷ func[8]
164 ┊ 5.82% ┊ ⤷ hello
4 ┊ 0.14% ┊ ⤷ type[5]
592.09% ┊ export "goodbye"
49 ┊ 1.74% ┊ ⤷ func[9]
551.95% ┊ export "goodbye"
45 ┊ 1.60% ┊ ⤷ func[9]
44 ┊ 1.56% ┊ ⤷ goodbye
4 ┊ 0.14% ┊ ⤷ type[3]
11 ┊ 0.39% ┊ export "memory"
2 ┊ 0.07% ┊ ⤷ memory[0]
9 ┊ 0.32% ┊ data[0]
4 ┊ 0.14% ┊ type[3]
37 changes: 28 additions & 9 deletions twiggy/tests/all/expectations/dominators_wee_alloc_csv
Original file line number Diff line number Diff line change
@@ -1,19 +1,38 @@
Id,Name,ShallowSize,ShallowSizePercent,RetainedSize,RetainedSizePercent,ImmediateDominator
18446744073709551615,<meta root>,0,0,1417,50.30173943911963,18446744073709551615
18446744073709551615,<meta root>,0,0,1688,59.92190273340433,18446744073709551615
38654705663,"""function names"" subsection",774,27.47603833865815,774,27.47603833865815,18446744073709551615
17179869185,"export ""hello""",8,0.2839900603478878,573,20.340788072417464,18446744073709551615
4294967304,func[8],1,0.03549875754348598,565,20.056798012069578,17179869185
25769803784,hello,164,5.8217962371317,560,19.879304224352147,4294967304
4294967298,func[2],1,0.03549875754348598,387,13.738019169329075,25769803784
4294967298,func[2],1,0.03549875754348598,387,13.738019169329075,18446744073709551615
25769803778,wee_alloc::alloc_with_refill::hb32c1bbce9ebda8e,152,5.395811146609868,378,13.418530351437699,4294967298
4294967299,func[3],1,0.03549875754348598,226,8.022719204827832,25769803778
25769803779,wee_alloc::alloc_first_fit::h9a72de3af77ef93f,225,7.987220447284344,225,7.987220447284344,4294967299
4,type[4],8,0.2839900603478878,8,0.2839900603478878,4294967298
30064771072,data[0],9,0.3194888178913738,9,0.3194888178913738,25769803784
8589934592,table[0],4,0.1419950301739439,271,9.620163294284701,18446744073709551615
21474836480,elem[0],12,0.42598509052183176,267,9.478168264110757,8589934592
4294967301,func[5],1,0.03549875754348598,137,4.863329783457579,21474836480
25769803781,<wee_alloc::size_classes::SizeClassAllocPolicy<'a> as wee_alloc::AllocPolicy>::new_cell_for_free_list::h3987e3054b8224e6,136,4.827831025914093,136,4.827831025914093,4294967301
4294967296,func[0],1,0.03549875754348598,77,2.7334043308484204,21474836480
25769803776,<wee_alloc::LargeAllocPolicy as wee_alloc::AllocPolicy>::new_cell_for_free_list::h8f071b7bce0301ba,76,2.697905573304934,76,2.697905573304934,4294967296
4294967306,func[10],1,0.03549875754348598,8,0.2839900603478878,21474836480
25769803786,__wasm_nullptr,4,0.1419950301739439,4,0.1419950301739439,4294967306
2,type[2],3,0.10649627263045794,3,0.10649627263045794,4294967306
4294967297,func[1],1,0.03549875754348598,7,0.24849130280440185,21474836480
25769803777,<wee_alloc::LargeAllocPolicy as wee_alloc::AllocPolicy>::min_cell_size::hc7cee2a550987099,6,0.21299254526091588,6,0.21299254526091588,4294967297
0,type[0],6,0.21299254526091588,6,0.21299254526091588,21474836480
1,type[1],6,0.21299254526091588,6,0.21299254526091588,21474836480
4294967303,func[7],1,0.03549875754348598,6,0.21299254526091588,21474836480
25769803783,<wee_alloc::size_classes::SizeClassAllocPolicy<'a> as wee_alloc::AllocPolicy>::min_cell_size::h6f746be886573355,5,0.1774937877174299,5,0.1774937877174299,4294967303
4294967300,func[4],1,0.03549875754348598,4,0.1419950301739439,21474836480
25769803780,core::ptr::drop_in_place::h8e9fdc2437d43666,3,0.10649627263045794,3,0.10649627263045794,4294967300
4294967302,func[6],1,0.03549875754348598,4,0.1419950301739439,21474836480
25769803782,core::ptr::drop_in_place::h4e5cdfd7b9310648.18,3,0.10649627263045794,3,0.10649627263045794,4294967302
17179869185,"export ""hello""",8,0.2839900603478878,177,6.283280085197019,18446744073709551615
4294967304,func[8],1,0.03549875754348598,169,5.999290024849131,17179869185
25769803784,hello,164,5.8217962371317,164,5.8217962371317,4294967304
5,type[5],4,0.1419950301739439,4,0.1419950301739439,4294967304
17179869186,"export ""goodbye""",10,0.3549875754348598,59,2.0944266950656725,18446744073709551615
4294967305,func[9],1,0.03549875754348598,49,1.7394391196308128,17179869186
17179869186,"export ""goodbye""",10,0.3549875754348598,55,1.9524316648917288,18446744073709551615
4294967305,func[9],1,0.03549875754348598,45,1.5974440894568689,17179869186
25769803785,goodbye,44,1.5619453319133831,44,1.5619453319133831,4294967305
3,type[3],4,0.1419950301739439,4,0.1419950301739439,4294967305
17179869184,"export ""memory""",9,0.3194888178913738,11,0.3904863329783458,18446744073709551615
12884901888,memory[0],2,0.07099751508697195,2,0.07099751508697195,17179869184
30064771072,data[0],9,0.3194888178913738,9,0.3194888178913738,18446744073709551615
3,type[3],4,0.1419950301739439,4,0.1419950301739439,18446744073709551615
Loading