iOS client for Grain grain.social
ios photography atproto
7
fork

Configure Feed

Select the types of activity you want to include in your feed.

build: signpost every on-disk image cache write

Adds a minimal ImagePipelineDelegate whose willCache hook emits a
DiskCacheWrite os_signpost event with the image's last path component
and byte count. Verifies the fullsize-never-cached discipline holds:
after the refactor every event should fall in the thumb/avatar byte
range (tens to a few hundred KB), never the fullsize range (1-5 MB).

authored by

Hima Aramona and committed by
Chad Miller
f77545d0 e9d2b428

+26 -1
+1 -1
Grain/GrainApp.swift
··· 18 18 if let dataCache = try? DataCache(name: "social.grain.images") { 19 19 config.dataCache = dataCache 20 20 } 21 - await MainActor.run { ImagePipeline.shared = ImagePipeline(configuration: config) } 21 + await MainActor.run { ImagePipeline.shared = ImagePipeline(configuration: config, delegate: GrainImagePipelineDelegate()) } 22 22 appSignposter.endInterval("NukePipelineSetup", state) 23 23 appLogger.debug("[NukePipelineSetup] end") 24 24 }
+25
Grain/Utilities/ImagePipelineSignposting.swift
··· 1 + import Foundation 2 + import Nuke 3 + import os 4 + 5 + private let diskCacheSignposter = OSSignposter(subsystem: "social.grain.grain", category: "DiskCache") 6 + 7 + /// Emits an os_signpost event every time Nuke is about to write an image to 8 + /// the on-disk `DataCache`. After the "fullsize never disk-cached" refactor, 9 + /// only thumb + avatar URLs should appear in `DiskCacheWrite` events — a 10 + /// fullsize URL showing up means the `.disableDiskCacheWrites` option leaked. 11 + /// `data.count` in the event payload makes thumb (~50–300 KB) vs fullsize 12 + /// (~1–5 MB) vs avatar (~5–50 KB) obvious at a glance. 13 + final class GrainImagePipelineDelegate: ImagePipelineDelegate { 14 + func willCache( 15 + data: Data, 16 + image _: ImageContainer?, 17 + for request: ImageRequest, 18 + pipeline _: ImagePipeline, 19 + completion: @escaping (Data?) -> Void 20 + ) { 21 + let name = request.url?.lastPathComponent ?? "nil" 22 + diskCacheSignposter.emitEvent("DiskCacheWrite", "\(name) bytes=\(data.count)") 23 + completion(data) 24 + } 25 + }