Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: allow computing a subset of costs in the estimator #4640

Merged
merged 4 commits into from
Sep 2, 2021

Conversation

matklad
Copy link
Contributor

@matklad matklad commented Aug 5, 2021

You can now pass something like

--metrics-to-measure Receipt,data_receipt_10b_1000,data_receipt_base_10b_1000

to calculate only those metrics. Note that metrics != costs. The end
goal is to do this for actual costs, as outlined in

#4633 (comment)

The current approach is an intermediate step in that direction. In
particular, it allows to debug estimator refactors much faster.

Test Plan

Manually run estimator to smoke test that this works, use a tool
(SSR)
to change extraction logic without introducing typos.

@matklad matklad force-pushed the matklad/cost-subset branch 3 times, most recently from 3d15776 to 369ccbd Compare August 25, 2021 15:14
@matklad matklad marked this pull request as ready for review August 25, 2021 15:15
@matklad matklad requested a review from olonho as a code owner August 25, 2021 15:15
You can now pass something like

  --metrics-to-measure Receipt,data_receipt_10b_1000,data_receipt_base_10b_1000

to calculate only those metrics. Note that metrics != costs. The end
goal is to do this for actual costs, as outlined in

  near#4633 (comment)

The current approach is an intermediate step in that direction. In
particular, it allows to debug estimator refactors much faster.

Test Plan
---------

Manually run estimator to smoke test that this works, use a tool
([SSR](https://rust-analyzer.github.io/manual.html#structural-search-and-replace))
to change extraction logic without introducing typos.
}

impl Config {
pub(crate) fn should_skip(&self, metric: Metric) -> bool {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Extracted this to a function, because there are two places where we check this. This is a smell, ideally we'd only check this once. However, the current curious pattern of passing in and returning a testbed prevents doing that without larger changes. I opted into not doing a larger refactor for testbed resuse logic -- I hope that in #4633 I just rewrite that logic entirely.

Luckily, & and && are equivalent enough for bool for this to not matter
@@ -294,7 +294,7 @@ pub fn run(mut config: Config, only_compile: bool) -> CostTable {
let mut f = || {
let account_idx = loop {
let x = rand::thread_rng().gen::<usize>() % config.active_accounts;
if !deleted_accounts.contains(&x) & &!beneficiaries.contains(&x) {
if !deleted_accounts.contains(&x) && !beneficiaries.contains(&x) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drive-by fix, but a fun one!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, nice find.

}

fn extract_max(&mut self, metric1: Metric, metric2: Metric, ext_cost: ExtCosts) {
if let Some(value1) = self.extract_value(metric1, ext_cost) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shalln't we report error if one is present and another is not?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's fine to not report the error, as just we won't compute the cost then (that is, we won't return a wrong cost). That's essentially the same behavior we have for other complex costs computed out of several metrics -- if you omit the metric, the whole cost is omitted.

The right behavior here is to just figure out what you need to compute to get the cost, and compute just that. That's a larger refactor that is being done #4733. The goal here is primaraly to be able to quickly test if #4733 returns roughly the same results.

@@ -200,6 +215,12 @@ where
Arc::new(Mutex::new(RuntimeTestbed::from_state_dump(&config.state_dump_path)))
}
};

if config.should_skip(metric) {
println!("skipped");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe remove print?

Copy link
Contributor

@olonho olonho left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, few nits.

@near-bulldozer near-bulldozer bot merged commit 119b065 into near:master Sep 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants