Chapter 19 · Settings and tools设置与工具設定與工具

Large-file editing大文件编辑大檔案編輯

The line threshold, Canvas rendering, what changes in that mode, and practical tuning.行数阈值、Canvas 渲染、该模式下的差异,以及实用调优。行數閾值、Canvas 渲染、該模式下的差異,以及實用調優。

Two rendering paths

Below the threshold, documents use the TextKit path with full layout. Above it, a Canvas path renders only a sliding window of lines, backed by a line index in UTF-8 byte offsets.

The threshold

  • Configurable between 5,000 and 40,000 lines.
  • Crossing it switches the active document to the Canvas path; the file on disk is unchanged.
  • Lowering the threshold helps on memory-constrained Macs; raising it keeps small conveniences available on medium files.

What stays the same

  • Editing, undo, find and replace, encoding and saving behave as usual.
  • Line numbers, current-line highlight and syntax colours remain.
  • Session restore still records caret and scroll position.

What differs

  • Only the visible window is laid out, so selection across a huge range is clamped to what is loaded.
  • Character-level comparison data is not produced for very large files (2,000-line limit).
  • Some decorations are dropped to keep frame time bounded.

Practical guidance

SituationRecommendation
Reading a 500 MB logOpen it, use find to jump, avoid select-all.
Editing a 60k-line configKeep the threshold below 60k so the Canvas path is used deliberately.
Comparing two big filesExpect whole-line highlights only; split the task by section if you need character detail.

Saving large files

Saving writes the buffer atomically. If the buffer cannot be written safely — for example an oversized in-memory representation — the app refuses and reports the failure instead of writing a truncated file.

Measurement policy

Performance statements on this site are limited to cases with a reproducible benchmark in the repository. We do not generalise from one machine or one file.

两条渲染路径

低于阈值时使用 TextKit 全量排版;超过阈值后切换到 Canvas 路径,只渲染一个滑动窗口,并以 UTF-8 字节偏移维护行索引。

阈值

  • 可在 5,000–40,000 行之间配置。
  • 超过即把当前文档切换到 Canvas 路径;磁盘上的文件不变。
  • 调低阈值对内存紧张的机器更友好;调高则能让中等文件继续享受完整能力。

保持不变的部分

  • 编辑、撤销、查找替换、编码与保存行为一致。
  • 行号、当前行高亮与语法配色保留。
  • 会话仍会记录光标与滚动位置。

不同的部分

  • 只排版可见窗口,因此超大范围的选择会被限制在已加载内容内。
  • 超大文件不生成字符级比较数据(上限 2,000 行)。
  • 部分装饰会被舍弃,以保证单帧时间可控。

实用建议

场景建议
查看 500 MB 日志打开后用查找跳转,避免全选。
编辑 6 万行配置把阈值设在 6 万以下,让 Canvas 路径明确接管。
比较两个大文件只会有整行高亮;需要字符级细节时请分段比较。

保存大文件

保存以原子方式写入。若缓冲区无法安全写出(例如内存表示过大),应用会拒绝并报告失败,而不是写出一个被截断的文件。

度量原则

本站的性能表述仅限于仓库中有可复现基准的场景,不从单台机器或单个文件外推。

兩條渲染路徑

低於閾值時使用 TextKit 全量排版;超過閾值後切換到 Canvas 路徑,只渲染一個滑動視窗,並以 UTF-8 位元組偏移維護行索引。

閾值

  • 可在 5,000–40,000 行之間配置。
  • 超過即把當前文件切換到 Canvas 路徑;磁碟上的檔案不變。
  • 調低閾值對記憶體緊張的機器更友好;調高則能讓中等檔案繼續享受完整能力。

保持不變的部分

  • 編輯、復原、尋找取代、編碼與儲存行為一致。
  • 行號、當前行高亮與語法配色保留。
  • 工作階段仍會記錄游標與捲動位置。

不同的部分

  • 只排版可見視窗,因此超大範圍的選擇會被限制在已載入內容內。
  • 超大檔案不生成字元級比較資料(上限 2,000 行)。
  • 部分裝飾會被捨棄,以保證單影格時間可控。

實用建議

場景建議
查看 500 MB 日誌開啟後用尋找跳轉,避免全選。
編輯 6 萬行配置把閾值設在 6 萬以下,讓 Canvas 路徑明確接管。
比較兩個大檔案只會有整行高亮;需要字元級細節時請分段比較。

儲存大檔案

儲存以原子方式寫入。若緩衝區無法安全寫出(例如記憶體表示過大),應用會拒絕並報告失敗,而不是寫出一個被截斷的檔案。

度量原則

本站的效能表述僅限於倉庫中有可復現基準的場景,不從單台機器或單個檔案外推。