Repository navigation
perf(inode): replace embedded MinObject with compact fileSourceMetadata in FileInode - #5212
kislaykishore wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request optimizes memory usage in gcsfuse by refactoring lookupCount from a struct to a compact int64 type and replacing the full gcs.MinObject in FileInode with a smaller fileSourceMetadata struct. It also replaces syncutil.InvariantMutex with sync.Mutex and stores CRC32C inline to avoid heap allocations. Corresponding tests and benchmarks are added to verify these changes. The feedback suggests removing a redundant defensive nil check on cfg in NewFileInode since it is an internal function where callers are expected to provide non-nil arguments.
| } | ||
| } else if cfg.FileSystem.EnableKernelReader { | ||
| f.kernelRangeReaderInstance = kernel_readers.NewKernelRangeReaderInstance(&minObj) | ||
| } else if cfg != nil && cfg.FileSystem.EnableKernelReader { |
There was a problem hiding this comment.
In NewFileInode, there is a defensive check cfg != nil in the else if branch. Since this is an internal function where all callers are within the same project and are expected to provide non-nil arguments, we should avoid defensive nil checks to prevent unnecessary CPU overhead. Please remove the redundant cfg != nil check.
References
- Avoid adding defensive nil checks for function parameters in internal utility functions when all callers are within the same project and are expected to provide non-nil arguments, to prevent unnecessary CPU overhead.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## perf/file-inode-mutex-opt #5212 +/- ##
=============================================================
+ Coverage 85.21% 85.27% +0.05%
=============================================================
Files 181 181
Lines 19951 19992 +41
=============================================================
+ Hits 17002 17048 +46
+ Misses 2948 2943 -5
Partials 1 1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
451ba3a to
36c8419
Compare
36c8419 to
a256813
Compare
a256813 to
cbe62f6
Compare
cbe62f6 to
adf6e1c
Compare
adf6e1c to
bdc1f1d
Compare
bdc1f1d to
6673b5c
Compare
Description
Optimize the in-memory footprint of
FileInodeby replacing the embedded 88-bytegcs.MinObjectwith a compactfileSourceMetadatarepresentation:src gcs.MinObject(88 bytes) with a 40-bytefileSourceMetadatastruct (generation,metaGeneration,size,contentEncoding) plus packedcrc32c uint32,isUnfinalized bool, andhasCRC32C boolfields onFileInode.FileInode.name) and customMetadatamap (only needed during initialparseMtime) so they can be garbage-collected immediately, and inlinecrc32cto avoid retaining a separate*uint32heap object.gcs.MinObjecton demand viasrcMinObject()/Source(), and avoid unconditional stack-to-heap escape ofminObjinNewFileInode.InitStreamingWriteHandlerIfEligiblefetches full object metadata viaStatObjectwhen appending to a finalized 0-byte object in a rapid/zonal bucket (since overwriting a finalized 0-byte object creates a new generation and requires custom metadata and extended attributes).lookupCount(perf(inode): compact lookupCount from 24-byte struct to 8-byte int64 #5217) andsync.Mutex(perf(inode): replace syncutil.InvariantMutex with sync.Mutex in FileInode #5218) optimizations, reducesunsafe.Sizeof(FileInode{})on 64-bit platforms from 312 bytes (320-byte size class) to 224 bytes (224-byte size class) with 1 heap allocation perNewFileInode(224 B/op, 1 allocs/op).Link to the issue in case of a bug fix.
b/585048166
Testing details
unsafe.Sizeof(FileInode{}) == 224), escape analysis, andmake build.internal/fs/inode/file_test.go,internal/fs/inode/file_mock_bucket_test.go, and updatedinternal/fs/inode/file_streaming_writes_test.go. Verifiedgo test -v -race ./internal/fs/inode/...andgo test -bench=BenchmarkNewFileInode -benchmem ./internal/fs/inode/....execute-integration-tests,execute-perf-test).Any backward incompatible change? If so, please explain.
N/A