Repository navigation
[2.1[ perf: Avoid rebuilding open-tag array on every closing BBCode tag - #9806
Merged
Merged
Conversation
parse_bbc() checked whether a closing tag matched any open tag by
calling array_map() to build a fresh array of every open tag's name,
then in_array() over the result. This ran on every closing tag
encountered, re-allocating and re-scanning the full open-tag stack
each time.
Replace it with a direct foreach that exits as soon as a match is
found, with identical matching semantics and no new allocation.
Benchmarked against a single [list] nested N levels deep (N opens
followed by N closes), timing parse_bbc() directly via a disposable
local instance:
N before after speedup
500 0.0403s 0.0251s 1.6x
1000 0.1377s 0.0772s 1.8x
2000 0.5133s 0.2725s 1.9x
4000 1.9780s 1.0139s 2.0x
8000 7.6830s 3.9038s 2.0x
16000 31.1173s 15.9310s 2.0x
32000 123.6493s 62.3919s 2.0x
Co-Authored-By: Claude Sonnet 5 <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.
parse_bbc() checked whether a closing tag matched any open tag by calling array_map() to build a fresh array of every open tag's name, then in_array() over the result. This ran on every closing tag encountered, re-allocating and re-scanning the full open-tag stack each time.
Replace it with a direct foreach that exits as soon as a match is found, with identical matching semantics and no new allocation.
Benchmarked against a single [list] nested N levels deep (N opens followed by N closes), timing parse_bbc() directly via a disposable local instance: