Try to call less circuitmux_find_map_entry()
The circuitmux_find_map_entry()
function is currently taking more than 3% of the CPU on a busy relay. It is literally the second highest after curv25519 crypto stuff (which is expected to be high).
We can't really optimize that function so much but we can try to call it less! For instance, at every single cell we append to a circuit in append_cell_to_circuit_queue()
we call update_circuit_on_cmux()
which calls 4 functions in succession that calls circuitmux_find_map_entry()
:
circuitmux_is_circuit_attached()
circuitmux_attached_circuit_direction()
-
circuitmux_set_num_cells()
and this function can call it again withcircuitmux_make_circuit_inactive()
orcircuitmux_make_circuit_active()
.
This is quite a lot of CPU at each cell especially when we do have many many circuits.