Repository navigation
fix: 限制长行字符级 diff 的规模,避免整行重写时前端卡死 - #8
Merged
Merged
Conversation
- 单行改动区超过 512 字符时跳过逐字符对齐,整段标记 - 行级 Myers 的编辑距离封顶 600,超限退化为整块删除加新增 - 高亮区间改按 UTF-16 偏移映射,修正 emoji 等代理对错位 - 版本升到 0.4.3,README 补充单行过长保护说明
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
在浏览器里编辑单行超长文件时,diff 卡片会把页面拖死。真实案例:
蓝图/太空挖矿.txt只有一行,编辑把 1421 字符整行换成 1565 字符,公共前缀只有 6、公共后缀是 0,等于整行重写。旧实现对该输入实测 6983ms、RSS 增长 528MB,主线程直接卡住,标签页失去响应。
原因
lineHighlight直接对整行跑字符级 Myers,既没有前后缀收缩,也没有规模上限。Myers 的回溯表按编辑距离平方增长,整行重写时 D 接近行长两倍,trace会存下几百万条快照,时间与内存一起爆掉。改动
超限时只是不逐字符对齐,diff 内容照常显示,工具行为不受影响。
验证
pnpm typecheck、pnpm build通过。