Commit 4bf3fef
authored
tracing: improve code generation at trace points significantly (#3398)
`ValueSet`s contain both a `FieldSet` reference and a slice of
(`&Field`, `Option<&dyn Value>`) pairs. In cases where `ValueSet`s are
generated via documented interfaces (specifically, `tracing::event!` and
other macros), the `Field` references are redundant, because the
`ValueSet` contains a value slot for every field (either a value or
`None`), in the correct order.
As a result, the code generated by the macros is terrible--it must
put a `Field` on the stack for each field--that's 32 bytes per field!
This is a lot of work for apparently no purpose at runtime, and it
can't be moved into a read-only data section since it's intermixed with
dynamic data.
Fix this by adding a variant of `ValueSet` that skips the `Field`
references, knowing that it represents the full set of fields. Keep
the old kind of `ValueSet`, too--it's still needed by `Span::record`,
by old versions of crates, and potentially by third-party crates using
undocumented methods such as `FieldSet::value_set`.
In some adhoc tests on x86_64 Linux, this reduces the code size as
follows:
* One-field event: 258 bytes to 189 bytes, 25% reduction.
* Five-field event: 638 bytes to 276 bytes, **57%** reduction.
* In a larger project with lots of events, ~5% reduction in .text section.1 parent c47c777 commit 4bf3fef
2 files changed
+131
-124
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
165 | 165 | | |
166 | 166 | | |
167 | 167 | | |
168 | | - | |
| 168 | + | |
169 | 169 | | |
170 | 170 | | |
171 | 171 | | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
172 | 180 | | |
173 | 181 | | |
174 | 182 | | |
| |||
922 | 930 | | |
923 | 931 | | |
924 | 932 | | |
925 | | - | |
| 933 | + | |
| 934 | + | |
| 935 | + | |
| 936 | + | |
| 937 | + | |
| 938 | + | |
| 939 | + | |
| 940 | + | |
| 941 | + | |
| 942 | + | |
| 943 | + | |
| 944 | + | |
| 945 | + | |
| 946 | + | |
| 947 | + | |
| 948 | + | |
926 | 949 | | |
927 | 950 | | |
928 | 951 | | |
| |||
1033 | 1056 | | |
1034 | 1057 | | |
1035 | 1058 | | |
1036 | | - | |
1037 | | - | |
1038 | | - | |
1039 | | - | |
| 1059 | + | |
| 1060 | + | |
| 1061 | + | |
| 1062 | + | |
| 1063 | + | |
| 1064 | + | |
| 1065 | + | |
| 1066 | + | |
| 1067 | + | |
| 1068 | + | |
| 1069 | + | |
1040 | 1070 | | |
1041 | | - | |
1042 | | - | |
| 1071 | + | |
| 1072 | + | |
| 1073 | + | |
| 1074 | + | |
| 1075 | + | |
| 1076 | + | |
1043 | 1077 | | |
1044 | 1078 | | |
1045 | 1079 | | |
| |||
1050 | 1084 | | |
1051 | 1085 | | |
1052 | 1086 | | |
1053 | | - | |
1054 | | - | |
1055 | | - | |
1056 | | - | |
1057 | | - | |
| 1087 | + | |
| 1088 | + | |
| 1089 | + | |
| 1090 | + | |
| 1091 | + | |
| 1092 | + | |
| 1093 | + | |
| 1094 | + | |
| 1095 | + | |
| 1096 | + | |
1058 | 1097 | | |
1059 | 1098 | | |
1060 | 1099 | | |
1061 | 1100 | | |
1062 | | - | |
1063 | | - | |
1064 | | - | |
| 1101 | + | |
| 1102 | + | |
| 1103 | + | |
| 1104 | + | |
| 1105 | + | |
1065 | 1106 | | |
1066 | | - | |
| 1107 | + | |
| 1108 | + | |
| 1109 | + | |
1067 | 1110 | | |
1068 | 1111 | | |
1069 | 1112 | | |
1070 | 1113 | | |
1071 | | - | |
1072 | | - | |
1073 | | - | |
1074 | | - | |
| 1114 | + | |
| 1115 | + | |
| 1116 | + | |
| 1117 | + | |
| 1118 | + | |
| 1119 | + | |
| 1120 | + | |
| 1121 | + | |
| 1122 | + | |
1075 | 1123 | | |
1076 | 1124 | | |
1077 | 1125 | | |
| |||
1081 | 1129 | | |
1082 | 1130 | | |
1083 | 1131 | | |
1084 | | - | |
1085 | | - | |
1086 | | - | |
1087 | | - | |
1088 | | - | |
1089 | | - | |
1090 | | - | |
1091 | | - | |
1092 | | - | |
1093 | | - | |
| 1132 | + | |
| 1133 | + | |
| 1134 | + | |
1094 | 1135 | | |
1095 | 1136 | | |
1096 | 1137 | | |
1097 | 1138 | | |
1098 | 1139 | | |
1099 | | - | |
1100 | | - | |
1101 | | - | |
1102 | | - | |
1103 | | - | |
1104 | | - | |
1105 | | - | |
1106 | | - | |
1107 | | - | |
| 1140 | + | |
| 1141 | + | |
| 1142 | + | |
1108 | 1143 | | |
1109 | 1144 | | |
1110 | 1145 | | |
| |||
0 commit comments