perf(memory): Minimizing the gcs.MinObject memory footprint#4830
Draft
raj-prince wants to merge 1 commit into
Draft
perf(memory): Minimizing the gcs.MinObject memory footprint#4830raj-prince wants to merge 1 commit into
raj-prince wants to merge 1 commit into
Conversation
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.
Description
Optimized the memory footprint of
gcs.MinObjectby changing the representation of itsUpdatedandFinalizedtimestamp fields fromtime.Time(24 bytes each) toint64Unix nanoseconds (8 bytes each).Rationale
gcs.MinObjectis the core structure used to represent GCS objects in the metadata stat cache and is embedded by value inFileInodeandSymlinkInode. Storing them astime.Timeis memory-inefficient becausetime.Timecarries additional overhead (like timezone pointers and monotonic clock readings) that are unnecessary for static caching.By converting these to
int64nanoseconds, we save 16 bytes per timestamp, reducing the struct size significantly.Changes
gcs.MinObjectRefactoring (object.go):UpdatedandFinalizedfields toint64.UpdatedTime() time.TimeandFinalizedTime() time.Timehelper methods to reconstructtime.Timeon the fly for callers.TimeToNS(time.Time) int64andNSToTime(int64) time.Timehelpers to handle safe conversion, specifically protecting against panics when callingUnixNano()on Go's zerotime.Timevalue.storageutil(object_attrs.go): Updated conversion helpers (ObjectAttrsToMinObject,ConvertObjToMinObject, etc.) to convert timestamps using the new helpers.fakeGCS (bucket.go): UpdatedcopyMinObjecthelper.gcsx(garbage_collect.go): Updated stale object age calculation to useo.UpdatedTime().inode(file.go, symlink.go): Updated attribute mapping and constructor code to useUpdatedTime()andgcs.TimeToNS().util,storage,gcsx,inode, andhandlepackages to useint64literals orgcs.TimeToNS()inMinObjectstruct literals.assert.EqualandExpectThatassertions in tests (including the shared GCS bucket test suite in bucket_tests.go) to comparetime.TimewithUpdatedTime()/FinalizedTime(), preventing runtime type mismatch failures.local_modifications_test.goandsymlink_test.goto use directint64integer comparisons (<and==) instead oftime.Time.Before()/Compare().Impact & Memory Savings (Verified via unsafe.Sizeof)
gcs.MinObjectsize: 120B → 88B (-32 bytes / 26.7% reduction).32 MBof RAM per 1 million cached objects.FileInodeembedsMinObjectby value, its size automatically shrank by 32 bytes (488B → 456B) onmaster, saving another32 MBof RAM per 1 million cached files.~64 MBof RAM saved permanently for a mount caching 1 million files.All tests compile and pass successfully.
Link to the issue in case of a bug fix.
Testing details
Any backward incompatible change? If so, please explain.