Repository navigation
filter: speed up large --include-from lists of directories - fixes #9014 - #10028
Conversation
ncw
left a comment
There was a problem hiding this comment.
This is a great fix - thank you :-)
The first line of the commit message goes into the changelog, so something users will recognise, like filter: speed up large --include-from lists of directories - fixes #9014, would be a little clearer.
I note that --ignore-case rules still use the linear scan. Can we deal with that in this PR too? Otherwise we'll have an awkward thing to explain to Windows users!
| func (rs *rules) include(remote string) bool { | ||
| if len(rs.byDirectory) != 0 { | ||
| directory, _, _ := strings.Cut(remote, "/") | ||
| // The syntax package normalizes invalid UTF-8 in literals. Keep the |
There was a problem hiding this comment.
As far as I can tell syntax.Parse rejects invalid UTF-8. The real reason for the fallback is that the regexp matcher decodes an invalid byte as U+FFFD, so a literal U+FFFD could match it. Could you reword the comment to say that?
2c14143 to
345fb1b
Compare
ncw
left a comment
There was a problem hiding this comment.
Thanks for the fixups - this looks great now :-)
What does this change do?
Speed up large lists of anchored directory filter rules, including
--ignore-case, while preserving first-match precedence.At 64 compiled rules, literal first-directory prefixes are indexed. Case-sensitive and case-insensitive rules have separate buckets; insensitive keys use Unicode simple folding consistent with Go's regexp matcher, including Kelvin sign, long s, and Greek sigma equivalents. Matching merges the exact bucket, folded bucket, and fallback rules in original order before evaluating the original regexps.
Small rule sets and expressions without a provable literal directory prefix retain the linear scan. Invalid UTF-8 in the first path component also uses the linear scan: regexp decodes invalid bytes as U+FFFD, which can match a literal U+FFFD even when a byte-based bucket lookup would miss it.
AddConfigcopies mutable rule storage and index buckets so appending rules to a copied configuration cannot corrupt the original filter's index. Other configuration fields retain their existing shallow-copy behavior.Linked issue
Fixes #9014
Changes following review
filter: speed up large --include-from lists of directories - fixes #9014.--ignore-casedirectory rules, with Unicode equivalence and mixed case-sensitive/insensitive precedence tests.Validation
RCLONE_CONFIG=/notfound go test -race ./fs/filter -count=1golangci-lint run ./fs/filter(v2.14.0): 0 issuesmake quicktest: 177 packages passed, with the freshly built rclone and flock on PATH and Docker available.On Apple M1 Pro / Go 1.26, the same 100,000-directory ignore-case benchmark was run against the previous PR implementation and the revised code (
-benchtime=500ms -count=2). Last-rule matches changed from 98–178 ms to 196–205 ns; misses changed from 90–96 ms to 341–498 ns. First-rule matches were already fast and changed from 134–143 ns to 296–351 ns. These are local filter-decision measurements, excluding remote I/O and rule loading, rather than end-to-end transfer results.The index adds construction cost: at 10,000 ignore-case input patterns, cumulative allocation per
NewFilterwas approximately 267 MB versus 223 MB in the previous PR implementation. These are allocated bytes, not resident memory. Rule sets sharing one first directory or dominated by fallback expressions can still require a near-linear scan.For new or changed backends
Not applicable; no backend changes.
Checklist
test_allpasses for this backend and if submitting a new backend can provide a test account for the integration tester - see CONTRIBUTING.md.Checklist notes: the indexing approach and ignore-case extension are discussed in this PR's review. User documentation and backend integration tests are not applicable to this internal optimization. AI assistance was used for implementation and validation.