From 7a15e3ee5caa9332f3f6011cc21058e6ceab838c Mon Sep 17 00:00:00 2001 From: Timothy Flynn Date: Thu, 26 Sep 2024 20:57:39 -0400 Subject: [PATCH] LibWeb: Do not break WebDriver errors into multiple socket writes Very similar to commit e5877cda61eb53cd9c1eebbfaf3c35d084b2973c. By sending as much data as we can in a single write, we see a massive performance improvement on WPT tests that hammer WebDriver with errors. On my Linux machine, this reduces the runtime of: /webdriver/tests/classic/perform_actions/invalid.py from 45-60s down to 3-4s. --- .../Libraries/LibWeb/WebDriver/Client.cpp | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/Userland/Libraries/LibWeb/WebDriver/Client.cpp b/Userland/Libraries/LibWeb/WebDriver/Client.cpp index e7de15f4dd3..d18ccd33d31 100644 --- a/Userland/Libraries/LibWeb/WebDriver/Client.cpp +++ b/Userland/Libraries/LibWeb/WebDriver/Client.cpp @@ -330,18 +330,17 @@ ErrorOr Client::send_error_response(Error const& err JsonObject result; result.set("value", move(error_response)); - StringBuilder content_builder; - result.serialize(content_builder); + auto content = result.serialized(); - StringBuilder header_builder; - header_builder.appendff("HTTP/1.1 {} {}\r\n", error.http_status, reason); - header_builder.append("Cache-Control: no-cache\r\n"sv); - header_builder.append("Content-Type: application/json; charset=utf-8\r\n"sv); - header_builder.appendff("Content-Length: {}\r\n", content_builder.length()); - header_builder.append("\r\n"sv); + StringBuilder builder; + builder.appendff("HTTP/1.1 {} {}\r\n", error.http_status, reason); + builder.append("Cache-Control: no-cache\r\n"sv); + builder.append("Content-Type: application/json; charset=utf-8\r\n"sv); + builder.appendff("Content-Length: {}\r\n", content.length()); + builder.append("\r\n"sv); + builder.append(content); - TRY(m_socket->write_until_depleted(TRY(header_builder.to_byte_buffer()))); - TRY(m_socket->write_until_depleted(TRY(content_builder.to_byte_buffer()))); + TRY(m_socket->write_until_depleted(builder.string_view())); log_response(error.http_status); return {};