-
Notifications
You must be signed in to change notification settings - Fork 203
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Zig file takes a long time to open #461
Comments
Are you sure it's because of the textobjects? is it slow when you remove this plugin too? Also, I noticed some slowdown using nvim-0.9.1. If you use nvim-0.9.0 is it still an issue? |
I'm pretty sure it is because of text objects I tried without and it doesn't take that much. I'll check with 0.9. Does it take seconds for you to open this file? const std = @import("std");
pub fn main() !void {
const stdout = std.io.getStdOut().writer();
try stdout.print("Hello, {s}!\n", .{"world"});
} |
It takes 3 times less in nvim-0.9.0. So it may be related to that Time
real 0m0.057s
user 0m0.038s
sys 0m0.022s
Hyperfine
Benchmark 1: nvim --clean -u init.lua main.zig -c "q"
Time (mean ± σ): 55.3 ms ± 1.2 ms [User: 36.7 ms, System: 19.7 ms]
Range (min … max): 54.0 ms … 59.9 ms 49 runs |
I also noticed that when running
All parsers are up-to-date!
[nvim-treesitter] [0/2] Downloading tree-sitter-zig...
[nvim-treesitter] [0/2] Downloading tree-sitter-zig...
[nvim-treesitter] [0/2] Creating temporary directory
[nvim-treesitter] [0/2] Extracting tree-sitter-zig...
[nvim-treesitter] [0/2] Compiling...
Error detected while processing command line:
nvim-treesitter[zig]: Error during compilation
cc1: fatal error: src/parser.c: No such file or directory
compilation terminated.
[nvim-treesitter] [1/2, failed: 1] Creating temporary directory
[nvim-treesitter] [1/2, failed: 1] Extracting tree-sitter-zig...
nvim-treesitter[zig]: Error during tarball extraction.
tar (child): tree-sitter-zig.tar.gz: Cannot open: No such file or directory
tar (child): Error is not recoverable: exiting now
tar: Child returned status 2
tar: Error is not recoverable: exiting now |
Do you use |
Nope |
For me, it takes pretty long to open that file, with and without textobjects. Even with nvim-0.9.0 it might be faster but it is still quite slow. |
I can't reproduce the compilation issue though. |
Oh do you have any suggestion to debug it on my side? |
Is it much faster on nvim-0.9.0 or is it just 3 times? The time says it took 0m0.057s, isn't it pretty fast compared to 3 seconds? If that's the case, maybe it's just the core neovim problem. |
About compilation issue, I can't help you with that. Maybe report it on |
Sorry I edited my previous benchmark comment right after, since a second benchmark I did went from 0m1.235s -> to 0m0.057s. I just forgot to edit the 3x speed.
I just checked I can only reproduce it with 0.9.1 btw |
Same issue with opening dart files. Edit:
and that treesitter call hangs at https://github.com/neovim/neovim/blob/12c2c16acf7051d364d29cfd71f2542b0943d8e8/runtime/lua/vim/treesitter/query.lua#L259 Output of ts.get_query('dart', 'textobjects'):'; class\n((\n [(marker_annotation)? (annotation)?] @class.outer.start .\n (class_definition \n body: (class_body) @_end @class.inner) @_start\n )\n (#make-range! "class.outer" @_start @_end))\n(mixin_declaration (class_body) @class.inner) @class.outer\n(enum_declaration\n body: (enum_body) @class.inner) @class.outer\n(extension_declaration\n body: (extension_body) @class.inner) @class.outer\n\n; function/method\n(( \n [(marker_annotation)? (annotation)?] @function.outer.start .\n [(method_signature) (function_signature)] @_start .\n (function_body) @_end\n )\n (#make-range! "function.outer" @_start @_end))\n\n(function_body\n (block . "{" . (_) @_start @_end (_)? @_end . "}"\n (#make-range! "function.inner" @_start @_end)))\n\n(type_alias (function_type)? @function.inner) @function.outer\n\n; parameter\n[\n (formal_parameter)\n (normal_parameter_type)\n (type_parameter)\n] @parameter.inner\n(\n"," @_start . [\n (formal_parameter)\n (normal_parameter_type)\n (type_parameter)\n ] @_par\n (#make-range! "parameter.outer" @_start @_par))\n(\n [\n (formal_parameter)\n (normal_parameter_type)\n (type_parameter)\n ] @_par . "," @_end \n (#make-range! "parameter.outer" @_par @_end))\n\n;; TODO: (_)* not supported yet -> for now this works correctly only with simple arguments \n((arguments\n . (_) @parameter.inner . ","? @_end)\n (#make-range! "parameter.outer" @parameter.inner @_end))\n((arguments\n "," @_start . (_) @parameter.inner)\n (#make-range! "parameter.outer" @_start @parameter.inner))\n\n; call\n(\n (identifier) @_start . (selector (argument_part) @_end)\n (#make-range! "call.outer" @_start @_end)\n)\n\n(\n (identifier) .\n (selector\n (argument_part\n (arguments . "(" . (_) @_start (_)? @_end . ")"\n (#make-range! "call.inner" @_start @_end))))\n)\n\n; block\n(block) @block.outer\n\n; conditional\n(if_statement\n [\n condition: (_)\n consequence: (_)\n alternative: (_)?\n ] @conditional.inner) @conditional.outer\n(switch_statement\n body: (switch_block) @conditional.inner) @conditional.outer\n(conditional_expression\n [\n consequence: (_)\n alternative: (_)\n ] @conditional.inner) @conditional.outer\n\n; loop\n(for_statement\n body: (block) @loop.inner) @loop.outer\n(while_statement\n body: (block) @loop.inner) @loop.outer\n(do_statement\n body: (block) @loop.inner) @loop.outer\n\n; comment\n[\n (comment)\n (documentation_comment)\n] @comment.outer\n\n; statement\n[\n (break_statement)\n (do_statement)\n (expression_statement)\n (for_statement)\n (if_statement)\n (return_statement)\n (switch_statement)\n (while_statement)\n (assert_statement)\n ;(labeled_statement)\n (yield_statement)\n (yield_each_statement)\n (continue_statement)\n (try_statement)\n] @statement.outer\n'Stacktrace
Is the output supposed to be that big? In other cases it's much shorter like |
Confirm @gepbird, dart files take from 7 up to 10 seconds to open on my machine (even for an empty file) with
|
I'm having the same issue on the nightly build of neovim.
Have to wait for about 1.5s to interact. Only seems to occur when $ nvim --version
NVIM v0.10.0-dev-2551+g8797429a7
Build type: RelWithDebInfo
LuaJIT 2.1.1707061634
Run "nvim -V1 -v" for more info |
Disabling |
Tree sitter issue: tree-sitter/tree-sitter#973 |
The slowdown is happening because tree-sitter spends some extra time at startup in order to improve the runtime of a query. As a workaround to reduce the effect of this feature, you can decrease this number in tree-sitter. Recompile neovim with the modified tree-sitter and this plugin will be fast. Here's an overlay for this patch if you're on NixOS: nixpkgs.overlays = [
(final: prev: {
tree-sitter = prev.tree-sitter.overrideAttrs {
patches = [
(prev.fetchpatch {
url = "https://github.com/gepbird/tree-sitter/commit/4b93751ee7fe92b3063baf0cd4d80e7991c6e5e8.patch";
hash = "sha256-bMFrPozoWUbSNdKyPVsFQLhSf+MYb3aiWlybI2/J6Zg=";
})
];
};
})
]; |
The situation for zig is better now. It doesn't take 3 seconds anymore. Should the issue be closed? |
Describe the bug
When I open a
zig
file with this extension enabled it takes 3 seconds on my machine to start itTo Reproduce
I made a minimal config to reproduce:
git clone https://github.com/lnc3l0t/treesitter-textobjects-issue /tmp/nvim; cd /tmp/nvim; . launch.sh
It contains:
launch.sh
script which clonenvim-treesitter
andnvim-treesitter-textobjects
, installs the zig parser, launches neovim and benchmarks it.init.lua
minimal neovim config that sets uppackage.path
andnvim-treesitter.config
main.zig
a minimal zig file to openExpected behavior
It should open like any other filetypes but on my machine the benchmarks take around 3 seconds:
Time
real 0m3.181s
user 0m3.159s
sys 0m0.024s
Hyperfine
Benchmark 1: nvim --clean -u init.lua main.zig -c "q"
Time (mean ± σ): 3.202 s ± 0.007 s [User: 3.181 s, System: 0.019 s]
Range (min … max): 3.189 s … 3.209 s 10 runs
Output of
:checkhealth nvim-treesitter
==============================================================================
nvim-treesitter: require("nvim-treesitter.health").check()
Installation ~
tree-sitter
found 0.20.8 (parser generator, only needed for :TSInstallFromGrammar)node
found v20.2.0 (only needed for :TSInstallFromGrammar)git
executable found.cc
executable found. Selected from { vim.NIL, "cc", "gcc", "clang", "cl", "zig" }Version: cc (GCC) 13.1.1 20230429
OS Info:
{
machine = "x86_64",
release = "6.3.5-arch1-1",
sysname = "Linux",
version = "#1 SMP PREEMPT_DYNAMIC Tue, 30 May 2023 13:44:01 +0000"
} ~
Parser/Features H L F I J
Legend: H[ighlight], L[ocals], F[olds], I[ndents], In[j]ections
+) multiple parsers found, only one will be used
x) errors found in the query, try to run :TSUpdate {lang} ~
Output of
nvim --version
Tried with both master and stableAdditional context
I checked for issues in these repository and in nvim-treesitter regarding zig but I couldn't find anything related.
The text was updated successfully, but these errors were encountered: