Farm v2.0 performance improvement #2113
Labels
enhancement
New feature or request
good first issue
Good for newcomers
performance
Performance dependent
v2.0
v2.0 version
Tracking pull request: #2116
Benchmarks of
std
alternativesAlternatives for
String
See https://github.com/fu050409/str-bench
Alternatives for
Vec
See https://github.com/fu050409/vec-bench
Alternatives for
HashMap
See https://github.com/fu050409/hashmaps-bench
Prerequisites
Refactor program
1.
String
The results of the benchmarks show that
EcoString
provides extreme performance on large string cloning, but does not perform as expected on string replacement.ImString
in also provides the same performance asEcoString
on cloning, but performs catastrophically poorly in several other benchmarks.ArcStr
, first mentioned by @ErKeLost, only shows a slight advantage inString
conversions with the standard library. AndCompactString
, which is highly prized by oxlint, while showing amazing performance on small strings, barely wins any of the other benchmarks, and even shows rather poor performance on large strings. For basic string manipulation, it's easy to see that insteadString
offers the best performance and is the most stable implementation.So pure substitution is likely to cause performance problems instead, and we should use a combination of these libraries. Both
EcoString
andCompactString
are fully compatible withString
and each performs very well in specific scenarios, allowing us to use the former in situations where we need to copy large strings, and the latter for storing small strings. Any situation where string operations are needed should be converted to the originalString
, and theto_string
operation has an overhead, but it's very small, an order of magnitude lower than the overhead of a string push operation.EcoString
CompactString
2.
Vec
For benchmarks of
Vec
and its alternatives,SmallVec
outperformsVec
in both large and small data volumes.EcoVec
provides good performance on clones, but performs poorly in anyVec
operation. We should useEcoVec
if the data requires mostClone
operations, and useSmallVec
instead in all other cases.SmallVec
andEcoVec
, and if the results show that the overhead of converting between the two is tolerable compared to theVec
operation, then we can useSmallVec
andEcoVec
interchangeably to improve performance.Vec
toSmallVec
EcoVec
3.
HashMap
It's easy to see from the benchmarks that using
rustc_hash
far outperforms the Rust standard library no matter what the situation, and we should refactor all hash tables torustc_hash
.Tracking PR: refactor(v2): use faster hasher to optimize #1941
4. Check if we have encountered lots of string search, if so, try with SIMD (Need benchmarks)
5. Check if it's OK to use other allocators to optimize performance
The text was updated successfully, but these errors were encountered: