[0147] 优化打开大体积 TMU 文件的性能#3420
Open
da-liii wants to merge 11 commits into
Open
Conversation
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>
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.
Summary
from_tmu.cpp中 RAW_DATA 的十六进制解析,用内联from_hex_char替代逐字节创建临时字符串调用from_hexread_next中普通字符解析,增加快速路径批量读取 ASCII 字符,避免逐字符调用read_chardecode函数,无转义字符时直接返回原字符串,避免不必要的复制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验证大文件加载正常🤖 Generated with Claude Code