fix: speed up splitLimitR long delimiter search#1063
Draft
He-Pin wants to merge 2 commits into
Draft
Conversation
Motivation: std.splitLimitR scanned backward with repeated prefix comparisons, so long delimiters with shared prefixes could degrade to O(N*M) per lookup and show release-regression risk versus 0.6.3. Modification: Add a bounded direct-probe fast path plus reverse-KMP fallback for multi-character right splits, keep the zero-split fast path O(1), and add regression coverage/bench data. Result: New split_limit_r_long_delim JMH case improves from 12.636 ms/op on master and 5.087 ms/op on 0.6.3 to 1.522 ms/op. Guardrail reverse delimiter stays at parity with master.
96c032e to
695f808
Compare
Motivation: std.splitLimitR should avoid unnecessary reverse-KMP setup when a delimiter cannot fit, and the optimized path needs direct coverage for the KMP fallback. Modification: Return the original string before bounded/KMP setup when the delimiter is longer than the input. Add splitLimitR tests for the long-delimiter case, the unbounded maxsplits path, and a case that forces the KMP fallback after naive probes. Result: Preserves splitLimitR semantics while removing avoidable work and pinning the optimized fallback paths with tests.
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.
Motivation
std.splitLimitRcan spend too much time searching for long multi-character delimiters with repeated prefixes. No-match inputs such as a long string ofacharacters with delimiteraaaaaaaaabrepeatedly re-check the same characters.Modification
Result
std.length(std.splitLimitR(importstr "long-a.txt", "aaaaaaaaab", 1))111, slower repeated probing1, reverse-KMP fallbackO(N*M)per lookupO(N+M)per lookupThe PR keeps the observable split result unchanged and improves the pathological search path.
Risks
std.splitLimitR.