Skip to content

continuous_sync makes :global command really slow #121

@arnevm123

Description

@arnevm123

When trying to execute a :g (:global) command with continuous_sync enabled this makes the command noticeable slower.

How to reproduce this:
Enable continuous_sync, open a random file and try a global command.
Example of this would be :g/^$/d to remove all empty lines in a file (a file with 20-30 empty lines already has a noticeable delay on my machine).
Toggle the continuous sync on and off to see the difference in speed.

Minimal config to test this:

local lazypath = vim.fn.stdpath("data") .. "/lazy/lazy.nvim"
if not (vim.uv or 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)
-- Example using a list of specs with the default options
vim.g.mapleader = " " -- Make sure to set `mapleader` before lazy so your mappings are correct
vim.g.maplocalleader = "\\" -- Same for `maplocalleader`

require("lazy").setup({
	{
		"AckslD/nvim-neoclip.lua",
		dependencies = {
			{ "kkharji/sqlite.lua", module = "sqlite" },
			{ "nvim-telescope/telescope.nvim" },
		},
		config = function()
			require("neoclip").setup({
				enable_persistent_history = true,
				-- set to false to have fast global commands again
				continuous_sync = true,
				db_path = vim.fn.stdpath("data") .. "/neoclip/neoclip.sqlite3",
			})
		end,
		lazy = false,
	},
})

Not sure if this would be an easy fix, but I have a workaround:
Only push the database on focus lost:

autocmd("FocusLost", {
	group = augroup("NeoClipFocus", {}),
	pattern = "*",
	callback = function()
		require("neoclip").db_push()
	end,
})

FocusGained does not work when using autoread, so I sync whenever I trigger the telescope menu:

:lua require('neoclip').db_pull()<CR>:Telescope neoclip<CR>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions