Skip to content

[2.1[ perf: Avoid rebuilding open-tag array on every closing BBCode tag - #9806

Merged
live627 merged 1 commit into
SimpleMachines:release-2.1from
live627:bbc
Oct 26, 2026
Merged

live627 merged 1 commit into
SimpleMachines:release-2.1from
live627:bbc

Conversation

@live627

@live627 live627 commented Oct 26, 2026

Copy link
Copy Markdown
Contributor

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

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>
@live627
live627 merged commit d9e5a1d into SimpleMachines:release-2.1 Oct 26, 2026
11 checks passed
@live627
live627 deleted the bbc branch October 26, 2026 03:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant