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.

Many rules store a
Vec<String>in their configs for things like ignore lists or JSX tags that should be checked. They are created once (infrom_configuration) and mostly used forVec::contains. There are a few problems with this:Strings are always heap-allocated. We should inline when possible, usingCompactStr.Vec::containsisO(n), and is usually used in a hot path.Vec::containsrequires an&T, meaning there are many cases when rules have an&strand need to allocate a newStringjust to pass it to contains. This is highly wasteful.Vec<String>from aValue.This PR adds
Set<T>, which seeks to make this use case more performant. It's very simple ordered set of unique items backed by aVec. Read the doc comments over the struct definition for a more in-depth rationale.Improvements
Set<T>supportsO(log(n))containment checks at the cost ofO(nlog(n))initialization. This is fine since we create it once and read from it many times.Set<T> where T: AsRef<str>>supports acontains_strmethod that is identical tocontainsbut does not force consumers to allocate new stringsSet<CompactStr>implementsTryFrom<Value>, which DRYs up rule config parsing. This trait is intentionally not implemented forSet<String>to nudge rules towards usingCompactStr.Following PRs will modify existing rules to use
Set<CompactStr>overVec<String>. Since most of these cases are within Jest and VITest rules, I don't expect improvements to appear on benchmarks (rules are skipped when non-applicable, and we have no benchmarks for Jest specs).