perf: optimize hot paths with string comparisons and reduced allocations#19
Draft
Koan-Bot wants to merge 1 commit intocern-mig:masterfrom
Draft
perf: optimize hot paths with string comparisons and reduced allocations#19Koan-Bot wants to merge 1 commit intocern-mig:masterfrom
Koan-Bot wants to merge 1 commit intocern-mig:masterfrom
Conversation
Replace regex with string equality checks in high-frequency code paths:
- _special_getdir: use 'ne' instead of regex for . and .. filtering
- count(): eliminate intermediate list allocation, filter and count in one pass
- get()/add_data(): cache $self->{type}{$name} in local variable, replace
regex dispatch with eq comparisons
- _hash2string/_string2hash: add index() early bailout before s///g
(most hash keys/values don't contain special chars)
- _purge_dir: use index() instead of regex for dot detection
- purge option validation: use eq instead of regex
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Replace regex with string equality checks (
eq) in high-frequency code paths, and eliminate unnecessary intermediate allocations.Changes
_special_getdir(Queue.pm): Usenestring comparison instead of regex/^\.\.?$/for filtering.and..entries — this function is called on everyfirst()/next()/count()/purge()operationcount()(Normal.pm, Simple.pm): Eliminate intermediate@listallocation — filter and count in a single pass instead of two loopsget()(Normal.pm): Cache$self->{type}{$name}in a local$typevariable to avoid repeated hash lookups; replace regex dispatch (=~ /^(binary|string)$/) witheqcomparisons_add_data()(Normal.pm): Same local variable caching andeqdispatch_hash2string()/_string2hash()(Normal.pm): Addindex()early bailout befores///gsubstitutions — most hash keys/values don't contain special chars, so the substitution is typically a no-op_purge_dir()(Simple.pm): Useindex($_, ".") >= 0instead of regex/\./purge()option validation (Normal.pm, Simple.pm): Useeqinstead of regex for matching"maxtemp"/"maxlock"Rationale
Perl
eqis ~3-5x faster than simple regex for string matching. Theindex()early bailout avoids the overhead of regex substitution when there's nothing to substitute (the common case for table data). Thecount()single-pass optimization eliminates an intermediate array allocation that was only used to iterate immediately after.All changes are behavior-preserving. 237 tests pass.
🤖 Generated with Claude Code