Repository navigation
lexbor: Shrink the initial tokenizer pools and mraw cache - #23949
Open
nicolas-grekas wants to merge 2 commits into
Open
nicolas-grekas wants to merge 2 commits into
nicolas-grekas wants to merge 2 commits into
Conversation
nicolas-grekas
force-pushed
the
lexbor-small-pools
branch
2 times, most recently
from
October 2, 2026 10:36
8f41929 to
7a758c4
Compare
nicolas-grekas
force-pushed
the
lexbor-small-pools
branch
2 times, most recently
from
October 6, 2026 13:53
846fe04 to
ad352ea
Compare
lexbor_array_obj_init() and lexbor_array_obj_expand() allocated 8 times the memory they need on 64-bit platforms, and lexbor_array_obj_delete() moved 8 times the bytes of the remaining entries. This is patch 0025, merged upstream as lexbor/lexbor@f4cbbcd. ext/dom uses such an array as its work list when it converts the parsed tree to libxml2, so gh25118.phpt needs a lower memory_limit to still fail during that conversion.
The HTML tokenizer preallocated 4096 tokens and 4096 token attributes, and each lexbor_mraw_t preallocated 512 entries for its cache of freed blocks, 7 of them per parser. This made Dom\HTMLDocument::createFromString() and setting innerHTML allocate about 1.1MB even for a few bytes of input. The tree builder uses a single token and these pools grow on demand, so start with 16 tokens, 256 attributes and 64 cache entries. This is patch 0026, the pending lexbor/lexbor#427. It allows setting the sizes at build time, which PHP does in config.m4 and config.w32.
nicolas-grekas
force-pushed
the
lexbor-small-pools
branch
from
November 12, 2026 17:29
ad352ea to
d58660f
Compare
Contributor
Author
|
I moved the lexbor/lexbor#427 is still open. The maintainer likes the @kocsismate @ndossche WDYT? Parsing a small string needs about 200KB instead of 1.1MB. |
kocsismate
reviewed
Nov 13, 2026
| after a dot segment in a path, replacement file drive paths, the output | ||
| encoding used for percent-encoding, the URLSearchParams tail pointer and | ||
| fragment serialization without a query. (alexandre-daubois) | ||
| . Merge patch lexbor/lexbor@f4cbbcd, fixing lexbor_array_obj_t allocating 8 |
Member
There was a problem hiding this comment.
isn't this too low level for a NEWS entry? I'm wondering if it would be possible to mention something directly related to end users.
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.
On top of #25431, which is the first commit here.
Dom\HTMLDocument::createFromString()and settinginnerHTMLallocate about 1.1MB on every call, even for a few bytes of input, because lexbor preallocates 4096 tokens, 4096 token attributes and, in each of the 7lexbor_mraw_tof a parser, 512 entries for its cache of freed blocks. It's freed after the call, but it's enough to push a small request into a second 2MB memory chunk.The tree builder uses a single token and these pools grow on demand, so this makes them start with 16 tokens, 256 attributes and 64 cache entries. The change is patch 0026. It's lexbor/lexbor#427, which isn't merged yet. The patch allows setting the sizes at build time, and PHP sets them in config.m4 and config.w32. So php-src doesn't depend on the defaults that upstream picks, and the patch can be replaced by the upstream commit once it's merged.
Parsing a small string then needs about 200KB instead of 1.1MB, and large documents parse as fast as before.