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

Small performance improvements #773

Merged
merged 3 commits into from
Oct 30, 2024
Merged

Small performance improvements #773

merged 3 commits into from
Oct 30, 2024

Conversation

itamarst
Copy link
Contributor

Fixes #755

Tested with

import time
from twisted.web import server
from twisted.internet.testing import StringTransport
from klein import Klein

app = Klein()

@app.route("/", branch=True)
def main(request):
    return "hello world"

factory = server.Site(app.resource())

start = time.time()
for i in range(20_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"))# + (b"X" * 100))
    assert b"200 OK" in transport.io.getvalue()
print("requests/sec:", 20_000 / (time.time() - start))

@itamarst itamarst requested a review from a team as a code owner September 17, 2024 18:41
@@ -232,6 +231,12 @@ def process(r: object) -> Any:
returns an IRenderable, then render it and let the result of that
bubble back up.
"""
# isinstance() is faster than providedBy(), so this speeds up the
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is... maybe a good idea? Depends on how common this case is.

Copy link

codecov bot commented Sep 17, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.08%. Comparing base (04db6d2) to head (671dd1f).
Report is 4 commits behind head on trunk.

Additional details and impacted files
@@           Coverage Diff           @@
##            trunk     #773   +/-   ##
=======================================
  Coverage   99.08%   99.08%           
=======================================
  Files          48       48           
  Lines        4042     4045    +3     
  Branches      544      545    +1     
=======================================
+ Hits         4005     4008    +3     
  Misses         23       23           
  Partials       14       14           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@glyph
Copy link
Member

glyph commented Oct 30, 2024

@itamarst this looks unobjectionable but I am curious if you could set up codespeed first, so as to get a baseline?

Copy link
Member

@adiroiban adiroiban left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the updates.

It looks like this is waiting in the review queue for a long time.
I think that is best to merge it, witout waiting for other tasks.

We can setup codespeed in a separate PR.

@itamarst itamarst merged commit 47cda03 into trunk Oct 30, 2024
25 checks passed
@itamarst itamarst deleted the 755-performance-round-1 branch October 30, 2024 14:17
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 this pull request may close these issues.

Klein adds significant performance overhead over a twisted.web server
4 participants