Issue Task Resolved

#110990Reduce trimExplode processing and allocations

Wouter Wolters 10/09/26, 16:38 updated 10/21/26, 11:35

Description

Unlimited calls removing empty values filter the exploded array,
reindex it and then trim the retained values in a second pass. Calls
retaining empty values also split the entire string before folding the
tail to enforce a positive limit.

Trim and collect nonempty values in one loop for unlimited calls. Use
explode’s native positive limit when empty values are retained,
avoiding the full split and subsequent tail slicing and joining.

Preserve negative-limit handling and positive limits removing empty
values. Empty values must be filtered before folding the tail, whose
internal whitespace must remain intact.

PHP 8.5 benchmarks with OPCache enabled show 28-37% less runtime for
padded lists removing empty values. A 100,000-value mixed list uses 30%
less peak memory. Splitting 1,000 values with a limit of two is 36
times faster and uses 76% less peak memory. These are isolated method
measurements, not application-wide performance claims.

Add coverage for empty input, trim whitespace, form feed and zero.

Reviews 1

History 18

  1. Wouter Wolters commented and changed status Under Review Resolved done 0 % 100 % <span data-processor="relativetime" data-value="2026-10-21T11:35:13+00:00" > 10/21/26, 11:35 </span>

    Applied in changeset commit:308b8fd6d89df7b1d50b7ebcb55e63f37c57855b.