# HG changeset patch # User Kim Alvefur # Date 1626395312 -7200 # Node ID 917eca7be82b6567ecfba850e98d48f8d4dae361 # Parent 1573099157c90561353b55784daf6044252ac03c net.server_epoll: Optionally let go of buffers Reusing an already existing buffer table would reduce garbage, but keeping it while idle is a waste. diff -r 1573099157c9 -r 917eca7be82b net/server_epoll.lua --- a/net/server_epoll.lua Fri Jul 16 01:21:05 2021 +0200 +++ b/net/server_epoll.lua Fri Jul 16 02:28:32 2021 +0200 @@ -86,6 +86,9 @@ -- Whether to let the Nagle algorithm stay enabled nagle = true; + + -- Reuse write buffer tables + keep_buffers = true; }}; local cfg = default_config.__index; @@ -472,17 +475,25 @@ local ok, err, partial = self.conn:send(data); if ok then self:set(nil, false); - for i = #buffer, 1, -1 do - buffer[i] = nil; + if cfg.keep_buffers then + for i = #buffer, 1, -1 do + buffer[i] = nil; + end + else + self.writebuffer = nil; end self:setwritetimeout(false); self:ondrain(); -- Be aware of writes in ondrain return ok; elseif partial then self:debug("Sent %d out of %d buffered bytes", partial, #data); - buffer[1] = data:sub(partial+1); - for i = #buffer, 2, -1 do - buffer[i] = nil; + if cfg.keep_buffers then + buffer[1] = data:sub(partial+1); + for i = #buffer, 2, -1 do + buffer[i] = nil; + end + else + data.writebuffer = { data:sub(partial+1) }; end self:set(nil, true); self:setwritetimeout(); @@ -509,6 +520,7 @@ if buffer then t_insert(buffer, data); else + self:noise("Allocating buffer!") self.writebuffer = { data }; end if not self._write_lock then