Problem
From verify of #115 (DA P3 #6):
「Performance:AnchorLookupOptions.contains 對全文做 O(N×M) 掃描,沒 short-circuit、沒 benchmark。1000+ paragraph 文件、多次 lookup 場景未驗證 perf。」
— Source: team:devils-advocate (P3)
Verify report: #115 (comment)
Type
perf / observability
Strategy
1. 加 benchmark target:
// In ooxml-swift Tests
final class AnchorLookupBenchmarks: XCTestCase {
func testLookupLatency_1000Paragraphs_FlagOff() throws {
let doc = makeDocxWith(paragraphs: 1000, avgChars: 200)
measure {
for _ in 0..<100 {
_ = doc.findText("typical anchor", options: .exact)
}
}
}
func testLookupLatency_1000Paragraphs_FlagOn() throws {
let doc = makeDocxWith(paragraphs: 1000, avgChars: 200)
measure {
for _ in 0..<100 {
_ = doc.findText("typical anchor", options: .mathScriptInsensitive)
}
}
}
}
報告 ratio:flag on 應該 < 2x flag off latency。
2. 若 ratio > 2x,考慮優化:
- Memoize per-paragraph normalized form on demand
- Pre-compute
flattenedNormalized field on Paragraph load(trade memory for repeated lookup speed)
- Short-circuit: if needle has no Unicode subscript / superscript chars, fall back to
.exact 路徑而非走 normalized
Test
- Benchmark target run on CI、結果記錄為 baseline
- Lib 加 measurement test,PR 不必 ship 結果但要有測試可跑
Related
Problem
Type
perf / observability
Strategy
1. 加 benchmark target:
報告 ratio:flag on 應該 < 2x flag off latency。
2. 若 ratio > 2x,考慮優化:
flattenedNormalizedfield on Paragraph load(trade memory for repeated lookup speed).exact路徑而非走 normalizedTest
Related