Skip to content

Manticore\Ds: typed string array on one byte buffer #271

Open

Description

@blacktrs

Problem

Manticore\Ds has fixed-width numeric and bit arrays, but no array of strings. A SplFixedArray or Vec of strings stores one cell per element and one refcounted string per cell, so a large list of short strings (tokens, identifiers, path segments) pays a header, a refcount and a pointer per element.

Proposal

A typed string array: all bytes in one contiguous buffer plus an offsets array, so N strings cost two allocations instead of N+1. Open design questions, to settle before code:

  • Read semantics: $a[$i] materialises a new string (copy) or returns a borrowed view; ownership rules from docs/design/memory-abi.md apply.
  • Write semantics: replacing an element with a longer string (compaction, gap buffer, or append-only with periodic repack).
  • Growth, push / pop, indexOf / equals, sort.
  • Memory-ABI: a new buffer kind in MemoryAbi (layout has one owner), and whether an ABI bump is needed.

Measure first: RSS and iteration time of 1M short strings in array<int,string> / SplFixedArray against a prototype, before committing to the layout.

Acceptance criteria

  • A measured RSS and time win over array<int,string> on a 1M-string corpus, reported in the PR.
  • Cases for the Zend-visible semantics (offset rules, exceptions, var_dump, serialize) as for the other Ds arrays.
  • docs/ds.md covers the class.

Split out of #101 (part 8).

Activity

  1. added
    enhancement
    on Oct 16, 2026
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