CircMgr: lower latency by keeping a collection of mostly-built (2-hop) circuits
One source of latency when connecting to onion services (and to unexpected exits) is the time it takes to build a 3-hop circuit to a chosen target relay.
Long ago, in C Tor, we would "cannibalize" unused 3-hop circuits and extend them to a 4th hop for our chosen purpose. This strategy led to additional latency when using those circuits for traffic, since each hop means a longer RTT. It also had a tendency to throw off some of our network latency and RTT calculations (IIUC).
A better approach would be for the CircMgr
to preemptively build a small pool of incomplete 2-hop circuits, and keep them around until we need a 3-hop circuit urgently. When that happens, the CircMgr
could try extending one of those circuits to the chosen third hop.
@mikeperry @dgoulet Do you foresee any problem with this approach?