submit_windowed_post no need alway to check the proven_sectors length
Proposal
windowpost message gasused are particularly high,
Background
I add gasused log in buildin-actors code. found the proven_sectors check can be optimized。
By example:
fvm_sdk::debug::log("xxxx p1-13".to_string());
let proven_sectors = &post_result.sectors - &post_result.ignored_sectors;
if proven_sectors.is_empty() {
// Abort verification if all sectors are (now) faults. There's nothing to prove.
// It's not rational for a miner to submit a Window PoSt marking *all* non-faulty sectors as skipped,
// since that will just cause them to pay a penalty at deadline end that would otherwise be zero
// if they had *not* declared them.
return Err(actor_error!(
illegal_argument,
"cannot prove partitions with no active sectors"
));
}
fvm_sdk::debug::log("xxxx p1-14".to_string());
got the log like this
2022-09-08T11:32:05.097 ERROR fvm::kernel::default > AL: xxxx p1-13; gas: 19823935.500
2022-09-08T11:32:05.097 ERROR fvm::kernel::default > AL: xxxx p1-14; gas: 19841139.500
but post_result.ignored_sectors is empy normal, we shoud check the ignored_sectors length first. it can save gas
Usually post_result.ignored_sectors is empty. The subtraction of Bitfield needs many CPU cycles. So checking it before subtraction is an optimization method.
Yeah, that works. But it would be nicer to just optimize that subtraction. But that's tricker.
Try running benchmarks with https://github.com/filecoin-project/ref-fvm/pull/849.
@Stebalien I used the https://github.com/filecoin-project/ref-fvm/pull/849. the result is very nice, but if i add check conditions if !post_result.ignored_sectors.is_empty() && !post_result.sectors.is_empty() the result is (I test another message) 2022-09-08T17:25:36.836 ERROR fvm::kernel::default > AL: xxxx p1-13; gas: 1118073682.500 2022-09-08T17:25:36.836 ERROR fvm::kernel::default > AL: xxxx p1-14; gas: 1118090962.500 just use the https://github.com/filecoin-project/ref-fvm/pull/849. result is 2022-09-08T17:06:55.032 ERROR fvm::kernel::default > AL: xxxx p1-13; gas: 1118073698.500 2022-09-08T17:06:55.032 ERROR fvm::kernel::default > AL: xxxx p1-14; gas: 1118130062.500
Yeah, #849 helps in the average case. In cases where we know we have a hotspot, it makes sense to optimize further.
Hey @marco-storswift! If you want to create a PR for this optimization, that would be great. But we will close the ticket for now, as this is not something that we plan to work on.