Skip to content

Conversation

kaja47
Copy link
Contributor

@kaja47 kaja47 commented May 7, 2021

  • unpack function bypasses costly snprintf call possible (ie. case of named fields without repetition).
  • field names are allocated by zend_string_init_fast and added to the resulting hashmap by zend_symtable_update. This way there's no internal call to strlen() as in add_assoc_*.
  • numerical suffixes for small number of repetitions are hardcoded for additional speedups

As a result this PR speeds up calls like unpack('Va/Vb/Vc/Vd/Ve', $str) almost 3x.

- unpack function bypasses costly snprintf call if possible (ie. named
  field without repetition).
- Elements are added via add_assoc_*_ex functions with explicit key length.
  This way there's no need for internal strlen call.
@ramsey ramsey added the Feature label May 7, 2021
@ramsey ramsey added this to the PHP 8.1 milestone May 8, 2021
@nikic nikic merged commit 21422e8 into php:master May 14, 2021
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.

4 participants