Commit 7d0db1e
committed
Auto merge of rust-lang#2647 - saethlin:current-span, r=RalfJung
Track local frames incrementally during execution
rust-lang/miri#2646 currently introduces a performance regression. This change removes that regression, and provides a minor perf improvement.
The existing lazy strategy for tracking the span we want to display is as efficient as it is only because we often create a `CurrentSpan` then never call `.get()`. Most of the calls to the `before_memory_read` and `before_memory_write` hooks do not create any event that we store in `AllocHistory`. But data races are totally different, any memory read or write may race, so every call to those hooks needs to access to the current local span.
So this changes to a strategy where we update some state in a `Thread` and `FrameExtra` incrementally, upon entering and existing each function call.
Before:
```
Benchmark 1: cargo +miri miri run --manifest-path /home/ben/miri/bench-cargo-miri/backtraces/Cargo.toml
Time (mean ± σ): 5.532 s ± 0.022 s [User: 5.444 s, System: 0.073 s]
Range (min … max): 5.516 s … 5.569 s 5 runs
Benchmark 1: cargo +miri miri run --manifest-path /home/ben/miri/bench-cargo-miri/mse/Cargo.toml
Time (mean ± σ): 831.4 ms ± 3.0 ms [User: 783.8 ms, System: 46.7 ms]
Range (min … max): 828.7 ms … 836.1 ms 5 runs
Benchmark 1: cargo +miri miri run --manifest-path /home/ben/miri/bench-cargo-miri/serde1/Cargo.toml
Time (mean ± σ): 1.975 s ± 0.021 s [User: 1.914 s, System: 0.059 s]
Range (min … max): 1.939 s … 1.990 s 5 runs
Benchmark 1: cargo +miri miri run --manifest-path /home/ben/miri/bench-cargo-miri/serde2/Cargo.toml
Time (mean ± σ): 4.060 s ± 0.051 s [User: 3.983 s, System: 0.071 s]
Range (min … max): 3.972 s … 4.100 s 5 runs
Benchmark 1: cargo +miri miri run --manifest-path /home/ben/miri/bench-cargo-miri/slice-get-unchecked/Cargo.toml
Time (mean ± σ): 784.9 ms ± 8.2 ms [User: 746.5 ms, System: 37.7 ms]
Range (min … max): 772.9 ms … 793.3 ms 5 runs
Benchmark 1: cargo +miri miri run --manifest-path /home/ben/miri/bench-cargo-miri/unicode/Cargo.toml
Time (mean ± σ): 1.679 s ± 0.006 s [User: 1.623 s, System: 0.055 s]
Range (min … max): 1.673 s … 1.687 s 5 runs
```
After:
```
Benchmark 1: cargo +miri miri run --manifest-path /home/ben/miri/bench-cargo-miri/backtraces/Cargo.toml
Time (mean ± σ): 5.330 s ± 0.037 s [User: 5.232 s, System: 0.084 s]
Range (min … max): 5.280 s … 5.383 s 5 runs
Benchmark 1: cargo +miri miri run --manifest-path /home/ben/miri/bench-cargo-miri/mse/Cargo.toml
Time (mean ± σ): 818.9 ms ± 3.7 ms [User: 776.8 ms, System: 41.3 ms]
Range (min … max): 813.5 ms … 822.5 ms 5 runs
Benchmark 1: cargo +miri miri run --manifest-path /home/ben/miri/bench-cargo-miri/serde1/Cargo.toml
Time (mean ± σ): 1.927 s ± 0.011 s [User: 1.864 s, System: 0.061 s]
Range (min … max): 1.917 s … 1.945 s 5 runs
Benchmark 1: cargo +miri miri run --manifest-path /home/ben/miri/bench-cargo-miri/serde2/Cargo.toml
Time (mean ± σ): 3.974 s ± 0.020 s [User: 3.893 s, System: 0.076 s]
Range (min … max): 3.956 s … 4.004 s 5 runs
Benchmark 1: cargo +miri miri run --manifest-path /home/ben/miri/bench-cargo-miri/slice-get-unchecked/Cargo.toml
Time (mean ± σ): 780.0 ms ± 5.3 ms [User: 740.3 ms, System: 39.0 ms]
Range (min … max): 771.2 ms … 784.5 ms 5 runs
Benchmark 1: cargo +miri miri run --manifest-path /home/ben/miri/bench-cargo-miri/unicode/Cargo.toml
Time (mean ± σ): 1.643 s ± 0.007 s [User: 1.584 s, System: 0.058 s]
Range (min … max): 1.635 s … 1.654 s 5 runs
```
(This change is marginal, but the point is that it avoids a much more significant regression)File tree
6 files changed
+153
-161
lines changed- src/tools/miri/src
- concurrency
- stacked_borrows
6 files changed
+153
-161
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
118 | 118 | | |
119 | 119 | | |
120 | 120 | | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
121 | 128 | | |
122 | 129 | | |
123 | 130 | | |
| |||
147 | 154 | | |
148 | 155 | | |
149 | 156 | | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
150 | 191 | | |
151 | 192 | | |
152 | 193 | | |
| |||
167 | 208 | | |
168 | 209 | | |
169 | 210 | | |
| 211 | + | |
170 | 212 | | |
171 | 213 | | |
172 | 214 | | |
| |||
184 | 226 | | |
185 | 227 | | |
186 | 228 | | |
187 | | - | |
188 | | - | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
189 | 238 | | |
190 | 239 | | |
191 | 240 | | |
| |||
414 | 463 | | |
415 | 464 | | |
416 | 465 | | |
417 | | - | |
| 466 | + | |
418 | 467 | | |
419 | 468 | | |
420 | 469 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
936 | 936 | | |
937 | 937 | | |
938 | 938 | | |
939 | | - | |
940 | | - | |
941 | | - | |
942 | | - | |
943 | | - | |
944 | | - | |
945 | | - | |
946 | | - | |
947 | | - | |
948 | | - | |
949 | | - | |
950 | | - | |
951 | | - | |
952 | | - | |
953 | | - | |
954 | | - | |
955 | | - | |
956 | | - | |
957 | | - | |
958 | | - | |
959 | | - | |
| 939 | + | |
| 940 | + | |
960 | 941 | | |
961 | | - | |
962 | | - | |
963 | | - | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
964 | 947 | | |
965 | 948 | | |
966 | 949 | | |
967 | 950 | | |
968 | 951 | | |
969 | 952 | | |
970 | 953 | | |
971 | | - | |
| 954 | + | |
972 | 955 | | |
973 | | - | |
974 | | - | |
975 | | - | |
976 | | - | |
977 | | - | |
| 956 | + | |
| 957 | + | |
| 958 | + | |
| 959 | + | |
978 | 960 | | |
979 | 961 | | |
980 | 962 | | |
981 | | - | |
| 963 | + | |
982 | 964 | | |
983 | 965 | | |
984 | | - | |
985 | | - | |
986 | | - | |
987 | | - | |
| 966 | + | |
| 967 | + | |
988 | 968 | | |
989 | 969 | | |
990 | | - | |
991 | | - | |
992 | | - | |
993 | | - | |
994 | | - | |
995 | | - | |
996 | | - | |
997 | | - | |
998 | | - | |
999 | | - | |
1000 | | - | |
1001 | | - | |
1002 | | - | |
1003 | | - | |
1004 | | - | |
1005 | | - | |
1006 | | - | |
1007 | | - | |
1008 | | - | |
1009 | | - | |
1010 | | - | |
| 970 | + | |
| 971 | + | |
| 972 | + | |
| 973 | + | |
| 974 | + | |
1011 | 975 | | |
1012 | 976 | | |
1013 | 977 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
97 | 97 | | |
98 | 98 | | |
99 | 99 | | |
100 | | - | |
| 100 | + | |
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
50 | 50 | | |
51 | 51 | | |
52 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
53 | 59 | | |
54 | 60 | | |
55 | 61 | | |
56 | 62 | | |
57 | 63 | | |
58 | | - | |
| 64 | + | |
59 | 65 | | |
60 | 66 | | |
61 | 67 | | |
| |||
65 | 71 | | |
66 | 72 | | |
67 | 73 | | |
68 | | - | |
| 74 | + | |
69 | 75 | | |
70 | 76 | | |
71 | 77 | | |
| |||
895 | 901 | | |
896 | 902 | | |
897 | 903 | | |
898 | | - | |
899 | | - | |
900 | | - | |
901 | | - | |
902 | | - | |
903 | | - | |
904 | | - | |
| 904 | + | |
905 | 905 | | |
906 | 906 | | |
907 | 907 | | |
| |||
1016 | 1016 | | |
1017 | 1017 | | |
1018 | 1018 | | |
1019 | | - | |
1020 | | - | |
| 1019 | + | |
1021 | 1020 | | |
1022 | 1021 | | |
1023 | 1022 | | |
| |||
1048 | 1047 | | |
1049 | 1048 | | |
1050 | 1049 | | |
1051 | | - | |
1052 | | - | |
| 1050 | + | |
1053 | 1051 | | |
1054 | 1052 | | |
1055 | 1053 | | |
| |||
1083 | 1081 | | |
1084 | 1082 | | |
1085 | 1083 | | |
1086 | | - | |
1087 | | - | |
| 1084 | + | |
1088 | 1085 | | |
1089 | 1086 | | |
1090 | 1087 | | |
| |||
1126 | 1123 | | |
1127 | 1124 | | |
1128 | 1125 | | |
| 1126 | + | |
1129 | 1127 | | |
| 1128 | + | |
1130 | 1129 | | |
1131 | 1130 | | |
1132 | 1131 | | |
| |||
1174 | 1173 | | |
1175 | 1174 | | |
1176 | 1175 | | |
| 1176 | + | |
| 1177 | + | |
| 1178 | + | |
| 1179 | + | |
| 1180 | + | |
| 1181 | + | |
| 1182 | + | |
1177 | 1183 | | |
1178 | 1184 | | |
1179 | 1185 | | |
| |||
1183 | 1189 | | |
1184 | 1190 | | |
1185 | 1191 | | |
| 1192 | + | |
| 1193 | + | |
| 1194 | + | |
| 1195 | + | |
| 1196 | + | |
| 1197 | + | |
| 1198 | + | |
1186 | 1199 | | |
1187 | 1200 | | |
1188 | 1201 | | |
| |||
0 commit comments