Skip to content
This repository has been archived by the owner on Aug 11, 2021. It is now read-only.

feat: new IPLD Format API #124

Closed
wants to merge 1 commit into from
Closed

Conversation

vmx
Copy link
Member

@vmx vmx commented Apr 9, 2019

BREAKING CHANGE: The API is now async/await based

There are numerous changes, the most significant one is that the API
is no longer callback based, but it using async/await.

The properties of DAGNode and DAGLink are now in sync with the paths
that are used for resolving. This means that e.g. name is now called
Name and size is Tsize.

All return values from resolve() now conform to the IPLD Data Model,
this means that e.g. links are no longer represented as
{'/': "baseecodedcid"}, but as CID instances instead.

For the full new API please see the IPLD Formats spec.

BREAKING CHANGE: The API is now async/await based

There are numerous changes, the most significant one is that the API
is no longer callback based, but it using async/await.

The properties of DAGNode and DAGLink are now in sync with the paths
that are used for resolving. This means that e.g. `name` is now called
`Name` and `size` is `Tsize`.

All return values from `resolve()` now conform to the [IPLD Data Model],
this means that e.g. links are no longer represented as
`{'/': "baseecodedcid"}`, but as [CID] instances instead.

For the full new API please see the [IPLD Formats spec].

[IPLD Data Model]: https://github.com/ipld/specs/blob/master/IPLD-Data-Model-v1.md
[CID]: https://github.com/multiformats/js-cid/
[IPLD Formats spec]: https://github.com/ipld/interface-ipld-format
@ghost ghost assigned vmx Apr 9, 2019
@ghost ghost added the status/in-progress In progress label Apr 9, 2019
@codecov
Copy link

codecov bot commented Apr 9, 2019

Codecov Report

Merging #124 into master will increase coverage by 2%.
The diff coverage is 94.87%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #124   +/-   ##
=======================================
+ Coverage   91.14%   93.14%   +2%     
=======================================
  Files          14       16    +2     
  Lines         271      248   -23     
=======================================
- Hits          247      231   -16     
+ Misses         24       17    -7
Impacted Files Coverage Δ
src/dag-link/util.js 100% <ø> (ø) ⬆️
src/resolver.js 100% <100%> (+5.79%) ⬆️
src/dag-link/index.js 85.71% <100%> (-2.29%) ⬇️
src/dag-node/addLink.js 100% <100%> (+9.09%) ⬆️
src/index.js 100% <100%> (ø) ⬆️
src/dag-node/create.js 100% <100%> (+12.5%) ⬆️
src/dag-node/util.js 94.44% <100%> (+3.96%) ⬆️
src/dag-node/addNamedLink.js 100% <100%> (ø)
src/dag-node/rmLink.js 93.33% <80%> (+0.47%) ⬆️
src/dag-node/index.js 90.62% <86.66%> (+2.62%) ⬆️
... and 4 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 98d4ca8...6024717. Read the comment docs.

function deserialize (buffer, callback) {
const pbn = proto.PBNode.decode(buffer)
const deserialize = async (buffer) => {
const pbn = proto.PBNode.decode(Buffer.from(buffer))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will cause a new buffer to be created and the existing data to be copied into it. Unnecessary buffer copying has previously been identified as a performance bottleneck in our codebase.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously we didn't copy this buffer before decoding it - did that cause a problem that this copy solves?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes there was an issue, without this the tests fail. Should I just plug in the other Protocol Buffers library that works directly on Uint8Arrays (I've the code ready somewhere).

Copy link
Member

@achingbrain achingbrain Apr 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

protons is one of ours, can we not just fix it there instead of swapping out the whole library?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's the reason, if we use https://github.com/mapbox/pbf we get a faster thing and don't have to maintain it!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would descope swapping out deps for another PR, just make this about the API changes.

Copy link
Member

@achingbrain achingbrain Apr 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking into the test failures, it seems it's related to returning Uint8Arrays instead of Buffers which is caused by this line in this PR - which is also a copy operation and so bad from a performance point of view.

The failures mostly seem to stem from other modules test to see if the thing they've been passed is a Buffer (instead of a Uint8Array or array-like object),

Not sure this is related to changing the API to be async/await - maybe you should try tackling that in a different PR to reduce the scope of this one?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The problem is that bubbling up the changes up to js-ipfs is a huge pain, it takes weeks. Hence I'd like to do as little breaking releases as possible. Though I'll think about that as keeping it would result in less per regressions and I could make a clean PR which is exchanging the PB lib and changes the return value to Uint8Array.

Copy link
Member

@achingbrain achingbrain Apr 10, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could make a clean PR which is exchanging the PB lib and changes the return value to Uint8Array

I think this would be preferable

Bubbling up the changes up to js-ipfs is a huge pain, it takes weeks

Agreed. I think we can coordinate better as a team - maybe have a week where will all try to ship the same feature - be that base32 CIDs or Uint8Arrays, etc. Let's bring it up at next week's js-core catchup.

name: this.name,
size: this.size,
cid: this._cid.toBaseEncodedString()
name: this.Name,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should these keys get the go-name treatment too? E.g.

this._json = Object.freeze({
  Name: this.Name,
  Tsize: this.Tsize,
  // etc

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about this, but I'm unsure. What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would, for consistency - we can remove some of the mapping steps from the HTTP API endpoints then too.

@vmx
Copy link
Member Author

vmx commented May 8, 2019

Superseded by #127.

@vmx vmx closed this May 8, 2019
@ghost ghost removed the status/in-progress In progress label May 8, 2019
@vmx vmx deleted the master-based-format-api-cleanup branch May 8, 2019 15:49
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants