Skip to content

Bug: CPU usage 100% when using luadoc TS parser in split-pane #1476

@litoj

Description

@litoj

Self Checks

  • I'm using the latest lualine.
  • I didn't find the issue in existing issues or PRs.

How to reproduce the problem

  1. open a lua file with type annotations where the annotations don't all fit on the screen - example file provided in Additional Info
  2. :vsplit
  3. press G in the second pane to go to the bottom of the file
  4. observe the performance suddenly goes up (to 12% in my case when using this almost empty file)

Expected behaviour

The cpu usage should stay at practically 0 since nothing is happening. Just like with the default statusline

Actual behaviour

nvim has signifficantly increased cpu usage for as long as the second buffer is open and scrolled over a different luadoc text

Minimal config to reproduce the issue

Using Lazy.nvim This is the entire config necessary to reproduce the problem:

-- to make it clear it happens even with no modules enabled -> some internal bug
vim.o.laststatus = 3
return {
	{
		'nvim-lualine/lualine.nvim',
		dependencies = { 'nvim-tree/nvim-web-devicons' },
		event = 'VeryLazy',
		opts = {
			sections = {
				lualine_a = {},
				lualine_b = {},
				lualine_c = {},
				lualine_x = {},
				lualine_y = {},
				lualine_z = {},
			},
		},
	},
	{
		'nvim-treesitter/nvim-treesitter',
		build = ':TSUpdate',
		event = 'VeryLazy',
		config = function()
			---@diagnostic disable-next-line: missing-fields
			require('nvim-treesitter.configs').setup { ensure_installed = { 'lua', 'luadoc' } }
		end,
	},
}

Additional information

lua file with replicatable issue (renamed to .txt for github)
bug.txt

you can track the performance change with the following bash script:

#!/usr/bin/bash
proc="${PROC:-nvim --embed}"
interval=${INTERVAL_MS:-1000} # interval in ms
seconds=$(bc <<<"scale=2;$interval/1000") # recalculated to s
while :; do
	pids=($(pgrep -f "$proc")) # get all nvim processes

	declare -i sum=0 # sum up the current cpu usage
	for pid in ${pids[@]}; do
		((sum -= $(cat /proc/$pid/stat | awk '{print $14+$15}')))
	done

	sleep $seconds

	for pid in ${pids[@]}; do # calculate the diff in cpu usage
		((sum += $(cat /proc/$pid/stat | awk '{print $14+$15}')))
	done

	((sum = 1000 * sum / interval)) # make the usage relative to 1 second
	echo "${proc^^}: $sum%"
done

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions