found we can optimize CastToBool used by IFDUP, VERIFY while reviewing #36721.
Currently the loop checks one byte at a time, instead we can process one word of 8 bytes at a time.
For the worst case scenario of one-tx-block with a script <520-byte stack element> [IFDUP VERIFY] repeated, with the element being 519 zero bytes + 0x01:
the benchamrk shows 3.1x speedup (from ~922ms to ~295ms)
Master at https://github.com/bitcoin/bitcoin/commit/a527a0077a0fcae913188410214efe98021c0cca:
| ns/script | script/s | err% | total | benchmark | |
|---|---|---|---|---|---|
| 922,608,458.00 | 1.08 | 1.3% | 10.21 | VerifyIfDupVerifyFullLast |
This PR :
| ns/script | script/s | err% | total | benchmark | |
|---|---|---|---|---|---|
| 295,193,916.00 | 3.39 | 1.5% | 3.31 | VerifyIfDupVerifyFullLast |