tantivy icon indicating copy to clipboard operation
tantivy copied to clipboard

Speed up searches by removing repeated memsets coming from vec.resize()

Open RaphaelMarinier opened this issue 1 year ago • 1 comments

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: baseline range_numeric reserve_exact and set_len range_numeric

Overall, it makes things a few percent faster on many queries: tantivy reserve_exact and set_len vs baseline

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.

RaphaelMarinier avatar Mar 12 '24 16:03 RaphaelMarinier

I think there is a problem in the benchmark. That code is not used in most of the queries showing an improvements.

fulmicoton avatar Mar 13 '24 00:03 fulmicoton