Skip to content

Use strcspn instead of regex for fast-skip in clean()#35

Merged
Seldaek merged 1 commit intocomposer:mainfrom
bendavies:perf/string-function-optimization
May 5, 2026
Merged

Use strcspn instead of regex for fast-skip in clean()#35
Seldaek merged 1 commit intocomposer:mainfrom
bendavies:perf/string-function-optimization

Conversation

@bendavies
Copy link
Copy Markdown
Contributor

@bendavies bendavies commented Apr 30, 2026

Hi,

I noticed on our project that composer dump-autoload --classmap-authoritative was suspicious slow. Looking into this showed Composer\ClassMapGenerator\PhpFileCleaner to be slow.

The regex used in clean() to skip up to certain character was the main culprit.

image

Switch from a regex "not in this character set" pattern to strcspn
which does the same job but in C, without the PCRE overhead.
@Seldaek
Copy link
Copy Markdown
Member

Seldaek commented May 5, 2026

That's great, looks like a ~20% improvement here in optimized autoload dumping, thanks!

@Seldaek Seldaek merged commit 56150a3 into composer:main May 5, 2026
14 checks passed
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.

2 participants