Skip to content

Commit 69f9876

Browse files
committed
perf: sendfile on linux
1 parent 8342463 commit 69f9876

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

lua/fzf-lua/rpc.lua

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
local uv = vim.uv or vim.loop
33

44
local _is_win = vim.fn.has("win32") == 1 or vim.fn.has("win64") == 1
5+
local _is_linux = vim.fn.has("linux") == 1
56

67
if vim.v.servername and #vim.v.servername > 0 then
78
pcall(vim.fn.serverstop, vim.v.servername)
@@ -34,18 +35,27 @@ local function server_listen(server_socket, server_socket_path)
3435
if tmpdir and #tmpdir > 0 then uv.fs_rmdir(tmpdir) end
3536
end
3637

38+
local finish = function()
39+
uv.close(receive_socket)
40+
uv.close(server_socket)
41+
-- on windows: ci fail when use uv.stop()
42+
-- on linux: zero event can freeze
43+
-- https://github.com/ibhagwan/fzf-lua/pull/1955#issuecomment-2785474217
44+
-- uv.stop()
45+
os.exit(0)
46+
end
47+
48+
if _is_linux then
49+
while true do
50+
local len = uv.fs_sendfile(1, receive_socket:fileno(), 0, 1024 * 1024)
51+
local eof = len == 0
52+
if eof then finish() end
53+
end
54+
end
55+
3756
receive_socket:read_start(function(err, data)
3857
assert(not err)
39-
if not data then
40-
uv.close(receive_socket)
41-
uv.close(server_socket)
42-
-- on windows: ci fail when use uv.stop()
43-
-- on linux: zero event can freeze
44-
-- https://github.com/ibhagwan/fzf-lua/pull/1955#issuecomment-2785474217
45-
-- uv.stop()
46-
os.exit(0)
47-
return
48-
end
58+
if not data then finish() end
4959
io.write(data)
5060
end)
5161
end)

0 commit comments

Comments
 (0)