Open Aumnescio opened 1 year ago
Hey, could you please update to the latest version on main
and see if the startup still remains as large? On my hardware, Neorg used to take 80 milliseconds to load on startup with all the modules except the integration modules for truezen or nvim-cmp. After the latest fixes Neorg now starts up in 28ms, which is a large decrease. Metrics from different hardware configurations is something useful to have :)
The Neorg package itself seems to load relatively fast. I'm getting about 20 to 50ms (up to 50'ish if including the treesitter dependency) in non-norg files, when not even attemption to lazy-load Neorg.
But in .norg
files, something silly is happening. My startuptime is still 830+ms with the latest main
, while it's around 500ms on 4.4.1
. The norg
file I have is only 700 lines long. Even in an extremely minimal norg file, the startuptime is 765ms.
I've confirmed that some plugins are somehow interfering with this, but I haven't tracked down specifics yet, except for what you can see in the first screenshot. I disabled nearly all plugins I had, and am still not able to get below 500ms (or 800 on main
) startuptime in a norg
file if Neorg is loading. Without loading Neorg, the norg files open just fine of course.
Other than Lazy, Neorg, and Treesitter, there's only like 8 actual plugins loading there, which all should be quite minimal and not cause issues. But somehow they do cause issues. Tried disabled folding completely, too, but no real effect in startuptime.
I'm working on a separate from-scratch Neovim config with Neorg that I'll use to track down specific issues.
The concealer speedup is noticeable and very welcome. Though it still doesn't quite fully activate when Neorg is lazy-loaded, until the cursor moves.
As for modules, I only have the defaults
, concealer
, and dirman
modules enabled.
Does it happen with any norg file?
Think so.
Even with:
* Title
- Things
Edit:
Also even with:
test
or a completely empty file.
I just tested on latest Nightly Neovim:
It takes almost 3 seconds.
Damn. I'll do some detailed profiling tomorrow in that case - I'm really interested what is actually causing the large slowdown. I also feel like there's a large lag when opening norg files, but i am not testing on a minimal config, which I will definitely try too. I'll post my findings then!
Okay so an update on the whole profiling situation - it seems like most of the time spent is parsing the highlights.scm
file. This is a really tricky scenario because there's no nice way of making these highlights shorter without making norg files look bland. I'll try to think of a solution but it's not an easy fix sadly lol
For reference, when loading a norg file ~420 milliseconds are spent on this process alone:
Figured its a treesitter related thing.
The thing is, in a very minimal setup, the total startuptime is still way less. I'm getting around 80ms. Which would imply maybe about only 20ms spent on that treesitter highlight parsing stuff. (Edit: in this case specifically)
Minimal config. Place into ~/.config/nvim_minimal/
as init.lua
.
-- File: `~/.config/nvim_minimal/init.lua`
-- NOTE: When using `NVIM_APPNAME=nvim_minimal` to launch into this alternate Neovim config,
-- this data path will not conflict with or pollute the primary data folders.
local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
-- Lazy Bootstrap:
if not vim.loop.fs_stat(lazypath) then
vim.fn.system({
"git",
"clone",
"--filter=blob:none",
"https://github.com/folke/lazy.nvim.git",
"--branch=stable", -- latest stable release
lazypath,
})
end
vim.opt.rtp:prepend(lazypath)
-- Lazy Setup:
require("lazy").setup({
{
"nvim-neorg/neorg",
lazy = false,
version = false,
cmd = {
"Neorg",
},
build = ":Neorg sync-parsers",
dependencies = {
"nvim-lua/plenary.nvim",
"nvim-treesitter/nvim-treesitter",
},
opts = {
load = {
[ "core.defaults" ] = {},
[ "core.concealer" ] = {},
},
},
config = function(_, opts)
require("neorg").setup(opts)
end,
},
})
-- End of File
Then launch Neovim using: NVIM_APPNAME=nvim_minimal nvim <some-norg-file>
NOTE: I'm on NVIM v0.9.0
, which seems to be load the fastest right now, for whatever reason.
Weird, difficult to pinpoint the exact cause here but I know that for larger configs treesitter is happily eating up most of the startup time. Indeed it runs pretty fast on the minimal config. As a side note, I'm testing in a test.lua
file and making it parse highlights.scm
, which I'm using as a benchmark. You can really feel it take a solid second on the default highlights.scm. What's causing the problem mainly boils down to this part:
((todo_item_undone) @neorg.todo_items.undone
.
(_) @neorg.todo_items.undone.content)
((todo_item_done) @neorg.todo_items.done
.
(_) @neorg.todo_items.done.content)
((todo_item_pending) @neorg.todo_items.pending
.
(_) @neorg.todo_items.pending.content)
((todo_item_on_hold) @neorg.todo_items.on_hold
.
(_) @neorg.todo_items.on_hold.content)
((todo_item_cancelled) @neorg.todo_items.cancelled
.
(_) @neorg.todo_items.cancelled.content)
((todo_item_uncertain) @neorg.todo_items.uncertain
.
(_) @neorg.todo_items.uncertain.content)
((todo_item_urgent) @neorg.todo_items.urgent
.
(_) @neorg.todo_items.urgent.content)
((todo_item_recurring) @neorg.todo_items.recurring
.
(_) @neorg.todo_items.recurring.content)
Which causes most of the slowdown. I'll change it to be faster by cutting some features.
Alright, after modifying the queries the startup time has dropped, but the performance issues are not fixed by any means lol, it's still very slow. I'll do more profiling, more benchmarking, maybe i'll magically come up with a good solution :D
Prerequisites
Neovim Version
NVIM v0.9.0
Neorg setup
Actual behavior
Neovim startuptime when opening *.norg files with Neorg installed is 10 to 20 times my normal startuptime. From ~50 ms to 500-1000ms.
The most recent Neorg version 4.5.0 increased my startuptime in *.norg files from ~500ms to ~950ms. I tested reverting back to 4.4.1, and my startuptime went back to ~500ms.
Even though
lazy.nvim
claims that the startuptime listed in the Profile tab of the UI is more accurate thannvim --startuptime
, I strongly believe this to be false in this case.lazy.nvim
seems to cut the startuptime off before something happens that seems to stall for quite a while. The difference between 500ms and ~1000ms can be felt very easily, as well.Here are small snippets from the end of the files generated by
nvim --startuptime
:v4.4.1:
v4.5.0:
Very awkwardly, I do not think this clearly explains what is causing the delay.
Expected behavior
I would expect the startuptime penalty from loading Neorg to be at most around twice my base startuptime, so 100ms in my case. I would also expect startuptime to not fluctuate so wildly between versions.
I would of course hope that the startuptime could be even lower, but I'm aware of a previous startuptime related issue which was closed as
wontfix
. However, I do believe this issue to be separate from the base startuptime being large. The startuptime should not increase this much from what are seemingly quite small changes.Steps to reproduce
nvim --startuptime time-v441.txt test.norg
using Neorg Version 4.4.1.nvim --startuptime time-v450.txt test.norg
using Neorg version 4.5.0.Potentially conflicting plugins
Other information
No response
Help
No
Implementation help
No response