perf(storage): remove protobuf's copy of data on unmarshalling#9526
Merged
Conversation
removes unmarshalling copy of all except first chunk off wire
tritone
reviewed
Mar 12, 2024
tritone
left a comment
Contributor
There was a problem hiding this comment.
Overall looks good; just a few minor suggestions and questions
tritone
approved these changes
Mar 14, 2024
dfawley
approved these changes
Mar 15, 2024
tritone
approved these changes
Mar 15, 2024
neild
reviewed
Mar 18, 2024
| // wire-encoded message buffer b, or an error if the message is invalid. | ||
| // This is used on the first recv of an object as it may contain all fields of | ||
| // ReadObjectResponse. | ||
| func readFullObjectResponse(b []byte) (*storagepb.ReadObjectResponse, error) { |
There was a problem hiding this comment.
Might want to note that this function is essentially identical to proto.Unmarshal, except it aliases the data in the input []byte. If we ever add a feature to Unmarshal that does that, this function can be dropped.
| } | ||
| } | ||
|
|
||
| // Unmarshal remaining fields. |
There was a problem hiding this comment.
You're unmarshaling all the fields in the message, so this will be a bit more efficient if you loop once over the fields rather than looking up each individually:
off := 0
for off < len(b) {
num, typ, n := protowire.ConsumeTag(b[off:])
if n < 0 {
return nil, protowire.ParseError(n)
}
off += n
switch {
case num == checksummedDataField && typ == protowire.BytesType:
// unmarshal the checksummed_data field
case num == objectChecksumsField && typ == protowire.BytesType:
// unmarshal the object_checksums field
case num == contentRangeField && typ == protowire.BytesType:
// unmarshal the content_range field
case num == metadataField && typ == protowire.BytesType:
// unmarshal the metadata field
default:
n = protowire.ConsumeFieldValue(num, typ, b[off:])
if n < 0 {
return nil, protowire.ParseError(n)
}
off += n
}
}
Contributor
Author
There was a problem hiding this comment.
Thanks for the suggestion!
tritone
approved these changes
Mar 19, 2024
gcf-merge-on-green Bot
pushed a commit
that referenced
this pull request
Mar 29, 2024
🤖 I have created a release *beep* *boop* --- ## [1.40.0](https://togithub.com/googleapis/google-cloud-go/compare/storage/v1.39.1...storage/v1.40.0) (2024-03-29) ### Features * **storage:** Implement io.WriterTo in Reader ([#9659](https://togithub.com/googleapis/google-cloud-go/issues/9659)) ([8264a96](https://togithub.com/googleapis/google-cloud-go/commit/8264a962d1c21d52e8fca50af064c5535c3708d3)) * **storage:** New storage control client ([#9631](https://togithub.com/googleapis/google-cloud-go/issues/9631)) ([1f4d279](https://togithub.com/googleapis/google-cloud-go/commit/1f4d27957743878976d6b4549cc02a5bb894d330)) ### Bug Fixes * **storage:** Retry errors from last recv on uploads ([#9616](https://togithub.com/googleapis/google-cloud-go/issues/9616)) ([b6574aa](https://togithub.com/googleapis/google-cloud-go/commit/b6574aa42ebad0532c2749b6ece879b932f95cb9)) * **storage:** Update protobuf dep to v1.33.0 ([30b038d](https://togithub.com/googleapis/google-cloud-go/commit/30b038d8cac0b8cd5dd4761c87f3f298760dd33a)) ### Performance Improvements * **storage:** Remove protobuf's copy of data on unmarshalling ([#9526](https://togithub.com/googleapis/google-cloud-go/issues/9526)) ([81281c0](https://togithub.com/googleapis/google-cloud-go/commit/81281c04e503fd83301baf88cc352c77f5d476ca)) --- This PR was generated with [Release Please](https://togithub.com/googleapis/release-please). See [documentation](https://togithub.com/googleapis/release-please#release-please).
tritone
added a commit
to tritone/google-cloud-go
that referenced
this pull request
Aug 22, 2024
googleapis#9526)" This reverts commit 81281c0. Also updates grpc-go to use new default codec
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Note that this could be made even more efficient by parsing the whole block at once instead of reusing the
readProtoBytesfunction, which will look at and then skip over the fields that have already been parsed.readProtoBytescalls protowire functions that do some calculations that re-slice the data buffer, without any copies. So, I don't think the improvement would be noticeable, especially since we only have 4 fields in the message. The cpu flame graphs do not show this function, so whatever time is spent there seems to be negligible.cc: @dfawley