Recently, I complete a lib hash_ord which contains OrdMap(avl tree) and HashMap(use avl to resolve Collision Attack). To improve performance, raw pointer is used frequently. However, I found out that, in a balanced binary tree, search operation does not seem to be much faster than insertion.
In C/C++, syntax like ptr = ( int < int ) ? ptr : ptr may not generate any branch, but in Rust, we can only use if ... {} else {}.
I want to know how to make conditional operations like if usize < usize { ptr } else { ptr } run faster except embedding assembly.
Have you fed your code to a PMC-enabled profiler like perf or VTune in order to figure out what is bottlenecking it? Spontaneously, on a binary tree search, I would suspect pipeline stalls caused by mispredictions or cache misses, but it is good to get a clear answer. Moreover, these tools can help you pinpoint your "slow" instructions down to the assembly level (even if they are not 100% accurate at this level, typically 1-4 instructions off, it already tells you where to look).
There is AFAIK no semantic difference between Rust's if-expression and C's ternary operator. So if compilers are able to eliminate the branch in C, they should be able to do so in Rust as well.
A very convenient way to look at the assembly generated by rustc and C compilers is https://godbolt.org/ . You may want to use it in order to figure out if rustc is doing what you want.