Repository navigation
fix: resolve benchmark cold start OOM by resetting DFA cache - #497
Merged
Merged
Conversation
Cythia828
approved these changes
Oct 29, 2026
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.
Fixes #498
现象与背景
在执行 MySQL 等语法的冷启动基准测试(如
npm run benchmark或npm run benchmark:release)时,进程经过多轮迭代后出现堆内存溢出(JavaScript heap out of memory)。问题根因
clearATNCache()中删除require.cache重新require模块以模拟无状态冷启动。但在tsx/Node 环境下,模块重新求值会导致重复创建大型静态 ATN、反序列化结构和 DFA 数组,旧模块闭包与已求值 ES 模块在 V8 内部无法被 GC 卸载,每轮净增约 30~37MB 内存,累积突破堆上限导致 OOM。package.json中的test与benchmark脚本使用了NODE_OPTIONS=... && ...语法,中间的&&导致环境变量未能正确导出给后续子进程。修复方案
src/parser/common/basicSQL.ts):resetDfaCache()方法,调用 antlr4ng 的interpreter.clearDFA()原位清空共享决策状态,并重置实例输入与 parseTree 缓存。benchmark/sqlBenchmark.ts):require模块;parser.resetDfaCache()清理决策状态,100% 保持冷启动的语法测试语义。package.json,scripts/benchmark.js):package.json中的NODE_OPTIONS语法错误,确保内存参数生效;scripts/benchmark.js中补充--hot传参与默认内存上限继承。test/common/basicSQL.test.ts):resetDfaCache针对共享 DFA 状态生成、重置与后续再次解析正确性的回归测试。验证
pnpm benchmark --lang=mysql跑完全部 12 组用例 × 5 轮(共 60 轮冷启动),内存稳定在 120MB~260MB 区间,彻底解决 OOM 问题;pnpm benchmark --lang=mysql --hot验证热启动,首轮后均稳定在毫秒级;pnpm test全量单元测试(224 个套件,6524 个测试)全部通过;pnpm check-types类型检查通过。