Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Zend/zend_language_scanner.l
Original file line number Diff line number Diff line change
Expand Up @@ -2540,7 +2540,11 @@ inline_char_handler:
HANDLE_NEWLINES(yytext, yyleng);

if (doc_com) {
CG(doc_comment) = zend_string_init(yytext, yyleng, 0);
/* Only the compiler consumes doc comments; tokenizing/highlighting
* would copy and then discard them. */
if (PARSER_MODE()) {
CG(doc_comment) = zend_string_init(yytext, yyleng, 0);
}
RETURN_OR_SKIP_TOKEN(T_DOC_COMMENT);
}

Expand Down
6 changes: 4 additions & 2 deletions ext/tokenizer/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,10 @@ static bool tokenize(zval *return_value, zend_string *source, zend_class_entry *
zend_prepare_string_for_scanning(&source_zval, ZSTR_EMPTY_ALLOC());

LANG_SCNG(yy_state) = yycINITIAL;
zend_hash_init(&interned_strings, 0, NULL, NULL, 0);
array_init(return_value);
zend_hash_init(&interned_strings, 128, NULL, NULL, 0);
/* Rough estimate: one token per ~5 source bytes; presizing avoids
* repeated doubling of the result array. */
array_init_size(return_value, ZSTR_LEN(source) / 5 + 8);

@LamentXU123 LamentXU123 Aug 10, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about this? Now, I see the reason why this improves performance somehow, as claude claims, but this completely depends on the input.

For example, a huge inline HTML, or very long strings only produce a few tokens. but the first insert will allocate packed array capacity based on source bytes. This can turn valid large inputs into avoidable OOM cases that we don't want to see.

As far as I can tell, roughly >160 MiB already exceeds HT_MAX_SIZE on 32 bits.

I didn't run any benchmark tho, so someone need to prove the improvements exists :)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm also skeptical about this... the ~5 figure really comes out of thin air.


HashTable *return_value_ht = Z_ARRVAL_P(return_value);

Expand Down
Loading