以前提過優化內存進行大對象處理這個點,今天看蘋果文檔正好有說起一個思路,這個思路大體是這個樣子:html
儘可能避免使用大的資源文件若是能使用小的。git
讓系統選擇格式的圖片資源根據設備的狀況而不是直接使用高清分辨率的圖片。github
避免把整個大的文件加入到內存中,而是使用mmap和munmap函數將文件的某些部分映射到內存中。app
MMKV--基於 mmap 的 iOS 高性能通用 key-value 組件函數
iOS圖片加載速度極限優化—FastImageCache解析性能
If you pass the DataReadingMappedIfSafe option to init(contentsOfFile:options:), files are memory mapped only when it’s possible to do so and the file is determined to be on a volume that can’t be removed or disappear suddenly.ui