pin cmd: stream recursive pins#6493
Conversation
|
Notes:
|
Add a --stream flag to stream the results instead of accumulating the final result in memory. This is a rework of ipfs#5005
274722b to
bb60184
Compare
Stebalien
left a comment
There was a problem hiding this comment.
This will need to correctly handle CID encoding (introduced since #5005).
Also note: we could also just send back a sequence of {cid: type} objects instead using a union (closer to ipfs ls --stream but definitely more expensive in terms of allocations). I don't feel strongly either way.
core/commands/pin.go
Outdated
| // Pin ls needs to output two different type depending on if it's streamed or not. | ||
| // We use this to bypass the cmds lib refusing to have interface{} | ||
| type PinLsOutputWrapper struct { | ||
| RefKeyList |
There was a problem hiding this comment.
We're going to have to use "omitempty" for full backwards compatibility.
Any pointer/example about this ? I don't really get what you are talking about. |
lanzafame
left a comment
There was a problem hiding this comment.
@MichaelMure considering that this is a perf-orientated improvement, could this PR get a go benchmark written for it so we can monitor the on going performance of this call, especially since this is a critical path for large deployments of go-ipfs
|
A few improvements:
|
|
@lanzafame not sure how I would do a go benchmark for this. This PR doesn't fundamentally change anything perf wise, it just start to output the result as it comes. The total run time will be similar. |
|
More improvements:
For indirect pins: --> ~3.4x faster ! It also looks like this change to use parallel graph walking might be used elsewhere. A quick search show that at least the GC might benefit from that. |
|
Test are now failing due to using |
21cbac7 to
7f6b583
Compare
7f6b583 to
16b4d74
Compare
We probably need to sort in the tests. |
|
FYI, I removed the commit that just change |
|
I'm guessing that the traversal order is random, causing the comparison against the expected pin list to fail. We need to sort both before comparing. |
|
I checked that, but the tests look ok to me: |
|
So... this is a bug. |
|
Hoooo, that explains a lot. One problem I had after adding the recursive pins before the indirect pins to the set and using |
|
Fix in #6499. Well, not really a fix, I just renamed these functions so that the names/documentation match up with what they do... |
With a benchmark, you can run |
|
@alanshaw this PR adds a {"Cid": "Qm1", "Type": "direct"}
{"Cid": "Qm2", "Type": "recursive"}
...Instead of a single: {
"Keys": {
"Qm1": "direct",
"Qm2": "recursive",
}
}This is completely backwards compatible but is likely something js-ipfs will want to implement. Thoughts? Objections? |
|
Yes please. I want this. No objections. |
|
🚀! Thanks @MichaelMure, @lanzafame, and @alanshaw! |
|
Ha, I was waiting for #6499 (comment) to get resolved so I could have the neat 3.4x perf improvement with the parallel walking, but ok ! |
|
Test case in #6504. Note: IMO, a benchmark isn't really useful here as this just streams the results, it doesn't reduce overall memory (still need to deduplicate results by storing them in a map). |
Let's do that in a followup. No reason to block this on a different change. |
Add a --stream flag to stream the results instead of
accumulating the final result in memory.
This is a rework of #5005