Skip to content
This repository has been archived by the owner on May 5, 2023. It is now read-only.

pcall(require, <missing module>) takes a long time #20

Closed
goolord opened this issue Sep 9, 2021 · 4 comments · Fixed by #24
Closed

pcall(require, <missing module>) takes a long time #20

goolord opened this issue Sep 9, 2021 · 4 comments · Fixed by #24

Comments

@goolord
Copy link

goolord commented Sep 9, 2021

ref: lukas-reineke/indent-blankline.nvim#213

tldr; a piece of code like this

local ts_status, ts_query = pcall(require, "nvim-treesitter.query")
local ts_status, ts_indent = pcall(require, "nvim-treesitter.indent")

is about 366% slower (~6 ms -> ~22 ms) with impatient.nvim enabled when nvim-treesitter, nvim-treesitter.query, and nvim-treesitter.indent don't exist

@chase
Copy link
Contributor

chase commented Sep 9, 2021

Hm, so the nvim-treesitter module isn't located anywhere in your runtime path?

If this is a regular case where a module doesn't exist, might need to figure out how to do a faster fall-through.
Maybe add a loader at the very end that records missing packages and checks ahead of loading the cache if the file exists, or something similar.

@lewis6991 lewis6991 changed the title a call to pcall(require, "nvim-treesitter.query"); takes dramatically longer pcall(require, <missing module>) takes a long time Sep 9, 2021
@lewis6991
Copy link
Owner

lewis6991 commented Sep 9, 2021

It is probably because we maintain the original vim loader, and we add 3 of our own.

One solution would be to just remove neovims original loader.

Maybe add a loader at the very end that records missing packages and checks ahead of loading the cache if the file exists, or something similar.

Interesting idea, we could do that. Problem is I'm not sure how to bail the loading process and skip all the loaders. Maybe redefining require?

lewis6991 added a commit that referenced this issue Sep 10, 2021
... and completely replace vim._load_package

This speeds up statements like:

  pcall(require, 'does.not.exist')

Since 'require' doesn't need to search through as many loaders and hence
results in less calls to nvim_get_runtime_file().

Resolves #20
lewis6991 added a commit that referenced this issue Sep 10, 2021
... and completely replace vim._load_package

This speeds up statements like:

  pcall(require, 'does.not.exist')

Since 'require' doesn't need to search through as many loaders and hence
results in less calls to nvim_get_runtime_file().

Resolves #20
@lewis6991
Copy link
Owner

@goolord can you give #24 a go. It should make the performance roughly the same as without impatient for loading missing modules.

lewis6991 added a commit that referenced this issue Sep 11, 2021
... and completely replace vim._load_package

This speeds up statements like:

  pcall(require, 'does.not.exist')

Since 'require' doesn't need to search through as many loaders and hence
results in less calls to nvim_get_runtime_file().

Resolves #20
@lewis6991 lewis6991 reopened this Sep 11, 2021
@lewis6991
Copy link
Owner

Fixed with #46

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants