Skip to content

Conversation

@brvoisin
Copy link

@brvoisin brvoisin commented Oct 6, 2025

The property TestResponse.forms takes time (about 1.6 seconds) on an HTML response containing a lot of forms (more than 30). For each form, the whole response is parsed. To avoid reparsing all the HTML, I added a cache on the property TestResponse.html that parse the response.

The property `response.forms` takes time (about 1.6 seconds) on an HTML
response containing a lot of froms (more than 30). For each form, the
whole reponse is parsed. To avoid reparsing all the HTML, I added a
cache on the property `Response.html` that parse the response.
@brvoisin
Copy link
Author

brvoisin commented Oct 6, 2025

Hello!

You can reproduce with the attached HTML file 30forms_complex.html and the unit test below.

import time
from unittest import TestCase
from webtest import TestApp


def application(environ, start_response):
    with open("30forms_complex.html", "rb") as f:
        content = f.read()
    headers = [
        ("Content-Type", "text/html; charset=utf8"),
        ("Content-Length", str(len(content))),
    ]
    start_response("200 OK", headers)
    return [content]


class FormsTest(TestCase):
    def test_forms(self):
        app = TestApp(application)
        response = app.get("/")
        start = time.time()
        try:
            response.forms["form30"]
        finally:
            print("Time taken:", time.time() - start)

@gawel gawel merged commit e9095d6 into Pylons:main Oct 6, 2025
14 checks passed
@brvoisin
Copy link
Author

brvoisin commented Oct 8, 2025

Thanks for your reactivity! It was released fast.

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.

2 participants