长章节内存优化 P0:每页子串改按需构造并新增内存打点
- RDEPUBTextPage.content 由存储属性改为基于 chapterContent+contentRange 的计算属性,三处构造点不再生成每页子串,章节缓存窗口内每章少一份 整章文本常驻副本 - 新增 RDEPUBMemoryProbe(--demo-memory-probe 开启),在章节插入、 每 20 次翻页、设置失效、转屏完成时输出 phys_footprint - shouldAvoidReaderPageCaching 补注释,锁定放开前置条件为 P1-1 - 新增实施清单文档 LONG_CHAPTER_MEMORY_OPTIMIZATION_PLAN.md 并勾选 P0 验证:Demo 编译通过;UI 回归 9/9 通过(PageNavigation/ ReaderOpenClose/LargeBookOnDemand) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
5a41066b66
commit
e4e629a06c
@@ -0,0 +1,43 @@
|
||||
import Foundation
|
||||
|
||||
/// Memory footprint probe for the long-chapter optimization work
|
||||
/// (Doc/LONG_CHAPTER_MEMORY_OPTIMIZATION_PLAN.md, P0-2). Enabled with the
|
||||
/// `--demo-memory-probe` launch argument; logs phys_footprint at chapter
|
||||
/// load, every 20 page turns, settings invalidation, and rotation.
|
||||
enum RDEPUBMemoryProbe {
|
||||
|
||||
static let isEnabled = ProcessInfo.processInfo.arguments.contains("--demo-memory-probe")
|
||||
|
||||
private static let pageTurnLogStride = 20
|
||||
|
||||
/// Main-thread only (page turns are delivered on main).
|
||||
private static var pageTurnCount = 0
|
||||
|
||||
static func logPageTurn() {
|
||||
guard isEnabled else { return }
|
||||
pageTurnCount += 1
|
||||
guard pageTurnCount % pageTurnLogStride == 0 else { return }
|
||||
log("pageTurn count=\(pageTurnCount)")
|
||||
}
|
||||
|
||||
static func log(_ event: String) {
|
||||
guard isEnabled else { return }
|
||||
let megabytes = Double(currentFootprint()) / 1_048_576
|
||||
print(String(format: "[EPUB][MemoryProbe] %@ footprint=%.1fMB", event, megabytes))
|
||||
}
|
||||
|
||||
/// phys_footprint matches the value Xcode's memory gauge and Jetsam use.
|
||||
private static func currentFootprint() -> UInt64 {
|
||||
var info = task_vm_info_data_t()
|
||||
var count = mach_msg_type_number_t(
|
||||
MemoryLayout<task_vm_info_data_t>.size / MemoryLayout<integer_t>.size
|
||||
)
|
||||
let result = withUnsafeMutablePointer(to: &info) { pointer in
|
||||
pointer.withMemoryRebound(to: integer_t.self, capacity: Int(count)) {
|
||||
task_info(mach_task_self_, task_flavor_t(TASK_VM_INFO), $0, &count)
|
||||
}
|
||||
}
|
||||
guard result == KERN_SUCCESS else { return 0 }
|
||||
return info.phys_footprint
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user