Skip to content

Commit

Permalink
refactor: simplify mem_eq (#1221)
Browse files Browse the repository at this point in the history
Co-authored-by: Pedro Fontana <fontana.pedro93@gmail.com>
  • Loading branch information
Oppen and pefontana authored Jun 12, 2023
1 parent e87dfa0 commit 695feee
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 23 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

* Add `RunResources::get_n_steps` method [#1225](https://github.com/lambdaclass/cairo-rs/pull/1225)

* refactor: simplify `mem_eq`

* fix: pin Cairo compiler version [#1220](https://github.com/lambdaclass/cairo-rs/pull/1220)

* perf: make `inner_rc_bound` a constant, improving performance of the range-check builtin
Expand Down
33 changes: 10 additions & 23 deletions src/vm/vm_memory/memory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -418,32 +418,19 @@ impl Memory {
}
};
match (
get_segment(lhs.segment_index),
get_segment(rhs.segment_index),
get_segment(lhs.segment_index).and_then(|s| s.get(lhs.offset..)),
get_segment(rhs.segment_index).and_then(|s| s.get(rhs.offset..)),
) {
(None, None) => {
return true;
}
(Some(_), None) => {
return false;
}
(None, Some(_)) => {
return false;
}
(Some(lhs_segment), Some(rhs_segment)) => {
let (lhs_start, rhs_start) = (lhs.offset, rhs.offset);
for i in 0..len {
let (lhs, rhs) = (
lhs_segment.get(lhs_start + i),
rhs_segment.get(rhs_start + i),
);
if lhs != rhs {
return false;
}
(Some(lhs), Some(rhs)) => {
let (lhs_len, rhs_len) = (lhs.len().min(len), rhs.len().min(len));
if lhs_len != rhs_len {
return false;
}
lhs[..lhs_len] == rhs[..rhs_len]
}
};
true
(None, None) => true,
_ => false,
}
}

/// Gets a range of memory values from addr to addr + size
Expand Down

1 comment on commit 695feee

@github-actions
Copy link

Choose a reason for hiding this comment

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

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.30.

Benchmark suite Current: 695feee Previous: e87dfa0 Ratio
add_u64_with_felt/0 1 ns/iter (± 0) 0 ns/iter (± 0) Infinity
add_u64_with_felt/1 3 ns/iter (± 0) 2 ns/iter (± 0) 1.50
add_u64_with_felt/2 3 ns/iter (± 0) 2 ns/iter (± 0) 1.50
add_u64_with_felt/4 2 ns/iter (± 0) 1 ns/iter (± 0) 2
add_u64_with_felt/5 2 ns/iter (± 0) 1 ns/iter (± 0) 2
add_u64_with_felt/6 4 ns/iter (± 0) 2 ns/iter (± 0) 2
add_u64_with_felt/7 4 ns/iter (± 0) 2 ns/iter (± 0) 2
add_u64_with_felt/8 3 ns/iter (± 0) 2 ns/iter (± 0) 1.50

This comment was automatically generated by workflow using github-action-benchmark.

CC: @unbalancedparentheses

Please sign in to comment.