[bruteforce] Fix bruteforce removePoint.#473
Conversation
|
@ttsugriy |
|
sounds good, @yurymalkov. Btw, unrelated to this change - have you considered using clangformat? Current formatting is somewhat inconsistent and makes reading code a bit harder. Also, if perf is important, I'd recommend considering moving away from interfaces to templates. Using interfaces for distance calculation and other strategy hooks prevents inlining, which even on its own adds overhead and branch mispredictions, but more importantly it prevents all useful compiler optimizations that rely on inlining. |
|
Hi @ttsugriy, As for interfaces/function pointers/templates I think I've tested inlining the distance computation manually long time ago and, as far as I recall, there was little if any penalty even for small dimensionalities. There is also a problem that there are several distance implementations depending on the vector length, if those are added as templates, I think the compile time will probably blow up. |
your call :)
This is super surprising since this overhead matters a lot even for much less hot code paths than distance computation. The only explanation for such results I can come up with is that the testing was performed using some terrible compiler, maybe visual studio?
Adding templates would most definitely add some compile time overhead, but its cost is O(1) in terms of number of possible implementations - it's only O(N) in terms of the number of implementations actually used during compilation, which is likely to be just 1. In any case, I trust your judgement :) |
|
Got it! I can check if it affects the performance now. |
|
@ttsugriy for formatting I used https://github.com/cpplint/cpplint. Probably I missed some parts of the code. |
Previous implementation was not thread-safe - unlike
addPointit didn't acquire an index lock.While at it, this change also switches to
.find()for cur_c lookups, so that followingerasewouldn't have to perform another lookup.P.S.: I don't see how
addPointis thread-safe as well, since write to data_ is performed outside of critical section, but oh well...