-
Notifications
You must be signed in to change notification settings - Fork 151
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
Convert relocation table to HashMap<usize, MaybeRelocatable> #1862
base: main
Are you sure you want to change the base?
Convert relocation table to HashMap<usize, MaybeRelocatable> #1862
Conversation
Thanks for the contribution @notlesh ! |
vm/src/vm/vm_core.rs
Outdated
/// Will return an error if any of the following conditions are not met: | ||
/// - Source address's segment must be negative (temporary). | ||
/// - Source address's offset must be zero. | ||
/// - There shouldn't already be relocation at the source segment. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't or mustn't? If the former, in which scenario would it be allowed? If the latter, can this function check it and return an error?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Mustn't" would be more appropriate here, although this verbiage was copied verbatim (it's already used a couple times in the codebase), so I hesitate to make it different.
This condition is checked in fn Memory::add_relocation_rule_maybe_relocatable()
, which this fn calls:
cairo-vm/vm/src/vm/vm_memory/memory.rs
Line 338 in 159f67d
return Err(MemoryError::DuplicatedRelocation(src_ptr.segment_index)); |
This seems to cause a significant slowdown see workflow. Is there any way to avoid the hit for more conforming programs? Is it possible to fix the calling code instead? |
Good catch, that's a significant performance decrease. I'm a bit surprised by it, actually, because it shouldn't be adding significant overhead. I'll try to run locally to understand it better. I agree that such a performance impact is not really acceptable for such a corner case... 😅 We have tried fixing the calling code; we come up with a workaround but unfortunately it doesn't always work. The OS makes an assert after calling %{ memory.add_relocation_rule(src_ptr=ids.src_ptr, dest_ptr=ids.dest_ptr) %}
assert src_ptr = dest_ptr; In this particular case,
|
IIUC, you only need to cover the |
Yes, this crossed my mind. The cases I've seen the OS fail on come from I suspect this overhead would be similar to my original approach, however. I run into compile errors when running Speaking of perf, I noticed there is a lot of noise in the measurements here, maybe the delta measured in this PR is within this noise? |
Yes, that or the offset. Both are invalid as
I'm not sure
Erm, not quite. Those measurements are really not looked at. As you noticed, criterion is too noisy for meaningful comparison of commits in a CI. That page is obsolete and we no longer refer to it for performance because of that. |
Yes let me post the benchmarks again, it seems like a ~15% performance degradation
|
Hi @notlesh !
Tell me what you think |
Hey, I think those are great ideas. It certainly solves the perf issue and it gives the VM a way to behave exactly like the pythonic impl. That said, we are also discussing some small changes to the OS itself that would prevent relocation-to-integers, so this change on the VM may not be needed. I'll keep you posted! Edit: yes, we are using the |
Great @notlesh ! |
@pefontana cf36b4a is a first pass at putting this all behind |
@notlesh Can you solve merge conflicts, so I can approve the CI run? |
@notlesh the performance hit seems to be fixed, but some builds in the CI are failing. Could you fix them? |
I think I took care of them all now. |
Co-authored-by: Gabriel Bosio <38794644+gabrielbosio@users.noreply.github.com>
Convert the relocation table to
MaybeRelocatable
s in order to support intsDescription
Fixes #1860.
This PR converts the relocation table from a
HashMap<usize, Relocatable>
to aHashMap<usize, MaybeRelocatable>
in order to support integers.The original
add_relocation_rule
fns have been left untouched so that they still only supportRelocatable
s and a newfn add_relocation_rule_maybe_relocatable()
has been added to support using aMaybeRelocatable
. This should prevent this change from affecting most users.See #1860 for more details on the motivation for this change.
Description of the pull request changes and motivation.
Checklist