blockservice & exchange & bitswap: add non variadic NotifyNewBlock#242
blockservice & exchange & bitswap: add non variadic NotifyNewBlock#242
Conversation
5344f5d to
4ff4bd2
Compare
Codecov Report❌ Patch coverage is @@ Coverage Diff @@
## main #242 +/- ##
==========================================
- Coverage 61.63% 61.60% -0.03%
==========================================
Files 254 254
Lines 31427 31469 +42
==========================================
+ Hits 19370 19387 +17
- Misses 10486 10507 +21
- Partials 1571 1575 +4
... and 3 files with indirect coverage changes 🚀 New features to boost your workflow:
|
|
@Jorropo : I don't see an issue linked to this PR. In the absence of this, can you share more on what's motivating this PR? |
|
@BigLep the PR and Commit bodies:
I can add the explanation about keeping it in-line with our other exchange APIs. This seems like a good usecase to try the idea @guseggert is cooking (some automated code migrator), that would add the |
4ff4bd2 to
3af3c29
Compare
There was a problem hiding this comment.
I don't have strong opinions on this. It seems a relatively small change that can bring memory benefits - although arguably low. If others agree, I'm fine to have it merged.
FYSA: I rebased the PR and added the updated exchange for the gateway examples.
3af3c29 to
311cd1f
Compare
|
2023-04-06 conversation: will defer for now. Want to have clarity on how we handle breaking changes in Boxo. |
311cd1f to
6a45c0e
Compare
|
This is ready to merge. Let's decide if we want this or not. |
There was a problem hiding this comment.
Lgtm? As noted in https://github.com/ipfs/boxo/pull/242/files#r1153577309 this follows existing convention from other places (Put vs PutMany, GetBlock vs GetBlocks etc), and simplifies code slightly. If someone has custom implementation, should be trivial to migrate.
@aschmahmann any concerns?
Variadicts in go are just syntactic sugar around passing a slice, that means all go memory reachability rules apply, this force the compiler to heap allocate the variadic slice for virtual call, because the implementation is allowed to leak the slice (and go's interprocedural optimisations do not cover virtuals). Passing a block without variadic will pass the itab either on the stack or decomposed through registers. Skipping having to allocate a slice.
73226d5 to
730b9bd
Compare
|
CI fails when calling |
| // This is fine to do because if no calls are virtual then the compiler is able | ||
| // to see that the slice does not leak and the slice is stack allocated. |
There was a problem hiding this comment.
It is not clear whether this is true or not in the golang documentation.
bitswap/client/client.go
Outdated
| // This is actually fine to do because no calls is virtual the compiler is able | ||
| // to see that the slice does not leak and the slice is stack allocated. |
There was a problem hiding this comment.
Escape analysis results seem to contradict this:
./client.go:432:7: leaking param content: bs
./client.go:432:34: leaking param: ctx
./client.go:432:55: leaking param: blk
|
I do not think it is worth the extra complexity to have separate functions, one for a single block and one for multiple blocks. |
Variadicts in go are just syntactic sugar around passing a slice, that means all go memory reachability rules apply, this force the compiler to heap allocate the variadic slice for virtual call, because the implementation is allowed to leak the slice (and go's interprocedural optimisations do not cover virtuals).
Passing a block without variadic will pass the itab either on the stack or decomposed through registers. Skipping having to allocate a slice.