mirror of
https://github.com/scylladb/scylladb.git
synced 2026-05-28 10:41:12 +00:00
send_to_live_endpoints() computes sets of endpoints to which we send mutations - remote endpoints (where we send to each set as a whole, using forwarding), and local endpoints, where we send directly. To make handling regular, each local endpoint is treated as its own set. Thus, each local endpoint and each datacenter receive one RPC call (or local call if the coordinator is also a replica). These sets are maintained a std::unordered_map (for remote endpoints) and a vector with the same value_type as the map (for local endpoints). The key part of the vector payload is initialized to the empty string. We simplify this by noting that the datacenter name is never used after this computation, so the vector can hold just the replica sets, without the fake datacenter name. The downstream variable `all` is adjusted to point just to the replica set as well. As a reward for our efforts, the vector's contents becomes nothrow move constructible (no string), and we can convert it to a small_vector, which reduces allocations in the common case of RF<=3. The reduction in allocations is visible in perf-simple-query --write results: ``` before 165080.62 tps ( 60.3 allocs/op, 16.0 logallocs/op, 14.2 tasks/op, 53438 insns/op, 26705 cycles/op, 0 errors) after 164513.83 tps ( 59.3 allocs/op, 16.0 logallocs/op, 14.2 tasks/op, 53347 insns/op, 26761 cycles/op, 0 errors) ``` The instruction count reduction is a not very impressive 70/op: before ``` instructions_per_op: mean= 53412.22 standard-deviation=32.12 median= 53420.53 median-absolute-deviation=20.32 maximum=53462.23 minimum=53290.06 ``` after ``` instructions_per_op: mean= 53350.32 standard-deviation=32.38 median= 53353.71 median-absolute-deviation=13.60 maximum=53415.20 minimum=53222.24 ``` Perhaps the extra code from small_vector defeated some inlining, which negated some of the gain from the reduced allocations. Perhaps a build with full profiling will gain it back (my builds were without pgo). Closes scylladb/scylladb#25270