-
Notifications
You must be signed in to change notification settings - Fork 35
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
Add close unstable #56
base: main
Are you sure you want to change the base?
Conversation
@@ -430,17 +436,45 @@ impl AccountInfo { | |||
// - 8 bytes for the data_len | |||
// | |||
// So we can zero out them directly. | |||
#[cfg(target_os = "solana")] | |||
sol_memset_(self.data_ptr().sub(48), 0, 48); |
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.
you can use slice::fill and can get rid of the cfg attr
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.
Using slice::fill
takes 58
CUs – same as the current code. The sol_memset_
is more efficient in this case.
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.
yes, but why?
If the compiler is desugaring to stores, CUs should be lower than the syscall - it's the whole point of applying the optimization. It might mean that the optimization is wrong, or the syscall is mispriced.
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.
I had the same question. 😊 @LucasSte looked into it and already has a plan to improve it.
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.
Four stores is the threshold to call memset
from compiler-builtins. This is what causing the CU bump. Both the threshold to call the library in LLVM and the threshold to call the syscall in compiler-builtins need to be revised.
unsafe { | ||
let zero = 0u64; | ||
core::arch::asm!( | ||
"stxdw [{0}-8], {1}", |
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.
You can try stdw [{0}-8], 0
directly here, without an extra register.
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.
As per offline conversation, the stdw
is not yet available to the compiler – only the vm.
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.
Yeah, this has been disabled since like forever. You literally can't deploy a program that contains any of the st
class insns. If your code never updates the value of r0, you can accomplish the same thing with stxdw[offset], r0 but it's not safe to do so in Rust without some kind of a compiler hint to tell it "please don't reassign r0".
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.
You literally can't deploy a program that contains any of the st class insns.
Where did you get this information from? Not only does the class pass the bytecode verification, but also is implemented in the jitter and the interpreter.
The fact that the compiler wasn't emitting code for the store immediate class doesn't mean you can't deploy a program with it.
Co-authored-by: Lucas Ste <[email protected]>
Problem
When PR #55 fixed the last index of the owner
Pubkey
onclose_unchecked
, it pushed the CUs used by the method to over50
.Solution
Reimplement
close_unchecked
using thesol_memset
syscall, which consumes14
CUs instead. Since this is still over the original7
CUs, this PR also re-adds theclose_unstable
which uses ASM – this variant takes7
CUs.The
close_unstable
can be enabled by using the feature"asm"
.Note:
close_unstable
courtesy of @L0STE and @deanmlittle