feat(parser): make assetsPrefetcher optional to skip asset collection - #1032
Draft
A-kirami wants to merge 2 commits into
Draft
feat(parser): make assetsPrefetcher optional to skip asset collection#1032A-kirami wants to merge 2 commits into
A-kirami wants to merge 2 commits into
Conversation
sceneParser 在逐语句 map 里用 [...assetsList, ...sentenceAssets] 复制整个 已累积列表,资源密集脚本的整体复杂度因此是 Θ(资源数²):8000 条语句 (5333 个资源引用)解析耗时 47.8ms,而同样语句数、不带资源的脚本只要 6.7ms(线性)。 改为就地 push 追加,结果内容与顺序完全不变。新增回归测试: - 多条语句的资源/子场景累积顺序、类型去重与 prefetcher 入参保持一致 - 语句数 ×4 时耗时不得超过 ×8(旧实现在该测试下比值约 22)
编辑器类调用方只需要语句结构,却要传一个空函数来满足签名,并为此付出每条语句 资源扫描、场景级汇总与去重的开销。把 assetsPrefetcher 改成可选:省略时不收集 资源,sentenceAssets / subScene / assetsList / subSceneList 均为空数组。 现有调用方行为不变(传了回调就照旧收集)。每条语句都带资源引用的脚本上,解析 耗时约降低 1/5 到 1/3(8000 条语句 10.0ms → 7.4ms)。
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.
改动
assetsPrefetcher改为可选。省略时不再收集资源:sentenceAssets/subScene/assetsList/subSceneList都是空数组,也不调用预取回调。编辑器只解析语句结构,却必须传一个空函数来满足签名,还要为此付出每条语句资源扫描、场景级汇总与去重的开销。传了回调的调用方(引擎运行时)行为不变。
效果
每条语句都带资源引用的脚本上(本机实测,重复测量取最小值):4000 条语句 4.9ms → 3.6ms,8000 条 9.9ms → 7.4ms。
验证
cd packages/parser && npx vitest run,34 个用例通过;新增 3 个用例覆盖跳过时的空字段、传回调时收集结果不变、跳过不影响语句切分与行范围。说明
Terre 的两处调用点(
packages/origine2/src/utils/parser.ts、.../GraphicalEditor/parser.ts)都不读这些字段,之后可以去掉空函数拿到收益,本 PR 不改动它们。