Skip to content

array_flip and array_splice stay 3-8x slower than php (hash insert path, cell-typed append) #285

Open

Description

@blacktrs

Problem

Two functions from the #278 sweep stayed slow after the bulk-copy work, because the cost is in shared machinery rather than in the PHP bodies.

  • array_flip: 30 ns per element against php's 8. A profile puts index_find at ~45% and index_build at ~20%: the hash-table insert path.
  • array_splice: 24-36 ns per element against php's 4. The cost is the cell-typed append; the new bulk path works only when the replacement and the input share an element hint, which is not the common case.

Also open from the same sweep: sort of shuffled strings is ~1.7x slower than php (near-sorted input is on par), and in_array over a bare untyped array is ~10x slower because the generic foreach retains and releases every element.

Proposal

Speed up the hash insert path (index probe / build for int and string keys) and give array_splice a bulk path across element hints; then re-measure array_flip, array_unique, array_count_values, which share the insert path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions