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

storage: skip Errorf for a frequent error that is never read #11208

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

sduchesneau
Copy link

While hunting down memory allocations, we found lots of calls to Errorf() that were useless (because the error is never actually read, it is only checked for nil condition)
Reusing the same error prevents all these allocations, while keeping a sane behavior for future use.

@sduchesneau sduchesneau requested review from a team as code owners December 2, 2024 19:37
Copy link

google-cla bot commented Dec 2, 2024

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

some CRC32 checks can cause lots of failing calls to decodeUint32, generating a new 'fmt.Errorf()',
but the error is never actually read, it is only checked for nil condition. Replacing with a (reused) more generic error prevents lots of allocations leading to less stress on the GC.
@sduchesneau sduchesneau force-pushed the storage_skip_error_alloc branch from 95d7819 to f77ff78 Compare December 2, 2024 19:45
@quartzmo quartzmo changed the title skip Errorf for a frequent error that is never read storage: skip Errorf for a frequent error that is never read Dec 2, 2024
Copy link
Contributor

@tritone tritone left a comment

Choose a reason for hiding this comment

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

Code change seems fine to me. I am more curious about how you are seeing this error occur internally to the library so frequently. Could you file an issue and describe what kind of data you are downloading, whether you are using storage.NewReader or NewRangeReader, whether the object has a checksum present when you look at it in the console? I would expect this failure case not to be very common in general.

@product-auto-label product-auto-label bot added the api: storage Issues related to the Cloud Storage API. label Dec 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the Cloud Storage API.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants