Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node/bindnode: more minor improvements for graphsync #331

Merged
merged 1 commit into from
Jan 13, 2022
Merged

node/bindnode: more minor improvements for graphsync #331

merged 1 commit into from
Jan 13, 2022

Conversation

mvdan
Copy link
Contributor

@mvdan mvdan commented Jan 11, 2022

(see commit messages - please do not squash)

@mvdan mvdan requested a review from warpfork January 11, 2022 17:04
@mvdan
Copy link
Contributor Author

mvdan commented Jan 11, 2022

Note to self: revisit bindnode's Next key being valid only until the next call.

Copy link
Collaborator

@warpfork warpfork left a comment

Choose a reason for hiding this comment

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

Most of these make sense.

I concede on the TypeStruct.Fields accessor and TypeEnum.Members accessor for sure. (I keep wanting Golang to have immutablity. It doesn't. I should stop wishing I can have nice things; and paying extra for them isn't worth it.)

I'm fairly nervous about the iterators returning something as a Node that's mutable. Maybe with enough documentation, it's going to be survivable. Still nerve-wracking and a fairly large divergence from the usual contract.

I wish we could make the iterators for structs and unions (e.g. what's wishing for these string wrappers) just grab pointers to "constant" strings that the schema.Type values already contain. That's hard at present because that package also spent effort on trying to be immutable in a language that's inimically hostile to it... but maybe it's worth drilling there instead.

node/basicnode/string.go Outdated Show resolved Hide resolved
node/bindnode/repr.go Outdated Show resolved Hide resolved
node/bindnode/infer.go Outdated Show resolved Hide resolved
Querying the fields and members of structs and enums is common.
I get the intent of trying to keep them read-only,
but the current mechanism is just too expensive.

	name                                 old time/op    new time/op    delta
	MessageEncodingRoundtrip/DagCbor-16    21.4µs ± 1%    16.9µs ± 0%  -20.66%  (p=0.029 n=4+4)

	name                                 old alloc/op   new alloc/op   delta
	MessageEncodingRoundtrip/DagCbor-16    32.8kB ± 0%    23.2kB ± 0%  -29.28%  (p=0.029 n=4+4)

	name                                 old allocs/op  new allocs/op  delta
	MessageEncodingRoundtrip/DagCbor-16       451 ± 0%       396 ± 0%  -12.20%  (p=0.029 n=4+4)

An alternative could be to provide a slice,
and then we'd append into it and reuse its space.
However, note that that would still copy memory.

An alternative could be to provide iterator-like methods, such as:

	Length() int
	FieldAt(int) StructField

However, that would get relatively clunky, and doesn't seem particularly
worth it right now.

Ultimately, we don't have read-only slices, so we shouldn't try to
invent our own. The fact that we return the direct slice does allow
replacing elements, but the user can't append or re-slice, so that
should be enough signal to most Go developers.
@mvdan
Copy link
Contributor Author

mvdan commented Jan 13, 2022

After talking to @warpfork about it yesterday, I ended up backing out my NewStringAddr change; it breaks the Next semantics from the MapIterator interface, and also makes us return ipld.Nodes which get modified under the hood, which is likely going to cause bugs.

All that doesn't seem worth it for a minor speed-up right now. I might investigate other avenues which don't lose us safety in the near future.

@mvdan
Copy link
Contributor Author

mvdan commented Jan 13, 2022

I concede on the TypeStruct.Fields accessor and TypeEnum.Members accessor for sure. (I keep wanting Golang to have immutablity. It doesn't. I should stop wishing I can have nice things; and paying extra for them isn't worth it.)

Taking this to mean that you're OK with that one commit, and given that the other two were removed, I'm going ahead and merging this :)

@mvdan mvdan merged commit a16dd99 into ipld:master Jan 13, 2022
@mvdan mvdan deleted the bindnode-graphsync-2 branch January 17, 2022 15:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants