Skip to content

ext/intl: various optimization#22069

Draft
LamentXU123 wants to merge 3 commits into
php:masterfrom
LamentXU123:opt-intl
Draft

ext/intl: various optimization#22069
LamentXU123 wants to merge 3 commits into
php:masterfrom
LamentXU123:opt-intl

Conversation

@LamentXU123
Copy link
Copy Markdown
Contributor

@LamentXU123 LamentXU123 commented May 17, 2026

  • When the array size is larger than 8, using array_init_size is slightly faster than array_init.Similar to uri: Preinitialize errors array with the correct size in fill_errors() #21560 and ext/openssl: various arrays optimisations. #18377
  • Directly use length instead of strlen(...) if it is already known to enhance readability.
  • In transliterator/transliterator_methods.cpp: counted the ICU enumeration up front with uenum_count(), reset it, and switched transliterator_list_ids() to array_init_size(). So we now use ICU APIs to get total length and use array_init_size instead of array_init directly here.
  • In resourcebundle/resourcebundle_class.cpp: ditto. counted available locales before iteration and initialized the return array with the exact capacity.

@LamentXU123 LamentXU123 marked this pull request as ready for review May 17, 2026 06:34
@LamentXU123 LamentXU123 requested a review from devnexen as a code owner May 17, 2026 06:34
@devnexen
Copy link
Copy Markdown
Member

If you have further optimisations plan you can put it there too.

@LamentXU123 LamentXU123 changed the title ext/intl: refactor to use array_init_size instead of array_init when the size is known ext/intl: various optimization May 17, 2026
@LamentXU123 LamentXU123 marked this pull request as draft May 17, 2026 08:16
@LamentXU123 LamentXU123 force-pushed the opt-intl branch 3 times, most recently from 0018bf2 to da1313e Compare May 17, 2026 12:52
@LamentXU123 LamentXU123 changed the base branch from master to PHP-8.4 May 17, 2026 12:52
}
if (date_type == UDAT_PATTERN && time_type != UDAT_PATTERN) {
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: time format must be UDAT_PATTERN if date format is UDAT_PATTERN", 0);
intl_error_set(NULL, U_ILLEGAL_ARGUMENT_ERROR, "datefmt_create: time format must be IntlDateFormatter::PATTERN if date format is IntlDateFormatter::PATTERN", 0);
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.

optimisations need to land in master, this is not one.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Let's open a separate PR for this :)

Copy link
Copy Markdown
Contributor Author

@LamentXU123 LamentXU123 May 17, 2026

Choose a reason for hiding this comment

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

I add this to #22073 targeting PHP 8.4 now this is targeting master.

Also lots of work remains here so feel free to unsubscribe. I will request for your review after everything is done :) p.s. could you delete those tags for me (just leave the ext:intl is fine)? there appears to be some github glitch...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants