Skip to content

Optimize rpc msg parse loop#1394

Merged
mfussenegger merged 1 commit intomasterfrom
optimize-rpc
Dec 14, 2024
Merged

Optimize rpc msg parse loop#1394
mfussenegger merged 1 commit intomasterfrom
optimize-rpc

Conversation

@mfussenegger
Copy link
Owner

@mfussenegger mfussenegger commented Dec 8, 2024

With a script like:

local num_bodies = 0
local function handle_body(_)
  num_bodies = num_bodies + 1
end
local function on_eof()
end
local parse_loop = require("dap.rpc").create_read_loop(handle_body, on_eof)

local payload = {
  seq = 1,
  type = "event",
  body = {
    foo = "bar"
  }
}
local msg = require("dap.rpc").msg_with_content_length(vim.json.encode(payload))

local pipes = vim.uv.pipe()

local stdin = assert(vim.uv.new_pipe())
local stdout = assert(vim.uv.new_pipe())
stdin:open(pipes.write)
stdout:open(pipes.read)
local iterations = 50000
local start = vim.uv.hrtime()
for i = 1, iterations do
  stdin:write(msg)
end
stdin:write("", function()
  stdin:close()
end)
stdout:read_start(parse_loop)

vim.wait(5000, function() return num_bodies == iterations end)
local duration = vim.uv.hrtime() - start
vim.print({ duration = duration * 0.000001, iterations = num_bodies })

Before: 130.322467
After: 74.878325

@mfussenegger mfussenegger marked this pull request as ready for review December 8, 2024 17:01
mfussenegger added a commit to mfussenegger/neovim that referenced this pull request Dec 8, 2024
Avoids some table allocations.
In a quick test over 50000 iterations it reduces the time from 130ms to
74 ms

For the test setup details see:

mfussenegger/nvim-dap#1394 (comment)
mfussenegger added a commit to mfussenegger/neovim that referenced this pull request Dec 8, 2024
Avoids some table allocations.
In a quick test over 50000 iterations it reduces the time from 130ms to
74 ms

For the test setup details see:

mfussenegger/nvim-dap#1394 (comment)
@mfussenegger mfussenegger force-pushed the optimize-rpc branch 2 times, most recently from f3d9724 to 8075f10 Compare December 8, 2024 21:22
mfussenegger added a commit to mfussenegger/neovim that referenced this pull request Dec 8, 2024
Avoids some table allocations.
In a quick test over 50000 iterations it reduces the time from 130ms to
74 ms

For the test setup details see:

mfussenegger/nvim-dap#1394 (comment)
@mfussenegger mfussenegger merged commit 567da83 into master Dec 14, 2024
4 checks passed
@mfussenegger mfussenegger deleted the optimize-rpc branch December 14, 2024 12:16
mfussenegger added a commit to mfussenegger/neovim that referenced this pull request Dec 16, 2024
Avoids some table allocations.
In a quick test over 50000 iterations it reduces the time from 130ms to
74 ms

For the test setup details see:

mfussenegger/nvim-dap#1394 (comment)
mfussenegger added a commit to mfussenegger/neovim that referenced this pull request Dec 31, 2024
Avoids some table allocations.
In a quick test over 50000 iterations it reduces the time from 130ms to
74 ms

For the test setup details see:

mfussenegger/nvim-dap#1394 (comment)
mfussenegger added a commit to mfussenegger/neovim that referenced this pull request Mar 1, 2025
Avoids some table allocations.
In a quick test over 50000 iterations it reduces the time from 130ms to
74 ms

For the test setup details see:

mfussenegger/nvim-dap#1394 (comment)
lewis6991 pushed a commit to lewis6991/neovim that referenced this pull request Mar 1, 2025
Avoids some table allocations.
In a quick test over 50000 iterations it reduces the time from 130ms to
74 ms

For the test setup details see:

mfussenegger/nvim-dap#1394 (comment)
lewis6991 pushed a commit to lewis6991/neovim that referenced this pull request Mar 2, 2025
Avoids some table allocations.
In a quick test over 50000 iterations it reduces the time from 130ms to
74 ms

For the test setup details see:

mfussenegger/nvim-dap#1394 (comment)
lewis6991 pushed a commit to lewis6991/neovim that referenced this pull request Mar 31, 2025
Avoids some table allocations.
In a quick test over 50000 iterations it reduces the time from 130ms to
74 ms

For the test setup details see:

mfussenegger/nvim-dap#1394 (comment)
msaher pushed a commit to msaher/neovim that referenced this pull request Apr 4, 2025
Avoids some table allocations.
In a quick test over 50000 iterations it reduces the time from 130ms to
74 ms

For the test setup details see:

mfussenegger/nvim-dap#1394 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant