robin/laufey

git clone https://git.robinwobin.dev/robin/laufey

Justin M. KeyesMerge #40865 from justinmk/fixcif907614088

master
7.5 KiB193 linesraw
1local n = require('test.functional.testnvim')()
2local t = require('test.testutil')
3local Screen = require('test.functional.ui.screen')
4
5local describe, it, before_each = t.describe, t.it, t.before_each
6local clear = n.clear
7local exec_lua = n.exec_lua
8
9describe('treesitter perf', function()
10  before_each(function()
11    clear()
12  end)
13
14  it('can handle large folds', function()
15    n.command 'edit ./src/nvim/eval.c'
16    exec_lua [[
17      local parser = vim.treesitter.get_parser(0, "c", {})
18      vim.treesitter.highlighter.new(parser)
19
20      local function keys(k)
21        vim.api.nvim_feedkeys(k, 't', true)
22      end
23
24      vim.opt.foldmethod = "manual"
25      vim.opt.lazyredraw = false
26
27      vim.cmd '1000,7000fold'
28      vim.cmd '999'
29
30      local function mk_keys(n)
31        local acc = ""
32        for _ = 1, n do
33          acc = acc .. "j"
34        end
35        for _ = 1, n do
36          acc = acc .. "k"
37        end
38
39        return "qq" .. acc .. "q"
40      end
41
42      local start = vim.uv.hrtime()
43      keys(mk_keys(10))
44
45      for _ = 1, 100 do
46        keys "@q"
47        vim.cmd'redraw!'
48      end
49
50      return vim.uv.hrtime() - start
51    ]]
52  end)
53
54  local function test_long_line(_pos, _wrap, _line, grid)
55    local screen = Screen.new(20, 11)
56
57    local result = exec_lua(function(...)
58      local pos, wrap, line = ...
59
60      vim.api.nvim_buf_set_lines(0, 0, 0, false, { line })
61      vim.api.nvim_win_set_cursor(0, pos)
62      vim.api.nvim_set_option_value('wrap', wrap, { win = 0 })
63
64      vim.treesitter.start(0, 'lua')
65
66      local total = {}
67      for _ = 1, 100 do
68        local tic = vim.uv.hrtime()
69        vim.cmd 'redraw!'
70        local toc = vim.uv.hrtime()
71        table.insert(total, toc - tic)
72      end
73
74      return { total }
75    end, _pos, _wrap, _line)
76
77    screen:expect({ grid = grid or '' })
78
79    local total = unpack(result)
80    table.sort(total)
81
82    local ms = 1 / 1000000
83    local res = string.format(
84      'min, 25%%, median, 75%%, max:\n\t%0.2fms,\t%0.2fms,\t%0.2fms,\t%0.2fms,\t%0.2fms',
85      total[1] * ms,
86      total[1 + math.floor(#total * 0.25)] * ms,
87      total[1 + math.floor(#total * 0.5)] * ms,
88      total[1 + math.floor(#total * 0.75)] * ms,
89      total[#total] * ms
90    )
91    print('\nTotal ' .. res)
92  end
93
94  local long_line = 'local a = { ' .. ('a = 5, '):rep(500) .. '}'
95  it('can redraw the beginning of a long line with wrapping', function()
96    local grid = [[
97      {15:^local} {25:a} {15:=} {16:{} {25:a} {15:=} {26:5}{16:,} {25:a}|
98       {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} |
99      {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,}|
100       {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}|
101      {16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} |
102      {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=}|
103       {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} |
104      {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a}|
105       {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} |
106      {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,}|
107                          |
108    ]]
109    test_long_line({ 1, 0 }, true, long_line, grid)
110  end)
111
112  it('can redraw the middle of a long line with wrapping', function()
113    local grid = [[
114      {1:<<<}{26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} |
115      {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,}|
116       {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}|
117      {16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} |
118      {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=}|
119       {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} |
120      {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a}|
121       {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} |
122      {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,}|
123       {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a}^ {15:=} {26:5}|
124                          |
125    ]]
126    test_long_line({ 1, math.floor(#long_line / 2) }, true, long_line, grid)
127  end)
128
129  it('can redraw the end of a long line with wrapping', function()
130    local grid = [[
131      {1:<<<}{25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=}|
132       {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} |
133      {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a}|
134       {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} |
135      {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,}|
136       {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}|
137      {16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} |
138      {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=}|
139       {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {25:a} |
140      {15:=} {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {16:^}}       |
141                          |
142    ]]
143    test_long_line({ 1, #long_line - 1 }, true, long_line, grid)
144  end)
145
146  it('can redraw the beginning of a long line without wrapping', function()
147    local grid = [[
148      {15:^local} {25:a} {15:=} {16:{} {25:a} {15:=} {26:5}{16:,} {25:a}|
149                          |
150      {1:~                   }|*8
151                          |
152    ]]
153    test_long_line({ 1, 0 }, false, long_line, grid)
154  end)
155
156  it('can redraw the middle of a long line without wrapping', function()
157    local grid = [[
158      {16:,} {25:a} {15:=} {26:5}{16:,} {25:a}^ {15:=} {26:5}{16:,} {25:a} {15:=} |
159                          |
160      {1:~                   }|*8
161                          |
162    ]]
163    test_long_line({ 1, math.floor(#long_line / 2) }, false, long_line, grid)
164  end)
165
166  it('can redraw the end of a long line without wrapping', function()
167    local grid = [[
168      {26:5}{16:,} {25:a} {15:=} {26:5}{16:,} {16:^}}         |
169                          |
170      {1:~                   }|*8
171                          |
172    ]]
173    test_long_line({ 1, #long_line - 1 }, false, long_line, grid)
174  end)
175
176  local long_line_mb = 'local a = { ' .. ('À = 5, '):rep(500) .. '}'
177  it('can redraw the middle of a long line with multibyte characters', function()
178    local grid = [[
179      {1:<<<}{26:5}{16:,} {25:À} {15:=} {26:5}{16:,} {25:À} {15:=} {26:5}{16:,} |
180      {25:À} {15:=} {26:5}{16:,} {25:À} {15:=} {26:5}{16:,} {25:À} {15:=} {26:5}{16:,}|
181       {25:À} {15:=} {26:5}{16:,} {25:À} {15:=} {26:5}{16:,} {25:À} {15:=} {26:5}|
182      {16:,} {25:À} {15:=} {26:5}{16:,} {25:À} {15:=} {26:5}{16:,} {25:À} {15:=} |
183      {26:5}{16:,} {25:À} {15:=} {26:5}{16:,} {25:À} {15:=} {26:5}{16:,} {25:À} {15:=}|
184       {26:5}{16:,} {25:À} {15:=} {26:5}{16:,} {25:À} {15:=} {26:5}{16:,} {25:À} |
185      {15:=} {26:5}{16:,} {25:À} {15:=} {26:5}{16:,} {25:À} {15:=} {26:5}{16:,} {25:À}|
186       {15:=} {26:5}{16:,} {25:À} {15:=} {26:5}{16:,} {25:À} {15:=} {26:5}{16:,} |
187      {25:À} {15:=} {26:5}{16:,} {25:À} {15:=} {26:5}{16:,} {25:À} {15:=} {26:5}{16:,}|
188       {25:À} {15:=} {26:5}{16:,} {25:À} {15:=} {26:5}{16:,} {25:À}^ {15:=} {26:5}|
189                          |
190    ]]
191    test_long_line({ 1, math.floor(#long_line_mb / 2) }, true, long_line_mb, grid)
192  end)
193end)