php / php/php-src

C apis for efficiently adding/checking if a pointer is in a HashTable, reducing hash collisions?

Abierto
#9,813 6 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Feature Status: Needs Triage
Lenguaje dominante
C
Estrellas
40.4k
Forks
8.2k
Merge medio
2 d 13 h
PR fusionados (30 d)
96

Descripción

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.

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Línea de trabajo

Comienza leyendo la implementación existente de zend_hash y el helper zend_rotr3 en opcache; después, revisa el pull request #7690 referenciado para conocer el contexto de las colisiones y el rendimiento. Se considerará terminado cuando se hayan acordado e implementado APIs de hash para claves de puntero, o un enfoque directo equivalente con zend_hash que preserve los bits de los punteros y reduzca las colisiones.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
c, php
Área
backend
Tipo de issue
Nueva funcionalidad
Dificultad
5/5
Tiempo estimado
Más de una semana
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
30/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.