# HG changeset patch # User Kim Alvefur # Date 1577510338 -3600 # Node ID cfeb0077c9e97144a862c606c77589a3acc826d0 # Parent 962efe23975d6db6f24d5d87ba90f5c843a83225 net.server_epoll: Avoid concatenating buffer with single item Saves creating a string that'll be identical to buffer[1] anyways, as well as a C function call. Depending on Lua version and length of the string, this could be reusing an interned string, but a longer one would probably be duplicated for no reason. Having exactly one item in the buffer seems like it would be fairly common, but I have not done an extensive study. If opportunistic writes are enabled then it will be even more likely. This special case could be optimized like this in table.concat but it does not look like it is. diff -r 962efe23975d -r cfeb0077c9e9 net/server_epoll.lua --- a/net/server_epoll.lua Tue Dec 24 08:42:53 2019 +0000 +++ b/net/server_epoll.lua Sat Dec 28 06:18:58 2019 +0100 @@ -408,7 +408,7 @@ self:onconnect(); if not self.conn then return; end -- could have been closed in onconnect local buffer = self.writebuffer; - local data = t_concat(buffer); + local data = #buffer == 1 and buffer[1] or t_concat(buffer); local ok, err, partial = self.conn:send(data); if ok then self:set(nil, false);