Avoid re-compiling rules
Opened this issue · 2 comments
I observed, while looking into #19, that due to the current implementation we're actually re-compiling every rule for every file. Updating the range
in matchIgnoreRule
to be by-reference improves performance on large repositories by a factor of ~3.
I independently noticed the same thing while working on ccbbeee and attempted to improve it, but since performace wasn't my main motivation in that commit I didn't spend much time studying the impact of the change I attempted there.
Looking back at it again with fresh eyes today I suspect I may not have actually fully addressed it: @skeggse's note about passing by reference instead of by value makes me notice that I seem to have made it just ineffectually precompile copies of the default rules, rather than the actual values that end up in the default ruleset:
go-slug/internal/ignorefiles/terraformignore.go
Lines 161 to 186 in 6a7ca7a
A small change that might make it effectual is to refer directly to the array elements by index, rather than working on the copies that the for ... range
is implicitly making:
for i := range defaultExclusions {
err := defaultExclusions[i].compile()
if err != nil {
panic(fmt.Sprintf("invalid default rule %q: %s", r.val, err))
}
}
The default match object includes a slice value covering the same backing array, so I expect that a change like the above would make it effective, but I've not yet tested.