NeogitOrg / neogit

An interactive and powerful Git interface for Neovim, inspired by Magit
MIT License
4.04k stars 239 forks source link

Path to gitmessages is not expanded before reading the file #163

Closed akinsho closed 3 years ago

akinsho commented 3 years ago

@TimUntersberger thanks for adding in functionality for reading a user's .gitmessages 👍🏾. I just tried committing since this change and hit an error

...acker/start/plenary.nvim/lua/plenary/async_lib/async.lua:14: The coroutine failed with this message: ...e/nvim/site/pack/packer/opt/neog
it/lua/neogit/lib/uv.lua:25: bad argument #1 to 'lines' (~/.gitmessage: No such file or directory)

I 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.

TimUntersberger commented 3 years ago

Should be fixed. Thank you!

akinsho commented 3 years ago

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 🤷🏾

TimUntersberger commented 3 years ago

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.

akinsho commented 3 years ago

@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.

TimUntersberger commented 3 years ago
    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.

akinsho commented 3 years ago

@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.

TimUntersberger commented 3 years ago

@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.

akinsho commented 3 years ago

@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

TimUntersberger commented 3 years ago

and it's much faster

how much faster are we talking?

akinsho commented 3 years ago

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.

neogit-slow-commit

I've got nothing big running at the moment on the mac, really not sure why the large difference in performance

TimUntersberger commented 3 years ago

I tried to reproduce this locally, but my commit buffer takes maybe 300-400ms to open.

TimUntersberger commented 3 years ago

I'll close this issue for now.

akinsho commented 3 years ago

Fair enough. It might be an issue local to that system 🤷🏿