长章节内存优化 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
@@ -291,7 +291,6 @@ public final class RDEPUBTextBookBuilder {
|
||||
pageIndexInChapter: localPageIndex,
|
||||
totalPagesInChapter: effectiveFrames.count,
|
||||
chapterContent: chapterAttributedContent,
|
||||
content: content.attributedSubstring(from: range),
|
||||
contentRange: range,
|
||||
pageStartOffset: range.location,
|
||||
pageEndOffset: range.location + max(range.length - 1, 0),
|
||||
|
||||
@@ -54,7 +54,15 @@ public struct RDEPUBTextPage: Equatable {
|
||||
|
||||
public var chapterContent: NSAttributedString
|
||||
|
||||
public var content: NSAttributedString
|
||||
/// Page substring derived on demand from `chapterContent` + `contentRange`.
|
||||
/// Not stored: keeping a per-page substring alive roughly doubles the
|
||||
/// chapter's resident text memory across the chapter cache window.
|
||||
public var content: NSAttributedString {
|
||||
let bounds = NSRange(location: 0, length: chapterContent.length)
|
||||
let clamped = NSIntersectionRange(contentRange, bounds)
|
||||
guard clamped.length > 0 else { return NSAttributedString() }
|
||||
return chapterContent.attributedSubstring(from: clamped)
|
||||
}
|
||||
|
||||
public var contentRange: NSRange
|
||||
|
||||
|
||||
@@ -75,7 +75,6 @@ public final class RDPlainTextBookBuilder {
|
||||
pageIndexInChapter: localPageIndex,
|
||||
totalPagesInChapter: effectiveFrames.count,
|
||||
chapterContent: chapterAttributedContent,
|
||||
content: content.attributedSubstring(from: range),
|
||||
contentRange: range,
|
||||
pageStartOffset: range.location,
|
||||
pageEndOffset: range.location + max(range.length - 1, 0),
|
||||
|
||||
Reference in New Issue
Block a user