Skip to content

Bulk Edit Optimization

Summary

Batch operations (multi-cursor, toggle comment, indent, replace-all) previously used Event::Batch which applied edits sequentially, causing O(n²) performance.

The BulkEdit event type solves this by:

  1. Applying all edits in a single tree traversal via PieceTree::apply_bulk_edits
  2. Storing tree snapshot for O(1) undo (Arc clone, not content copy)
  3. Tracking cursor positions before/after for proper undo/redo

Performance

MetricBefore (Batch)After (BulkEdit)
Tree traversalsO(N)O(1)
Tree rebuildsO(N)O(1)
Memory for undoO(N) event objectsO(1) Arc clone
Time complexityO(N × pieces)O(pieces + N)

For 500 cursors: ~500x improvement.

Migration Status

OperationStatusLocation
Multi-cursor edits✅ Donesrc/app/mod.rs
Replace All✅ Donesrc/app/render.rs (ReplaceAll event removed)
Toggle Comment✅ Donesrc/app/render.rs
Indent/Dedent✅ Donesrc/app/mod.rs
LSP Rename✅ Donesrc/app/lsp_requests.rs
Multi-cursor Paste✅ Donesrc/app/clipboard.rs

Key Functions

  • PieceTree::apply_bulk_edits() - Apply multiple edits in single traversal
  • Editor::apply_events_as_bulk_edit() - Convert Insert/Delete events to BulkEdit
  • Event::BulkEdit - Stores old_tree, old_cursors, new_cursors for undo/redo

Released under the Apache 2.0 License