aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
authorKim Alvefur <zash@zash.se>2021-07-08 18:21:59 +0200
committerKim Alvefur <zash@zash.se>2021-07-08 18:21:59 +0200
commit3faf5009d98cc967da200ab0af351078347fb1fe (patch)
tree845123fa613ea1f0a27c878e63405cb14b548190 /net
parentb40b79873c9fd79c5fa0bfc1533619a384b26e83 (diff)
downloadprosody-3faf5009d98cc967da200ab0af351078347fb1fe.tar.gz
prosody-3faf5009d98cc967da200ab0af351078347fb1fe.zip
net.http: Send entire HTTP request header as one write
When opportunistic writes are enabled this reduces the number of syscalls and TCP packets sent on the wire. Experiments with TCP Fast Open made this even more obvious. That table trick probably wasn't as efficient. Lua generates bytecode for a table with zero array slots and space for two entries in the hash part, plus code to set [2] and [4]. I didn't verify but I suspect it would have had to resize the table when setting [1] and [3], although probably only once. Concatenating the strings directly in Lua is easier to read and involves no extra table or function call.
Diffstat (limited to 'net')
-rw-r--r--net/http.lua8
1 files changed, 3 insertions, 5 deletions
diff --git a/net/http.lua b/net/http.lua
index 3481389a..a13c3942 100644
--- a/net/http.lua
+++ b/net/http.lua
@@ -164,13 +164,11 @@ function listener.onconnect(conn)
t_insert(request_line, 4, "?"..req.query);
end
- conn:write(t_concat(request_line));
- local t = { [2] = ": ", [4] = "\r\n" };
for k, v in pairs(req.headers) do
- t[1], t[3] = k, v;
- conn:write(t_concat(t));
+ t_insert(request_line, k .. ": " .. v .. "\r\n");
end
- conn:write("\r\n");
+ t_insert(request_line, "\r\n")
+ conn:write(t_concat(request_line));
if req.body then
conn:write(req.body);