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

Documentation: Policy for borrowing Copy structs #210

Open
carlaKC opened this issue Jan 13, 2025 · 0 comments
Open

Documentation: Policy for borrowing Copy structs #210

carlaKC opened this issue Jan 13, 2025 · 0 comments
Labels
documentation Improvements or additions to documentation Low Priority

Comments

@carlaKC
Copy link
Contributor

carlaKC commented Jan 13, 2025

This is very low priority, I just found it interesting 🦀


In sim-ln we borrow &PublicKey when we pass it to functions, rather than copying it (PublicKey).
By contrast, LDK mostly just copies around PublicKey.

I was interested in when we should borrow vs copy smaller structs, and did some digging:

All of my sources here are reddit comments (😅 ) so it would be interesting to confirm:

  • That the compiler will optimize-away borrows of small structs
  • That the compiler will under the hood borrow large structs rather than copying them

We're not going to get some big performance gain here, so this really is more an intellectual exercise / matter of standardizing how we do things. Seems reasonable to update docs to advise:

  • If < 64 bytes -> Copy
  • If > 64 bytes -> &borrow

This way we're covered even if the compiler isn't being super smart (on my to-do list to figure out if it is).

@carlaKC carlaKC added documentation Improvements or additions to documentation Low Priority labels Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation Improvements or additions to documentation Low Priority
Projects
None yet
Development

No branches or pull requests

1 participant