This repository has been archived by the owner on Sep 13, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Avoid quadratic complexity in poll()
streaming::pipeline::server::Dispatch::poll() called poll on every single entry of self.in_flight, and then removed at most one element from that structure (via pop_front()). So, the complexity is O(n^2) in the size of self.in_flight. Calling poll() on the first entry of self.in_flight should be sufficient, the other entries can be handled later. This reduces the complexity to O(n). This behavior can be significant if self.in_flight gets large, which can happen if input is read very quickly. I triggered it with a simple echo server fed from a unix domain socket: $ time yes | head -n 1000 | nc -U -N /tmp/sock >/dev/null real 0m0.051s $ time yes | head -n 10000 | nc -U -N /tmp/sock >/dev/null real 0m3.534s $ time yes | head -n 20000 | nc -U -N /tmp/sock >/dev/null real 0m13.883s With this patch, the runtime becomes linear and much faster: $ time yes | head -n 1000 | nc -U -N /tmp/sock >/dev/null real 0m0.010s $ time yes | head -n 10000 | nc -U -N /tmp/sock >/dev/null real 0m0.049s $ time yes | head -n 20000 | nc -U -N /tmp/sock >/dev/null real 0m0.084s $ time yes | head -n 100000 | nc -U -N /tmp/sock >/dev/null real 0m0.405s $ time yes | head -n 1000000 | nc -U -N /tmp/sock >/dev/null real 0m3.738s
- Loading branch information