Message235401
Benchmark on Fedora 21 (Linux 3.18.3, glibc 2.20, Python 3.5 rev 7494f3972726).
Original:
haypo@selma$ ./python -m timeit -s 'import os, selectors; s=selectors.SelectSelector(); r,w=os.pipe(); s.register(r, selectors.EVENT_READ)' 's.modify(r, selectors.EVENT_WRITE); s.modify(r, selectors.EVENT_READ)'
10000 loops, best of 3: 43.7 usec per loop
haypo@selma$ ./python -m timeit -s 'import os, selectors; s=selectors.PollSelector(); r,w=os.pipe(); s.register(r, selectors.EVENT_READ)' 's.modify(r, selectors.EVENT_WRITE); s.modify(r, selectors.EVENT_READ)'
10000 loops, best of 3: 45.1 usec per loop
haypo@selma$ ./python -m timeit -s 'import os, selectors; s=selectors.EpollSelector(); r,w=os.pipe(); s.register(r, selectors.EVENT_READ)' 's.modify(r, selectors.EVENT_WRITE); s.modify(r, selectors.EVENT_READ)'
10000 loops, best of 3: 48.4 usec per loop
Patched:
haypo@selma$ ./python -m timeit -s 'import os, selectors; s=selectors.SelectSelector(); r,w=os.pipe(); s.register(r, selectors.EVENT_READ)' 's.modify(r, selectors.EVENT_WRITE); s.modify(r, selectors.EVENT_READ)'
10000 loops, best of 3: 37.2 usec per loop
haypo@selma$ ./python -m timeit -s 'import os, selectors; s=selectors.PollSelector(); r,w=os.pipe(); s.register(r, selectors.EVENT_READ)' 's.modify(r, selectors.EVENT_WRITE); s.modify(r, selectors.EVENT_READ)'
10000 loops, best of 3: 40.5 usec per loop
haypo@selma$ ./python -m timeit -s 'import os, selectors; s=selectors.EpollSelector(); r,w=os.pipe(); s.register(r, selectors.EVENT_READ)' 's.modify(r, selectors.EVENT_WRITE); s.modify(r, selectors.EVENT_READ)'
10000 loops, best of 3: 39.9 usec per loop
* SelectSelector: 14% faster (-6.5 us)
* PollSelector: 10% faster (-4.6 us)
* EpollSelector: 18% faster (-8.5 us)
--
> _BaseSelectorImpl.modify() still calls unregister() and register().
I chose to factorize code in modify() and only put the specific code in _modify(). The advantage is to pass directly oldkey and key to _modify().
We may even try to keep the selector consistent if _modify() fails. For example, start with unregister, and only register if _modify() succeed.
--
In a previous (local) patch, the default implementation of _modify() was:
self.unregister(fileobj)
return self.register(fileobj, events, data)
And each specialized _modify() started with:
oldkey = self.unregister(fileobj)
key = self.register(fileobj, events, data)
Do you prefer this? |
|
Date |
User |
Action |
Args |
2015-02-04 20:25:57 | vstinner | set | recipients:
+ vstinner, gvanrossum, pitrou, giampaolo.rodola, christian.heimes, meador.inge, neologix, rosslagerwall, python-dev, sbt, felipecruz, yselivanov |
2015-02-04 20:25:57 | vstinner | set | messageid: <1423081557.24.0.833405690983.issue18932@psf.upfronthosting.co.za> |
2015-02-04 20:25:57 | vstinner | link | issue18932 messages |
2015-02-04 20:25:56 | vstinner | create | |
|