Skip to content
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

perf: Lazily require adapter mappings #70

Merged
merged 1 commit into from
Apr 19, 2023
Merged

Conversation

Natr1x
Copy link
Contributor

@Natr1x Natr1x commented Apr 19, 2023

Because vim.fn.exepath can potentially be very slow if the searched for executable cannot be found, loading every adapter mapping at startup is not ideal. This change moves the adapter mappings into their own files and then lazily requires them from lua/mason-nvim-dap/mappings/adapters/init.lua.

While looking for non existing adapters on cluttered paths will still be slow this will avoid looking until they are needed. Which should usually mean that not all of them are searched for at startup but also that uninstalled adapters will probably not be looked for that often (given that users hopefully aren't in the habit of setting up DAP adapters they have not installed).

Users on none cluttered or slow paths will probably also see a small improvement in startup times as the system calls searching for just one non existing executable will almost certainly take more time than any additional overhead created from splitting up the adapter mappings.

Related Issues: #69 #67

@Natr1x Natr1x changed the title Lazily require adapter mappings perf: Lazily require adapter mappings Apr 19, 2023
@meuter
Copy link

meuter commented Apr 19, 2023

Thanks @Natr1x 🚀

I just tested your fork and it works like a charm:

083.503  000.240  000.240: require('mason-nvim-dap')
083.542  000.036  000.036: require('mason-nvim-dap.settings')
083.668  000.047  000.047: require('mason-nvim-dap.mappings.source')
083.673  000.118  000.071: require('mason-nvim-dap.ensure_installed')
084.363  000.137  000.137: require('mason-nvim-dap.mappings.adapters')
084.518  000.152  000.152: require('mason-nvim-dap.mappings.filetypes')
089.397  000.074  000.074: require('mason-core.functional.type')
166.432  081.913  081.838: require('mason-nvim-dap.mappings.configurations')
166.537  000.092  000.092: require('mason-nvim-dap.mappings.adapters.delve')
166.569  000.029  000.029: require('mason-nvim-dap.automatic_setup')
166.644  000.030  000.030: require('mason-nvim-dap.mappings.adapters.bash')
166.696  000.034  000.034: require('mason-nvim-dap.mappings.adapters.codelldb')
166.756  000.031  000.031: require('mason-nvim-dap.mappings.adapters.python')

Would it make sense to apply the same trick to lazy load the configurations? 80ms (in my config - Ubuntu22.04 on WSL2)

@Natr1x
Copy link
Contributor Author

Natr1x commented Apr 19, 2023

@meuter
Not sure, I guess it depends on your config but I don't think there is much point in using metatables this way when you can simply just require things the regular way.

I e since these two are functionally equivalent: require('mappings.adapters').codelldb and require('mappings.adapters.codelldb')
Why would you go through the trouble with the metatable instead of just plain writing the later one?

The reason I think it made sense in this context is that the first pattern would not require code using the 'mappings.adapters' module to be rewritten (unless they are looping through it instead of just accessing the keys) so it avoids breaking anyone's existing neovim config.

But if it is just your own config then that probably doesn't matter as much and is probably just useful for aestethic reasons while adding unnecessary complexity.

Although if the question was just about whether it would be a good idea to split the config into multiple files and then lazily requiring them when they are needed then I can't think of many cases where that doesn't make sense.

@jay-babu jay-babu merged commit 9816e2a into jay-babu:main Apr 19, 2023
antonpetrovmain pushed a commit to antonpetrovmain/mason-nvim-dap.nvim that referenced this pull request Apr 20, 2023
@meuter
Copy link

meuter commented Apr 21, 2023

Thanks! I was indeed referring to splitting the configurations and loading them lazily.

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

Successfully merging this pull request may close these issues.

3 participants