php / php/php-src

Function `zend_hash_find_bucket` consumes much time in WordPress workload

Đang mở
#12,873 13 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Category: Engine
Ngôn ngữ chính
C
Star
40.4k
Fork
8.2k
Merge trung bình
2 ngày 13 giờ
Pull request đã merge (30 ngày)
96

Mô tả

Description

Dear, maintainers:
I am utilizing PHP-FPM and have profiled performance data for a WordPress workload. Within this benchmark, I've identified certain hotspots. The performance analysis from 'perf' highlights that functions such as zend_hash_find and zend_hash_find_known_hash are consuming a considerable amount of time. Upon investigation, I suspect that the core issue lies within the zend_hash_find_bucket function.
image

Upon inspecting the assembly code and annotating it, I noticed that certain 'mov' instructions are causing significant delays. To address this, I attempted to optimize the zend_hash_find_bucket function. I experimented with optimizations such as utilizing prefetch instructions and employing struct alignment. However, these optimizations did not seem to have a discernible impact on performance.

Percent│
       │
       │
       │    Disassembly of section .text:
       │
       │    0000000000532ae0 <zend_hash_find>:
       │    zend_hash_find():
  0.84 │      push %r12
  0.04 │      push %rbp
  0.01 │      mov  %rsi,%rbp
  2.52 │      push %rbx
       │    zend_string_hash_val():
  8.01 │      mov  0x8(%rsi),%rax
       │    zend_hash_find():
  0.02 │      mov  %rdi,%rbx
       │    zend_string_hash_val():
  0.12 │      test %rax,%rax
  0.14 │    ↓ je   78
       │    zend_hash_find_bucket():
  5.63 │13:   or   0xc(%rbx),%eax
  0.28 │      mov  0x10(%rbx),%r12
  0.16 │      cltq
 25.03 │      mov  (%r12,%rax,4),%ebx
  1.98 │      cmp  $0xffffffff,%ebx
  0.56 │    ↓ je   a0
  0.85 │      shl  $0x5,%rbx
  0.50 │      add  %r12,%rbx
 15.20 │      cmp  0x18(%rbx),%rbp
 12.97 │    ↓ jne  68
       │    zend_hash_find():
  1.41 │32:   mov  %rbx,%rax
  0.60 │      pop  %rbx
  0.03 │      pop  %rbp
  1.25 │      pop  %r12
  1.83 │    ← ret
       │      nop
       │    zend_hash_find_bucket():
  0.26 │40:   mov  0x18(%rbx),%rdi
  0.04 │      test %rdi,%rdi
       │    ↓ je   53
       │    zend_string_equal_content():
  0.01 │      mov  0x10(%rbp),%rax
  0.01 │      cmp  %rax,0x10(%rdi)
  5.03 │    ↓ je   90
       │    zend_hash_find_bucket():
  1.06 │53:   mov  0xc(%rbx),%ebx
  0.11 │      cmp  $0xffffffff,%ebx
  0.15 │    ↓ je   a0
  0.33 │      shl  $0x5,%rbx
  0.24 │      add  %r12,%rbx
  1.90 │      cmp  0x18(%rbx),%rbp
  2.69 │    ↑ je   32
  2.00 │68:   mov  0x8(%rbp),%rax
  0.24 │      cmp  %rax,0x10(%rbx)

Is this a known performance issue within the PHP community? I'm seeking suggestions or insights on potential avenues for optimization. Your feedback and suggestions would be greatly appreciated.

PHP Version

master

Operating System

No response

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách đọc zend_hash_find_bucket và các entry point liên quan là zend_hash_find và zend_hash_find_known_hash, sau đó tái hiện profile perf đã được báo cáo trên workload WordPress. Công việc được xem là hoàn tất khi có một thay đổi có cơ sở với mức cải thiện đo được trên workload đó, đồng thời vẫn bảo toàn hành vi tra cứu hash.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
c, php
Lĩnh vực
backend, performance
Loại issue
Tái cấu trúc
Độ khó
5/5
Thời gian dự kiến
Hơn một tuần
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Cần làm rõ
Mức phù hợp với người mới
25/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.