perf(cache): use Arc<str> for etag/content_type in ContentCachePort

Replace String with Arc<str> for etag and content_type fields in the
content cache. String::clone() allocates and copies the full string on
every cache hit (O(n)), while Arc<str>::clone() is O(1) — just an atomic
ref-count increment.

This eliminates 2 heap allocations per cache hit on the hottest download
path. At 1000 req/s that is 2000 fewer alloc/dealloc cycles per second.

Changed files:
- cache_ports.rs: trait signatures String → Arc<str>
- file_content_cache.rs: CacheEntry fields, get/put methods, tests
- stubs.rs: StubContentCachePort signatures
- file_retrieval_service.rs: caller creates Arc<str> before put()
This commit is contained in:
Dionisio
2026-02-24 13:22:04 +01:00
parent 962468a1ce
commit cace61127f
4 changed files with 29 additions and 23 deletions
+2 -2
View File
@@ -790,11 +790,11 @@ impl ContentCachePort for StubContentCachePort {
false
}
async fn get(&self, _file_id: &str) -> Option<(Bytes, String, String)> {
async fn get(&self, _file_id: &str) -> Option<(Bytes, Arc<str>, Arc<str>)> {
None
}
async fn put(&self, _file_id: String, _content: Bytes, _etag: String, _content_type: String) {}
async fn put(&self, _file_id: String, _content: Bytes, _etag: Arc<str>, _content_type: Arc<str>) {}
async fn invalidate(&self, _file_id: &str) {}