LibWeb: Do not break WebDriver errors into multiple socket writes

Very similar to commit e5877cda61.

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.
This commit is contained in:
Timothy Flynn 2024-09-26 20:57:39 -04:00 committed by Tim Ledbetter
parent e436c31b97
commit 7a15e3ee5c
Notes: github-actions[bot] 2024-09-27 08:48:02 +00:00

View file

@ -330,18 +330,17 @@ ErrorOr<void, Client::WrappedError> Client::send_error_response(Error const& err
JsonObject result; JsonObject result;
result.set("value", move(error_response)); result.set("value", move(error_response));
StringBuilder content_builder; auto content = result.serialized<StringBuilder>();
result.serialize(content_builder);
StringBuilder header_builder; StringBuilder builder;
header_builder.appendff("HTTP/1.1 {} {}\r\n", error.http_status, reason); builder.appendff("HTTP/1.1 {} {}\r\n", error.http_status, reason);
header_builder.append("Cache-Control: no-cache\r\n"sv); builder.append("Cache-Control: no-cache\r\n"sv);
header_builder.append("Content-Type: application/json; charset=utf-8\r\n"sv); builder.append("Content-Type: application/json; charset=utf-8\r\n"sv);
header_builder.appendff("Content-Length: {}\r\n", content_builder.length()); builder.appendff("Content-Length: {}\r\n", content.length());
header_builder.append("\r\n"sv); 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(builder.string_view()));
TRY(m_socket->write_until_depleted(TRY(content_builder.to_byte_buffer())));
log_response(error.http_status); log_response(error.http_status);
return {}; return {};