3 ms·
I was curious enough about the O(1) claims to look at the source code[1], and I don't think this is true: It's O(1) to add an fd to the set of watched fds It
by userbinator 11y ago
I was curious enough about the O(1) claims to look at the source code[1], and I don't think this is true:
It's O(1) to add an fd to the set of watched fds
It uses a red-black tree to keep track of the set of watched fds associated with each epoll fd, which makes insertion O(log n). However, waiting and notification can be done in O(1).
[1] http://lxr.free-electrons.com/source/fs/eventpoll.c http://lxr.free-electrons.com/source/fs/eventpoll.c
- asveikau 11y agoOK, so I was being a bit fast and loose with my description of insert. What I was going for is it doesn't copy and scan the entire list every time. It's also not too hard to imagine a constant time implementation. The api would allow for it. Whereas poll is broken at the api level. It assumes O(n) at every call and there's no good way to get around it.