[Twisted-Python] Ticket #8244 (old-style decorator)

L. Daniel Burr ldanielburr at me.com
Wed Mar 23 15:10:10 MDT 2016


Hi Glyph,
On March 23, 2016 at 1:39:53 PM, Glyph (glyph at twistedmatrix.com) wrote:


On Mar 23, 2016, at 9:22 AM, L. Daniel Burr <ldanielburr at me.com> wrote:

My concern is that, should these classes be converted into hybrids via the @oldStyle decorator, my service may experience some reduction in the number of requests per second that it handles

If oldStyle converts the classes into hybrids, then it's broken.  Hybrids don't follow the semantics of old-style classes.  So this won't happen.

 I should definitely test the results to see if there *is* a performance regression in my case.

My guess is that this is an insignificant micro-optimization and that pypy has gotten better at optimizing hybrids since that caution was written.  That said, we're really bad at paying attention to speed.twistedmatrix.com and we really need a way to see pre-merge performance metrics rather than just a graph over time.


In the interest of putting my money where my mouth is, I’ve tested a very simple case, where I create a class inheriting from twisted.web.resource.Resource, and a subclass which mixes in “object”:

from twisted.application import internet, service
from twisted.internet import endpoints, reactor
from twisted.web import resource, server


class MyResource(resource.Resource):
    isLeaf = True

    def render_GET(self, request):
        return 'Hello, World!'

class FrankenStyle(MyResource, object):
    pass

print type(MyResource)
print type(FrankenStyle)

application = service.Application(‘test')
root = FrankenStyle()
s = server.Site(root)
ep = endpoints.serverFromString(reactor, 'tcp:8080')
svc = internet.StreamServerEndpointService(ep, s)
svc.setName(‘hybridtest')
svc.setServiceParent(application)

Running siege --benchmark --concurrent=10 --reps=1000 "http://127.0.0.1:8080/“ against the “MyResource” version gets me 5714.29 requests per second across 3 runs.
Running siege --benchmark --concurrent=10 --reps=1000 "http://127.0.0.1:8080/“ against the “FrankenStyle” version gets me an average of 5671.61 requests per second across 3 runs.
So, not a huge difference, overall, and it might not even be visible over a long enough period of time.
Thanks,
Daniel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: </pipermail/twisted-python/attachments/20160323/9c832ea8/attachment-0002.html>


More information about the Twisted-Python mailing list