perf: Optimize folder UpdateTime timestamp by using int64 instead of time.Time #4859
perf: Optimize folder UpdateTime timestamp by using int64 instead of time.Time #4859vedantdas-source wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the Folder struct's UpdateTime field from time.Time to int64 (Unix nanoseconds) across the GCS and fake storage implementations, and adds a benchmark test for GCSFolder. The review feedback highlights a critical concurrency issue in RenameFolder where the mutex lock b.mu is not acquired, potentially causing race conditions. Additionally, the reviewer recommends replacing instances of time.Now() with the mock clock b.clock.Now() in the fake bucket implementation to maintain deterministic test behavior.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #4859 +/- ##
===========================================
+ Coverage 0 83.70% +83.70%
===========================================
Files 0 170 +170
Lines 0 20954 +20954
===========================================
+ Hits 0 17539 +17539
- Misses 0 2760 +2760
- Partials 0 655 +655
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:
|
Description
By default,
Folder.UpdateTimewas stored as atime.Timevalue, which occupies 24 bytes. By converting this field to a Unix nanosecondint64representation which uses 8 bytes, we can safely reduce the structural footprint of everyFolderobject .Changes Made
Folder.UpdateTimefrom time.Time toint64.!t.IsZero()inGCSFolderto ensure that uninitialized folder timestamps default to 0 instead of a negative value.UnixNano()values.Benchmarking results
Using
time.TimeUsing
int64All existing tests pass successfully.
Link to the issue in case of a bug fix.
Testing details
BenchmarkGCSFolderbenchmark infolder_test.goto compare memory and CPU performance.Any backward incompatible change? If so, please explain.