wangjiacai666 commented on PR #16544: URL: https://github.com/apache/dubbo/pull/16544#issuecomment-6486382890
Thanks @LI123456mo — that re-run is exactly what I expected, and it confirms the shape of the problem. The gain is not a constant factor, it scales with the number of bits: `BitList#get(i)` is `synchronized` and walks `BitSet#nextSetBit` from the head on every call, so the original loop performs `sum(i)` bitset scans (~N²/2) instead of N. Measured on the same list sizes, single thread, JDK 21: | list | before | after | ratio | |---|---|---|---| | `BitList`, N = 782 (all bits set) | 1.04 ms | 0.04 ms | ~25x | | `BitList`, N = 3125 (all bits set) | 16.3 ms | 0.14 ms | ~113x | | `ArrayList`, N = 3125 | unchanged | unchanged | ~1x | So with the address count you tested, the loop was already a small part of `select()`, which is why you see ~2.3x (13,409 ms → 5,696 ms) rather than ~100x. The ratio grows quickly with N, and it grows as the rest of `select()` gets cheaper. What matters for production is that the old cost is paid on *every* select, so it adds O(N²) work to every call: with ~3000 provider addresses we measured the end-to-end RT of a downstream call drop from ~38 ms to ~14 ms after the same change. The latest commit also applies this fix to `LeastActiveLoadBalance` and `ShortestResponseLoadBalance`, and adds a large-N test that counts `get(int)` calls so this cannot silently regress. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
