tantivy
tantivy copied to clipboard
Speed up searches by removing repeated memsets coming from vec.resize()
Also, reserve exactly the size needed, which is surprisingly needed to get the full speedup of ~5% on a good fraction of the queries.
The memset (accounting for 4% of the CPU cycles) in the range_numeric query is indeed gone with this PR, see flame graphs:
Overall, it makes things a few percent faster on many queries:
Note: I made sure to use the same version of tantivy for the baseline and for this proposed change. The only difference between the two columns is this PR.
It would be possible to have this speedup without using unsafe by never truncating it (as is done in filter_vec_in_place()) and instead passing the number of final elements in the vector back to VecCursor.
I think there is a problem in the benchmark. That code is not used in most of the queries showing an improvements.