C apis for efficiently adding/checking if a pointer is in a HashTable, reducing hash collisions?
Personne n'a encore pris cette issue.
- Langage dominant
- C
- Étoiles
- 40.4k
- Forks
- 8.2k
- Merge moyen
- 2 j 13 h
- PR mergées (30 j)
- 96
Description
Description
Description
C pointers in php are aligned to at least ZEND_MM_ALIGNMENT_LOG2 (generally 3 on 64-bit systems, 2 on 32-bit systems), whether they're from malloc or emalloc. (the lowest bit of the pointer represents the address of the byte)
Often, PECLs or php has use cases for inserting, deleting, and iterating over pointers in a hash map, and this is much slower when they collide to the same 1 in 8 (or 1 in 16, for larger value types) hash buckets
-
e.g. in https://github.com/php/php-src/pull/7690 saw a performance improvement from the reduction in hash collisions from shifting the pointers (and issues referencing that PR)
-
For access patterns such as allocating alternating keys and values, or pointers to large objects, there may be even more collisions with emalloc
Adding a struct such as struct zend_ptr_hash { struct zend_hash inner; } and macros/functions for common use cases when pointers are used as keys may help (zend_ptr_hash*). It'd probably be better to use the zend_hash directly.
The helper function static zend_always_inline zend_ulong zend_rotr3(zend_ulong key) in opcache could be used for preserving all bits of the pointer while avoiding hash collisions
The x32 ABI (64 bit pointers and 32 bit zend_long) is not officially supported by PHP, so there's no need for that in this feature request.
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par lire l’implémentation existante de zend_hash et l’helper zend_rotr3 dans opcache, puis examinez la pull request #7690 référencée pour le contexte concernant les collisions et les performances. Le travail sera considéré comme terminé lorsqu’il y aura accord sur des API de hachage pour clés de pointeur, ou sur une approche directe équivalente avec zend_hash, et que celle-ci sera implémentée de manière à préserver les bits des pointeurs tout en réduisant les collisions.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- c, php
- Domaine
- backend
- Type d'issue
- Fonctionnalité
- Difficulté
- 5/5
- Temps estimé
- Plus d'une semaine
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 30/100