Skip to content

Reduce finite-state machine hash allocations - #781

Closed
Ubospica wants to merge 1 commit into
mlc-ai:mainfrom
Ubospica:codex/perf-compact-fsm-hash
Closed

Ubospica wants to merge 1 commit into
mlc-ai:mainfrom
Ubospica:codex/perf-compact-fsm-hash

Conversation

@Ubospica

Copy link
Copy Markdown
Collaborator

改动

XGrammar 是本仓库的语法约束生成库。有限状态机是一种用状态和状态转换表示允许路径的数据结构。本改动用连续数组保存状态编号和临时摘要,替代反复创建树形映射与小对象,减少整条有限状态机摘要计算期间的内存分配。

改动只涉及摘要计算,不改变公开接口和摘要语义。

性能

输入 编译时间变化 允许词元集合生成时间变化
大型结构化标签 524.570 -> 494.245 毫秒,减少 5.8% 减少 0.4%
小型结构化标签 6.258 -> 5.946 毫秒,减少 5.0% 减少 2.8%
大型 JSON 结构描述 增加 1.7% 增加 1.7%
小型 JSON 结构描述 增加 3.1% 增加 4.1%

两类结构化标签有可见收益,另外两类输入的变化没有达到 5% 的明确变化阈值。

正确性

  • 四类正式输入的优化前后接受结果差异为 0。
  • 对应非可编辑安装运行语法编译测试:11 项通过,9 项因需要额外模型词表而未执行。

@Ubospica Ubospica changed the title [codex] Reduce finite-state machine hash allocations Reduce finite-state machine hash allocations Jul 30, 2026
@Ubospica
Ubospica marked this pull request as ready for review July 30, 2026 15:38
Copilot AI review requested due to automatic review settings July 30, 2026 15:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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.

3 participants