Skip to content

Commit cdce076

Browse files
arvidnrichardkiss
authored andcommitted
increase cost granularity by 2 orders of magnitude
fix args-unknown-1.clvm test to exceed the max cost again tweak costs to charge more for memory allocations charge for memory allocations accurately, based on output size, not input size
1 parent 35a447c commit cdce076

File tree

5 files changed

+163
-128
lines changed

5 files changed

+163
-128
lines changed

src/core_ops.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@ use crate::node::Node;
44
use crate::op_utils::{atom, check_arg_count};
55
use crate::reduction::{Reduction, Response};
66

7-
const FIRST_COST: Cost = 1;
8-
const IF_COST: Cost = 1;
9-
const CONS_COST: Cost = 3;
10-
const REST_COST: Cost = 1;
11-
const LISTP_COST: Cost = 1;
12-
const CMP_BASE_COST: Cost = 2;
13-
const CMP_COST_PER_BYTE_DIVIDER: Cost = 64;
7+
const FIRST_COST: Cost = 30;
8+
const IF_COST: Cost = 33;
9+
// Cons cost lowered from 245. It only allocates a pair, which is small
10+
const CONS_COST: Cost = 50;
11+
// Rest cost lowered from 77 since it doesn't allocate anything and it should be
12+
// the same as first
13+
const REST_COST: Cost = 30;
14+
const LISTP_COST: Cost = 19;
15+
const EQ_BASE_COST: Cost = 117;
16+
const EQ_COST_PER_BYTE: Cost = 1;
1417

1518
pub fn op_if<T: Allocator>(a: &mut T, input: T::Ptr, _max_cost: Cost) -> Response<T::Ptr> {
1619
let args = Node::new(a, input);
@@ -67,6 +70,6 @@ pub fn op_eq<T: Allocator>(a: &mut T, input: T::Ptr, _max_cost: Cost) -> Respons
6770
let a1 = args.rest()?.first()?;
6871
let s0 = atom(&a0, "=")?;
6972
let s1 = atom(&a1, "=")?;
70-
let cost = CMP_BASE_COST + (s0.len() as Cost + s1.len() as Cost) / CMP_COST_PER_BYTE_DIVIDER;
73+
let cost = EQ_BASE_COST + (s0.len() as Cost + s1.len() as Cost) * EQ_COST_PER_BYTE;
7174
Ok(Reduction(cost, if s0 == s1 { a.one() } else { a.null() }))
7275
}

0 commit comments

Comments
 (0)