Repository navigation
未閉じ構文の反復で解析時間が二次になる問題の修正 - #39
Merged
Merged
Conversation
1 回の解析中だけ </plain> の探索結果(発見位置または不在)を共有し、二次の再走査を無くす。 あわせて url/link の substring(position).startsWith を startsWith(pattern, position) に置き換えて全文コピーを避ける。 Co-Authored-By: Codex Sol <noreply@openai.com>
1 回の解析中だけ、失敗した走査区間とネスト予算の消費量を記録して再生し、二次の再走査を無くす。 予算の消費量と AST は変えない。 Co-Authored-By: Codex Sol <noreply@openai.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <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.
概要
未閉じの構文を多数並べた入力で、解析時間が入力長の二乗で増え、同期呼び出しが数秒止まる問題を修正。mfm.js 0.28.0 は同じ入力で線形。
原因
閉じが無いと、開始記号ごとに残りの入力全体を走査し直していた。mfm.js は走査済みの区間や失敗位置を再利用する。
変更
<plain>: 1 回の解析中だけ</plain>の探索結果(発見位置または不在)を共有。[・[a(リンクラベル)、\((インライン数式)、<center>+ 改行: 失敗した走査区間と、その走査が消費したネスト予算を記録して再生。AST とネスト予算の消費量は変えない。substring(position).startsWith(...)をstartsWith(pattern, position)に置換し、全文コピーを除去。計測(5,000 回繰り返し、JIT)
<plain>[[a\(<center>+ 改行80,000 回でも線形。通常の長文(約 31,000 文字)は 45ms から 30ms。
確認
<plain>、リンク、数式、center の通常・入れ子・途中閉じ・改行コード・quote 内・parser 再利用・予算消費後の挙動)。dart test(911 件)・dart analyze成功。[Unreleased]を更新。補足
parser.dartのbuildSimpleと CHANGELOG で競合する。後からマージする側で解消する。