Agoric / agoric-sdk

monorepo for the Agoric Javascript smart contract platform
Apache License 2.0
303 stars 191 forks source link

chore(cosmos): avoid string byte slices copies where possible #9568

Open mhofman opened 1 week ago

mhofman commented 1 week ago

closes: #XXXX refs: https://github.com/Agoric/agoric-sdk/pull/9549#pullrequestreview-2133916778

Description

Avoid copies between byte slices and string wherever possible when we need to convert from one to the other. Introduces a couple helpers for the common cases

Security Considerations

All changes were checked to ensure the byte slices are not mutated. The biggest concern would be a use after free, but apparently golang is smart enough to maintain liveness of the raw memory if any golang value (string or byte slice) points into it.

Scaling Considerations

Should avoid unnecessary copies, some in hot paths

Documentation Considerations

None

Testing Considerations

Will put this change through a genesis export / import stress test.

Upgrade Considerations

None, but would be good to include in u16

cloudflare-pages[bot] commented 1 week ago

Deploying agoric-sdk with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6ca7f17
Status: ✅  Deploy successful!
Preview URL: https://fbe1e424.agoric-sdk.pages.dev
Branch Preview URL: https://mhofman-optimize-golang-stri.agoric-sdk.pages.dev

View logs

mhofman commented 1 week ago

@michaelfig I pushed a few more changes handling []byte -> string cases PTAL