Skip to content

[0147] 优化打开大体积 TMU 文件的性能#3420

Open
da-liii wants to merge 11 commits into
mainfrom
da/0147/big_doc
Open

[0147] 优化打开大体积 TMU 文件的性能#3420
da-liii wants to merge 11 commits into
mainfrom
da/0147/big_doc

Conversation

@da-liii
Copy link
Copy Markdown
Contributor

@da-liii da-liii commented May 20, 2026

Summary

  • 优化 from_tmu.cpp 中 RAW_DATA 的十六进制解析,用内联 from_hex_char 替代逐字节创建临时字符串调用 from_hex
  • 优化 read_next 中普通字符解析,增加快速路径批量读取 ASCII 字符,避免逐字符调用 read_char
  • 优化 decode 函数,无转义字符时直接返回原字符串,避免不必要的复制
  • 真实文件 chapter-4.tmu(14.4MB)解析时间从 399ms 降至 284ms(约 29% 提升)

Test plan

  • xmake b convert_test && xmake r convert_test 单元测试通过
  • xmake b stem && xmake r stem /home/da/DevTeam/chapter-4.tmu 验证大文件加载正常
  • 新增 TMU 解析性能测试用例

🤖 Generated with Claude Code

da-liii and others added 11 commits May 19, 2026 17:52
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
避免在解析 <#...> 十六进制数据时,每两个字符创建一次临时字符串。
通过内联函数直接处理字符,1M hex bytes 解析时间从 41ms 降至 29ms。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
通过快速路径直接批量读取连续的 ASCII 普通字符,避免逐字符调用
read_char 创建临时字符串。1M 文本字符解析时间从约 100ms 降至约 40ms。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
对于不含反斜杠转义的字符串,直接返回原字符串,避免逐字节复制。
1M 文本字符解析时间从约 40ms 进一步降至约 20ms。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
新增单元测试覆盖 RAW_DATA、长文本和真实文件(chapter-4.tmu)的
解析性能,用于验证优化效果。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
更新 0147.md 中的性能数据为 bench_start/bench_end 测量结果,
应用 bin/format 格式化。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
- 移除 from_hex_char 中多余的 C-style cast
- 移除 read_next 中冗余的 if-else 分支和注释掉的旧代码
- 统一 fast path 中 ch 变量的使用
- UTF-8 分支改为批量追加替代逐字符追加
- 测试中 hex_data 构建改用 <<char 避免 100 万次临时 string 分配
- 新增单元测试:纯文本、转义序列、文档、复合节点

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant