Skip to content

perf: reduce allocations in string.gsub and pattern matching - #1

Merged
pixel2175 merged 1 commit into
masterfrom
perf
Nov 29, 2026
Merged

pixel2175 merged 1 commit into
masterfrom
perf

Conversation

@pixel2175

Copy link
Copy Markdown
Owner

The original PR is available here: [#558](yuin#558).

However, it seems that the maintainer is no longer interested in maintaining the repository (it's been over a month without even a review), so I've decided to maintain this fork myself.

This repository was created specifically to support [Merodi](https://github.com/pixel2175/merodi). Therefore, any changes made here will primarily be related to Merodi's requirements.

* build the gsub result once using strings.Builder instead of copying the entire string for each match
* cache compiled patterns in pm
* reuse MatchData across failed match attempts
* remove the unused MatchData return value from recursiveVM
* skip the replacement scanner when the replacement contains no `%`
@pixel2175
pixel2175 merged commit 981c0ff into master Nov 29, 2026
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