Closed akinsho closed 3 years ago
Should be fixed. Thank you!
Just tested it out and seems to have fixed the issue 👍🏾. Thanks 💯
PS: this is definitely an optimisation for the future but it seems to be kind of slow to open the commit buffer now, it takes about 2-3 seconds before it appears on my end 🤷🏾
PS: this is definitely an optimisation for the future but it seems to be kind of slow to open the commit buffer now, it takes about 2-3 seconds before it appears on my end 🤷🏾
This only happens when you have a commit message template.
@TimUntersberger I figured as much but I'm still surprised that the whole process takes that long, especially with libuv
especially versus using Fugitive which is viml and completely synchronous. I was wondering if there is something particularly slow happening. I know where are some gotchas with reading files in lua and some mechanisms being surprisingly slow, not that I know a great deal about it specifically.
local msg_template_path = cli.config.get("commit.template").call_sync()[1]
if msg_template_path then
local msg_template = uv_utils.read_file_sync(vim.fn.glob(msg_template_path))
for _, line in pairs(msg_template) do
table.insert(output, line)
end
table.insert(output, "")
end
That is the code that is reponsible for the slowness. I don't really know what could be the reason.
@TimUntersberger I haven't tried this but did a bit of looking around re. lua and reading files and found a lot of references to using file:read("*all")
i.e. reading out the whole file and then iterating it with something like contents:gmatch("\n")
This link from the lua book seems to indicate that the performance of reading a file all at once is better than doing it line by line.
Usually, in Lua, it is much faster to read a file as a whole than to read it line by line.
Haven't tried this, but tbh looking at a few other examples mentioned in the lua book testing (on pentiums 🤣) the speed of io.lines
seems to be slower but should still be way faster on the hardware I'm on, assuming it is the bottle neck could just as easily be the git call to get the template dir or something else.
@akinsho can you paste your custom git message? I'll try to profile this to see what causes the slowness.
Edit:
Also lets reopen the issue for now.
@TimUntersberger I'm using this on my personal machine atm, and it's much faster, my work machine runs macOS whereas my personal machine runs Linux 🤷🏾♂️. My gitmessage
file is here on github
and it's much faster
how much faster are we talking?
Wow very strange I thought I replied to this last night but can't see my response 🤕 . Anyway on my Linux machine it takes less than a second whereas on the mac it's closer to 2 seconds. The pause is the wait after the commit popup disappears.
I've got nothing big running at the moment on the mac, really not sure why the large difference in performance
I tried to reproduce this locally, but my commit buffer takes maybe 300-400ms to open.
I'll close this issue for now.
Fair enough. It might be an issue local to that system 🤷🏿
@TimUntersberger thanks for adding in functionality for reading a user's
.gitmessages
👍🏾. I just tried committing since this change and hit an errorI found that I'm able to fix this error by changing the path inside my gitconfig to specify the path to the gitmessages as
<full-path>/.gitmessages
, so I think the issue is that before trying to read the gitmessages file the path needs to be expanded.