ipfs / go-cid

Content ID v1 implemented in go
MIT License
156 stars 47 forks source link

implement CidFromReader #127

Closed mvdan closed 3 years ago

mvdan commented 3 years ago

(see commit message)

welcome[bot] commented 3 years ago

Thank you for submitting this PR! A maintainer will be here shortly to review it. We are super grateful, but we are also overloaded! Help us by making sure that:

Getting other community members to do a review would be great help too on complex PRs (you can ask in the chats/forums). If you are unsure about something, just leave us a comment. Next steps:

We currently aim to provide initial feedback/triaging within two business days. Please keep an eye on any labelling actions, as these will indicate priorities and status of your contribution. We are very grateful for your contribution!

mvdan commented 3 years ago

Not super helpful that codecov is complaining about every uncovered line... I'd need to spend another 4h on this to get 100% coverage, and it feels somewhat futile.

warpfork commented 3 years ago

I'd love to have some tests that check that all the byte buffering dancing is correct. (It looks correct, but I've stopped trusting my eyes and mental model of the compiler completely in things as fiddly as this.)

Either would be good. The latter is more fragile and gives less holistic impact numbers, but also results in something that can actually go red/green in CI rather than requiring someone to keep an eyeball on things, so both have different kinds of value.

I don't know if I consider this a blocking request or not, though. If it's already been profiled from some place where it's being used, I'll believe it's correct. Having tests or benchmarks in the same repo will just make it easier to be sure we don't ever regress it.

warpfork commented 3 years ago

Interface LGTM, anyway.

Returning an int like this to report partial progress in I/O reading is golang normative, yes. It describes a side effect that you couldn't otherwise get much insight into, and while that data's not always needed, when it is, you really need it, so it's good practice to always return it.

mvdan commented 3 years ago

I don't know if I consider this a blocking request or not, though. If it's already been profiled from some place where it's being used, I'll believe it's correct. Having tests or benchmarks in the same repo will just make it easier to be sure we don't ever regress it.

This PR is pure functionality, not optimization/performance. It's virtually impossible to accomplish this without CidFromReader today, unless you're happy with reading a "probably large enough" chunk of bytes and hoping for the best.

In that way, I don't think performance should block this PR. I agree benchmarks and profiling would be nice, but that seems like it should come after. All I can say on the matter is that our use in carv2 works, and seems fast enough :)

I admit I didn't go out of my way to write more tests to try to get 100% test coverage on this func. I'll see if I can reuse TestBadCidFromBytes for that purpose.

mvdan commented 3 years ago

The leading varint simplification that Steven suggested is now done.

I'll see if I can reuse TestBadCidFromBytes for that purpose.

That's now done too.

mvdan commented 3 years ago

@Stebalien the two byte slice comments are addressed, and the two perf nits now have TODOs. Want to take one last look?