For P2SH inputs, GetPubKeyFromInput evaluated the full scriptSig with EvalScript and then ran Solver on the redeem script, even though only P2SH-P2WPKH is eligible for BIP-352. That costs time on every non-segwit P2SH spend (e.g. multisig), whose scriptSigs can be up to MAX_SCRIPT_SIZE.
BIP-141 requires the scriptSig of a P2SH-wrapped witness program to be exactly a single push of the redeem script (SCRIPT_ERR_WITNESS_MALLEATED_P2SH). So any valid P2SH-P2WPKH scriptSig is exactly 0x16 OP_0 0x14 <20-byte keyhash>, and matching that template gives the same result without evaluating anything.
Benchmarks
bench_bitcoin -filter='BIP352_GetPubKey_P2SH_.*' -min-time=2000, Release build.
Before:
| ns/input | input/s | err% | total | benchmark | |
|---|---|---|---|---|---|
| 688.30 | 1,452,858.07 | 0.1% | 2.20 | BIP352_GetPubKey_P2SH_Multisig |
|
| 7,158.19 | 139,700.11 | 0.1% | 2.20 | BIP352_GetPubKey_P2SH_P2WPKH |
After:
| ns/input | input/s | err% | total | benchmark | |
|---|---|---|---|---|---|
| 56.87 | 17,584,611.40 | 0.0% | 2.20 | BIP352_GetPubKey_P2SH_Multisig |
|
| 6,949.45 | 143,896.18 | 0.0% | 2.20 | BIP352_GetPubKey_P2SH_P2WPKH |
P2SH multisig is about 12x faster to rule out. P2SH-P2WPKH saves about 200 ns per input; its time is still dominated by CPubKey::IsFullyValid().