Skip to main content
drupalreleases

Use direct release data with your AI assistant.

Learn more

Data Structures

Security covered Under active development 27 sites

This module provides developer tools to create type-safe objects that can replace associative and indexed arrays, offering better performance and memory efficiency. It includes Drush generators and classes for creating typed sequences and performing set operations.

The Data Structures module is a developer utility module. It provides two sets of tools to developers: drush generators for value objects, and classes for typed sequences on the most common base types.

Toolset

  • Drush generator commands provide an easy way to create classes to replace associative and indexed arrays with type safe objects.
  • Data structure classes that instantiate typed sequences using the most common base types.
  • Classes and interfaces for set operations

Background

After bumping into an archived presentation by Crell we conducted a performance evaluation using 1,000,000 instances of data structures with two items, one integer and one string. Averaging 300 iterations of instantiating and executing with the given data structure clearly shows that properly structured objects are faster and more memory efficient than associative arrays.

Sorting Runtime Delta Memory Delta Assoc. Array 4.92563 499.547 MB Object (public) 4.59630 -6.7% 211.928 MB -57.6% Object (readonly) 4.15491 -15.6% 211.928 MB -57.6% Object (private) 6.33438 +28.6% 211.930 MB -57.6% Serialization Runtime Delta Memory Delta Assoc. Array 1.07523 1032.741 MB Object (public) 1.09756 +2.1% 849.519 MB -17.7% Object (readonly) 1.35624 +27.0% 934.409 MB -9.5% Object (private) 1.09738 +2.1% 856.520 MB -17.7%

Efficiency should increase with larger data sets. Typed sequences need to use an indexed array as an internal data structure, so there are not equivalent efficiencies, however they do enforce a reliable type. If Adopt php-ds for data structures were ever adopted, we could use a more efficient data structure and this penalty would likely evaporate.

Usage

Install as you would normally install a contributed Drupal module: composer require drupal/data_structures. See Add a module with Composer for further information.

Drush Commands

  • drush gen data-structures:map: Generates a typed key-value class with public or readonly properties
  • data-structures:typed-sequence: Generates a typed sequence class with utility methods.

Sequences

Classes that can be used or extended in custom code to enforce and manage typed sequences.

  • CallableImmutableSequence
  • FloatImmutableSequence
  • IntImmutableSequence
  • ObjectImmutableSequence
  • StringImmutableSequence

Sets

A Set class and interface, which can be extended to provide typed data, that ensures data elements added to an instance are unique and has methods for performing set operations between instances.

Additional Requirements

Requires Drush version 13 or higher.

Drupal 11 · not 10 PHP >=8.3

Ask your assistant about Data Structures

Check compatibility with your Drupal and PHP version, maintenance and security coverage, from current release data. How it works

Depends on

Dependencies of the latest stable release

No dependencies recorded for this project.

Required by

Tracked projects that depend on this one

No tracked projects depend on this one yet.

Activity

Tracked releases
8
Tracked since
Oct 2023
Latest release
4 days ago
Releases (12 mo)
2 ▲ from 1
Maintenance
Active

Release Timeline

Releases

Version Type Core PHP Release date
1.1.0 Stable 11 PHP >=8.3 Oct 11, 2026
1.1.x-dev Dev 11 PHP >=8.3 Oct 11, 2026
1.0.4 Stable 10–11 Feb 18, 2025
1.0.3 Stable 10–11 PHP >=8.1 Aug 4, 2024
1.0.2 Stable 10 PHP >=8.1 Dec 12, 2023
1.0.1 Stable 10 PHP >=8.1 Dec 12, 2023
1.0.0 Stable 10 PHP >=8.1 Oct 10, 2023
1.0.x-dev Dev 10–11 PHP >=8.3 Oct 10, 2023