fix(parser): accumulate assets and subscenes in place to remove superlinear cost - #1031
Merged
MakinoharaShoko merged 1 commit intoSep 13, 2026
Conversation
sceneParser 在逐语句 map 里用 [...assetsList, ...sentenceAssets] 复制整个 已累积列表,资源密集脚本的整体复杂度因此是 Θ(资源数²):8000 条语句 (5333 个资源引用)解析耗时 47.8ms,而同样语句数、不带资源的脚本只要 6.7ms(线性)。 改为就地 push 追加,结果内容与顺序完全不变。新增回归测试: - 多条语句的资源/子场景累积顺序、类型去重与 prefetcher 入参保持一致 - 语句数 ×4 时耗时不得超过 ×8(旧实现在该测试下比值约 22)
MakinoharaShoko
approved these changes
Sep 13, 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.
改动
sceneParser累积语句资源时写成了assetsList = [...assetsList, ...sentenceAssets],每条语句都会复制一遍当前已累积的列表,解析成本因此随资源引用数二次增长。资源密集的脚本(每条语句都带bg/changeFigure/say -vocal)规模上去后开销很明显。改成就地
push。累积结果、顺序、去重以及assetsPrefetcher的入参都不变;另外补了两条测试:多条语句的资源/子场景累积与去重,以及一个复杂度守卫(语句数 ×4 时耗时不得超过 ×8,旧实现在该用例下比值 22)。效果
每条语句都带一个资源引用时(本机实测):8000 条语句 41.1ms → 11.8ms,4000 条 13.1ms → 5.9ms。编辑器类调用方每次编辑都会整篇解析,这部分直接体现为输入延迟。
验证
cd packages/parser && npx vitest run,31 个用例通过。