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

Optimise out uploading the empty blob in a couple of places #184

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions go/pkg/client/cas.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ func (c *Client) UploadIfMissing(ctx context.Context, data ...*chunker.Chunker)
var dgs []digest.Digest
chunkers := make(map[digest.Digest]*chunker.Chunker)
for _, c := range data {
dg := c.Digest()
if _, ok := chunkers[dg]; !ok {
dgs = append(dgs, dg)
chunkers[dg] = c
if dg := c.Digest(); dg != digest.Empty {
if _, ok := chunkers[dg]; !ok {
dgs = append(dgs, dg)
chunkers[dg] = c
}
}
}

Expand Down Expand Up @@ -221,6 +222,9 @@ func (c *Client) WriteProto(ctx context.Context, msg proto.Message) (digest.Dige

// WriteBlob uploads a blob to the CAS.
func (c *Client) WriteBlob(ctx context.Context, blob []byte) (digest.Digest, error) {
if len(blob) == 0 {
return digest.Empty, nil // The empty blob does not need to be uploaded
}
ch := chunker.NewFromBlob(blob, int(c.ChunkMaxSize))
dg := ch.Digest()
return dg, c.WriteChunked(ctx, c.ResourceNameWrite(dg.Hash, dg.Size), ch)
Expand Down Expand Up @@ -597,6 +601,9 @@ func (c *Client) ResourceNameWrite(hash string, sizeBytes int64) string {
// GetDirectoryTree returns the entire directory tree rooted at the given digest (which must target
// a Directory stored in the CAS).
func (c *Client) GetDirectoryTree(ctx context.Context, d *repb.Digest) (result []*repb.Directory, err error) {
if d.SizeBytes == 0 && d.Hash == digest.Empty.Hash {
return nil, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Wait, is that correct? Shouldn't this return an empty Directory proto?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's returning a slice of directory protos, so nil is pretty equivalent to an empty slice here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but I mean: shouldn't it return a slice containing one item, []*repb.Directory{&repb.Directory{}}, instead? An empty digest maps to an empty directory.

}
pageTok := ""
result = []*repb.Directory{}
closure := func(ctx context.Context) error {
Expand Down