Commit 0d0232e
authored
Optimise out block header calculation (#8446)
This is a `tracing`-driven optimisation. While investigating why Lighthouse is slow to send `newPayload`, I found a suspicious 13ms of computation on the hot path in `gossip_block_into_execution_pending_block_slashable`:
<img width="1998" height="1022" alt="headercalc" src="https://github.com/user-attachments/assets/e4f88c1a-da23-47b4-b533-cf5479a1c55c" />
Looking at the current implementation we can see that the _only_ thing that happens prior to calling into `from_gossip_verified_block` is the calculation of a `header`. We first call `SignatureVerifiedBlock::from_gossip_verified_block_check_slashable`:
https://github.com/sigp/lighthouse/blob/261322c3e3ee467c9454fa160a00866439cbc62f/beacon_node/beacon_chain/src/block_verification.rs#L1075-L1076
Which is where the `header` is calculated prior to calling `from_gossip_verified_block`:
https://github.com/sigp/lighthouse/blob/261322c3e3ee467c9454fa160a00866439cbc62f/beacon_node/beacon_chain/src/block_verification.rs#L1224-L1226
Notice that the `header` is _only_ used in the case of an error, yet we spend time computing it every time!
This PR moves the calculation of the header (which involves hashing the whole beacon block, including the execution payload), into the error case. We take a cheap clone of the `Arc`'d beacon block on the hot path, and use this for calculating the header _only_ in the case an error actually occurs. This shaves 10-20ms off our pre-newPayload delays, and 10-20ms off every block processing 🎉
Co-Authored-By: Michael Sproul <michael@sigmaprime.io>1 parent 2ba8a8e commit 0d0232e
File tree
2 files changed
+14
-8
lines changed- beacon_node/beacon_chain/src
- consensus/types/src
2 files changed
+14
-8
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1164 | 1164 | | |
1165 | 1165 | | |
1166 | 1166 | | |
1167 | | - | |
| 1167 | + | |
1168 | 1168 | | |
1169 | | - | |
| 1169 | + | |
1170 | 1170 | | |
1171 | 1171 | | |
1172 | 1172 | | |
| |||
1221 | 1221 | | |
1222 | 1222 | | |
1223 | 1223 | | |
1224 | | - | |
1225 | | - | |
1226 | | - | |
| 1224 | + | |
| 1225 | + | |
| 1226 | + | |
| 1227 | + | |
| 1228 | + | |
| 1229 | + | |
| 1230 | + | |
1227 | 1231 | | |
1228 | 1232 | | |
1229 | 1233 | | |
| |||
1248 | 1252 | | |
1249 | 1253 | | |
1250 | 1254 | | |
1251 | | - | |
| 1255 | + | |
1252 | 1256 | | |
1253 | 1257 | | |
1254 | 1258 | | |
1255 | 1259 | | |
1256 | | - | |
| 1260 | + | |
1257 | 1261 | | |
1258 | 1262 | | |
1259 | 1263 | | |
| |||
1264 | 1268 | | |
1265 | 1269 | | |
1266 | 1270 | | |
1267 | | - | |
| 1271 | + | |
1268 | 1272 | | |
1269 | 1273 | | |
1270 | 1274 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| |||
253 | 254 | | |
254 | 255 | | |
255 | 256 | | |
| 257 | + | |
256 | 258 | | |
257 | 259 | | |
258 | 260 | | |
| |||
0 commit comments