FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Improve parser and loader performance by GrahamCampbell · Pull Request #600 · vlucas/phpdotenv · GitHub

Improve parser and loader performance - #600

Merged
GrahamCampbell merged 8 commits into
masterfrom
parser-performance
Aug 23, 2026
Merged

Improve parser and loader performance#600
GrahamCampbell merged 8 commits into
masterfrom
parser-performance

Conversation

Copy link
Copy Markdown
Collaborator

This addresses the slowdown reported in #549. The parser and loader accumulated their results with array_merge inside array_reduce, which made loading O(n²) in the number of entries; both now append to a local array instead. Values that are plain literals, or single or double quoted literals containing no escapes, variables or nested quotes, now skip the token state machine entirely, and a few internal call sites avoid unnecessary closure and option allocations. Loading a 2,000 line file is around 4 times faster on PHP 8.4 and 3.6 times faster on PHP 7.4, scaling is now linear, and behaviour was verified unchanged against the previous implementation across PHP 7.2 to 8.5. The one visible fix is that names consisting only of digits now keep their keys in the array returned by load and parse instead of being renumbered by array_merge, which is covered by a new test.

GrahamCampbell merged commit c86b8f0 into master Aug 23, 2026
38 checks passed
GrahamCampbell deleted the parser-performance branch August 24, 2026 17:49
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant


Back | FazBrowse Home | New Git URL