From a2df8ae68faf13400967b85f7e91c72ab7aa631c Mon Sep 17 00:00:00 2001 From: Akiba So Date: Tue, 23 Jun 2026 03:51:44 +0800 Subject: [PATCH] feat(perf): compact strokes (RDP) on persist (R10) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Wires simplifyStroke into the save conversion: a fast Surface-Pen stroke's hundreds of near-collinear samples are thinned before hitting the DB, shrinking the row + speeding reload re-rasterization (R10) with no perceptible change. The live in-memory strokes are untouched — only what we PERSIST is simplified. Makes the (unit-tested) RDP core load-bearing. flutter analyze lib/editor clean; 238/238 tests pass. Co-Authored-By: Claude Opus 4.8 (1M context) --- lib/editor/canvas/pen_editor_screen.dart | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/editor/canvas/pen_editor_screen.dart b/lib/editor/canvas/pen_editor_screen.dart index b09a882..af0d6ce 100644 --- a/lib/editor/canvas/pen_editor_screen.dart +++ b/lib/editor/canvas/pen_editor_screen.dart @@ -11,6 +11,7 @@ import 'package:pdfrx/pdfrx.dart'; import '../../services/database_service.dart'; import '../engine/stroke_geometry.dart' show kDefaultPenThinning; import '../engine/stroke_model.dart'; +import '../engine/stroke_simplify.dart'; import '../engine/undo_stack.dart'; import '../input/diagnostic_logger.dart'; import '../input/pen_config.dart'; @@ -281,8 +282,13 @@ class _PenEditorScreenState extends State { void _schedulePageSave(int pageIndex, List strokes) { final scheduler = _saveScheduler; if (scheduler == null) return; - final editorStrokes = - strokes.map((s) => EditorStroke.fromPenStroke(s)).toList(); + // Compact strokes (RDP) before persisting: a fast Surface-Pen stroke lands + // hundreds of near-collinear samples; thinning them shrinks the DB row + + // speeds reload re-rasterization (R10) with no perceptible change. The live + // in-memory strokes are untouched — only what we PERSIST is simplified. + final editorStrokes = strokes + .map((s) => simplifyStroke(EditorStroke.fromPenStroke(s))) + .toList(); scheduler.schedule( 'page', EditorRepository.pageHostId(_documentId, pageIndex),