fix(castore): introduce fast path while getting torrent metadata to reduce allocs#611
fix(castore): introduce fast path while getting torrent metadata to reduce allocs#611sambhav-jain-16 wants to merge 6 commits into
Conversation
There was a problem hiding this comment.
Pull request overview
Improves CAStore.GetCacheFileMetadata performance when serving torrent metadata from the in-memory cache by avoiding per-read serialization/deserialization, and adds coverage/benchmarks to validate allocation behavior.
Changes:
- Add a fast path in
CAStore.GetCacheFileMetadatato return the cached*core.MetaInfopointer directly for*metadata.TorrentMeta. - Add a unit test asserting the no-copy behavior when reading metadata from the memory cache.
- Add a benchmark suite to measure allocations/time across different blob sizes and piece counts for memory-cache metadata reads.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
lib/store/ca_store.go |
Returns cached *core.MetaInfo directly for torrent metadata reads from memory cache, avoiding JSON round-trips. |
lib/store/ca_store_test.go |
Adds a no-copy unit test and a benchmark measuring metadata read allocations across scenarios. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
b1e3e09 to
42420f8
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
6aaaf7d to
33637e0
Compare
33637e0 to
d4a51c1
Compare
| // hand back cached pointer | ||
| tm.MetaInfo = entry.MetaInfo | ||
| return nil |
What?
TorrentMeta.Serialize/Deserializeround-trip svia JSON (json.Marshal + json.Unmarshal) for a MetaInfo. For every blob this allocates a fresh[]bytebuffer and a new*core.MetaInfoon every call toGetCacheFileMetadata. The fast path short-circuits it when the entry is already in the memory cache it hands back the existing*core.MetaInfopointer directly, so a metadata read becomes a single pointer assignment with zero heap allocations.Why only TorrentMetadata ?
TorrentMetais the only metadata type whose backing value (*core.MetaInfo) is immutable after creation. Other metadata types (e.g.LastAccessTime) are mutable values written on every access.Testing
Added a benchmark
BenchmarkGetCacheFileMetadata_MemoryCachewith different blob sizes and metadata sizesFollowing is the
benchstatcomparison.