Skip to content
Discussion options

You must be logged in to vote

Thanks for proposing this!

The current zend_hash_str_* path does a fresh zend_string_init (emalloc + memcpy + hash recomputation) on every new bucket. Letting callers pass a zend_string directly hits zend_hash_update and friends, which:

  • reuse the cached ZSTR_H(key) (no re-hash),
  • for interned keys, store the pointer with no allocation, no copy, and keep HASH_FLAG_STATIC_KEYS set,
  • for refcounted keys, just bump the refcount.

I can see real wins for interned hotkeys cached at MINIT, mangled property keys (\0Class\0prop), and zend_string round-tripping from PHP into a new array.

A few concerns for the PR:

  1. Additive, not a replacement. We should keep the &str and String paths untouched.
  2. Scop…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ptondereau
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants