]> git.ipfire.org Git - thirdparty/tornado.git/commit
_Timeout.__lt__ speedup 1729/head
authorDmitry Volodin <dv@nocproject.org>
Wed, 25 May 2016 22:17:38 +0000 (02:17 +0400)
committerDmitry Volodin <dv@nocproject.org>
Wed, 25 May 2016 22:17:38 +0000 (02:17 +0400)
commitfb639dc79e1118e453a2df43e11b719753e1aa69
treeab78e5b314782cd3157fd7f256e1f28ea85138b5
parenta97ec9569b1995d8aa3da0a7f499510bffc006a3
_Timeout.__lt__ speedup

One of our services uses a lots of callbacks (~15k per IOLoop) and performs massive network IO. During profiling we'd found that significant amount of time consumed in the _Timeout.__lt__ method. Current implementation constantly builds two tuples per comparison. Proposed one pre-builds tuple
during _Timeout creation. Its about ~40% faster.

In [1]: from tornado.ioloop import _Timeout, IOLoop
In [2]: io = IOLoop.current()
In [3]: t0 = _Timeout(io.time(), None, io)
In [4]: t1 = _Timeout(io.time(), None, io)
In [5]: %timeit t0 < t1
1000000 loops, best of 3: 587 ns per loop
In [6]: %timeit t0 < t1
1000000 loops, best of 3: 336 ns per loop
tornado/ioloop.py