Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Speed up twisted.web, part 1 of N #12133

Closed
itamarst opened this issue Apr 23, 2024 · 5 comments · Fixed by #12149
Closed

Speed up twisted.web, part 1 of N #12133

itamarst opened this issue Apr 23, 2024 · 5 comments · Fixed by #12149
Assignees

Comments

@itamarst
Copy link
Contributor

Going to try do the equivalent of what I did for twisted.web client: fix a bunch of small performance issues that add up. Initial investigation suggests there will be things to fix, e.g. various overhead from deprecated code paths.

Might be a series of issues, will see.

@itamarst itamarst self-assigned this Apr 23, 2024
@itamarst itamarst changed the title Speed up twisted.web Speed up twisted.web, part 1 of N Apr 23, 2024
@itamarst
Copy link
Contributor Author

My benchmark:

import time

from twisted.web import server, static
from twisted.internet.testing import StringTransport

DATA = static.Data(b"This is a result hello hello" * 4, "text/plain")
DATA.getChild = lambda *args, **kwargs: DATA

factory = server.Site(DATA)

start = time.time()
for i in range(100_000):
    transport = StringTransport()
    protocol = factory.buildProtocol(None)
    protocol.makeConnection(transport)
    protocol.dataReceived(b"""\
    GET / HTTP/1.1
    Host: example.com
    User-Agent: XXX
    Time: XXXX
    Content-Length: 0

    """.replace(b"\n", b"\r\n"))
    assert b"200 OK" in transport.io.getvalue()
print("requests/sec:", 100_000 / (time.time() - start))

Best run via something like hyperfine.

@glyph
Copy link
Member

glyph commented Apr 23, 2024

Best run via something like hyperfine.

This seems like it would be a nice, simple thing to get started with https://codspeed.io and perhaps finally replace the long-lost speed.twistedmatrix.com?

@itamarst
Copy link
Contributor Author

Might do a follow-up for that, I guess.

@glyph
Copy link
Member

glyph commented Apr 23, 2024

Might do a follow-up for that, I guess.

I have no concept of how difficult it would be, so I won't insist on it, but having something in CI first to set performance budgets so you can see progress over time would be a nice way to measure the impact of repeated changes

@itamarst
Copy link
Contributor Author

itamarst commented May 1, 2024

OK, gonna do codspeed issue/PR next.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants