You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There isn't much difference when you benchmark it (in the scenario that article tested)
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).
The text was updated successfully, but these errors were encountered:
Yeah that's my understanding as well, that article is one of the ones I read when writing up this issue.
This is more to note that we currently pass around references for small things like Pubkey where we don't need to. I think that this rule of thumb should be a good approach for anyone looking at this in the future:
If < 64 bytes -> Copy
If > 64 bytes -> &borrow
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:
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:
Copy
&
borrowThis way we're covered even if the compiler isn't being super smart (on my to-do list to figure out if it is).
The text was updated successfully, but these errors were encountered: