## 事象 `hoge.ts`を作成して ```ts function main() { console.log("hoge"); } ``` `nvim hoge.ts`で開き、`:Lazy profile`コマンドで結果を出力。 ``` Startuptime: 261.86ms Based on the actual CPU time of the Neovim process till UIEnter. This is more accurate than `nvim --startuptime`. LazyStart 2.97ms LazyDone 23.75ms (+20.78ms) UIEnter 261.86ms (+238.11ms) ``` [[UIEnter]]で238msもの時間がかかっている。100msを超えると画面の突っかかりを感じるので解消したい。 ### 設定 ```lua { 'nvim-treesitter/nvim-treesitter', event = { 'BufNewFile', 'BufRead' }, build = ":TSUpdate", config = function() require('nvim-treesitter.configs').setup { ensure_installed = { "typescript", }, highlight = { enable = true, disable = { "ini" } }, autotag = { enable = true, }, textobjects = { select = { enable = true, lookahead = true, keymaps = { ["af"] = "@function.outer", ["if"] = "@function.inner", ["ac"] = "@class.outer", ["ic"] = { query = "@class.inner", desc = "Select inner part of a class region" }, } }, } } end }, ``` ## 原因 [[nvim-treesitter]]プラグインや、そのtypescript実装自体の処理による限界ぽい。 ## 解決方法 使用する[[nvim-treesitter]]の機能を制限する。たとえば、各機能を無効化するとそれぞれ速度が改善する。 | 速度(UIEnter増加分) | highlight | autotag | textobjects | | ------------------- | --------- | ------- | ----------- | | 110ms | O | | | | 37ms | | O | | | 105ms | | | O | | 110ms | O | O | | | 106ms | | O | O | | 180ms | O | | O | | 196ms | O | O | O | | 39ms | | | | 以上から以下が分かる。 - `highlight`と`textobjects`はそれぞれ70ms程度かかる - `autotag`は影響しない 個人的に`textobjects`の利用は必須でないため削除した。