Skip to content

perf(inode): replace embedded MinObject with compact fileSourceMetadata in FileInode - #5212

Draft
kislaykishore wants to merge 1 commit into
perf/file-inode-mutex-optfrom
perf/file-inode-memory-opt
Draft

kislaykishore wants to merge 1 commit into
perf/file-inode-mutex-optfrom
perf/file-inode-memory-opt

Conversation

@kislaykishore

@kislaykishore kislaykishore commented Nov 2, 2026 •

Copy link
Copy Markdown
Collaborator

Description

Optimize the in-memory footprint of FileInode by replacing the embedded 88-byte gcs.MinObject with a compact fileSourceMetadata representation:

  • Replace src gcs.MinObject (88 bytes) with a 40-byte fileSourceMetadata struct (generation, metaGeneration, size, contentEncoding) plus packed crc32c uint32, isUnfinalized bool, and hasCRC32C bool fields on FileInode.
  • Omit the redundant object name string (already stored in FileInode.name) and custom Metadata map (only needed during initial parseMtime) so they can be garbage-collected immediately, and inline crc32c to avoid retaining a separate *uint32 heap object.
  • Reconstruct gcs.MinObject on demand via srcMinObject() / Source(), and avoid unconditional stack-to-heap escape of minObj in NewFileInode.
  • Ensure InitStreamingWriteHandlerIfEligible fetches full object metadata via StatObject when 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).
  • Together with the preceding lookupCount (perf(inode): compact lookupCount from 24-byte struct to 8-byte int64 #5217) and sync.Mutex (perf(inode): replace syncutil.InvariantMutex with sync.Mutex in FileInode #5218) optimizations, reduces unsafe.Sizeof(FileInode{}) on 64-bit platforms from 312 bytes (320-byte size class) to 224 bytes (224-byte size class) with 1 heap allocation per NewFileInode (224 B/op, 1 allocs/op).

Link to the issue in case of a bug fix.

b/585048166

Testing details

  1. Manual - Verified struct layout (unsafe.Sizeof(FileInode{}) == 224), escape analysis, and make build.
  2. Unit tests - Added unit tests and benchmarks in internal/fs/inode/file_test.go, internal/fs/inode/file_mock_bucket_test.go, and updated internal/fs/inode/file_streaming_writes_test.go. Verified go test -v -race ./internal/fs/inode/... and go test -bench=BenchmarkNewFileInode -benchmem ./internal/fs/inode/....
  3. Integration tests - Triggered via PR labels (execute-integration-tests, execute-perf-test).

Any backward incompatible change? If so, please explain.

N/A

@kislaykishore kislaykishore added execute-perf-test Execute performance test in PR execute-integration-tests Run only integration tests labels Nov 2, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread internal/fs/inode/file.go Outdated
}
} else if cfg.FileSystem.EnableKernelReader {
f.kernelRangeReaderInstance = kernel_readers.NewKernelRangeReaderInstance(&minObj)
} else if cfg != nil && cfg.FileSystem.EnableKernelReader {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

medium

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
  1. 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

codecov Bot commented Nov 2, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.82353% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 85.27%. Comparing base (f5e1a01) to head (6673b5c).

Files with missing lines Patch % Lines
internal/fs/inode/file.go 98.82% 1 Missing ⚠️
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              
Flag Coverage Δ
unittests 85.27% <98.82%> (+0.05%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
@kislaykishore
kislaykishore force-pushed the perf/file-inode-memory-opt branch from 451ba3a to 36c8419 Compare November 2, 2026 14:06
@kislaykishore kislaykishore added execute-integration-tests Run only integration tests execute-perf-test Execute performance test in PR and removed execute-integration-tests Run only integration tests execute-perf-test Execute performance test in PR labels Nov 2, 2026
@kislaykishore
kislaykishore force-pushed the perf/file-inode-memory-opt branch from 36c8419 to a256813 Compare November 4, 2026 10:03
@kislaykishore kislaykishore changed the title perf(inode): optimize FileInode and lookupCount memory footprint and allocations Nov 4, 2026
@kislaykishore
kislaykishore changed the base branch from master to perf/file-inode-mutex-opt November 4, 2026 10:04
@kislaykishore
kislaykishore added this pull request to stack #5220 November 4, 2026 14:29
@kislaykishore
kislaykishore force-pushed the perf/file-inode-memory-opt branch from a256813 to cbe62f6 Compare November 4, 2026 14:30
@kislaykishore
kislaykishore force-pushed the perf/file-inode-memory-opt branch from cbe62f6 to adf6e1c Compare November 13, 2026 08:50
@kislaykishore
kislaykishore force-pushed the perf/file-inode-memory-opt branch from adf6e1c to bdc1f1d Compare November 13, 2026 14:44
@kislaykishore
kislaykishore removed this pull request from stack #5220 November 13, 2026 14:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

execute-integration-tests Run only integration tests execute-perf-test Execute performance test in PR

1 participant