neovim

Neovim text editor
git clone https://git.dasho.dev/neovim.git
Log | Files | Refs | README

decor_spec.lua (4906B)


      1 local n = require('test.functional.testnvim')()
      2 local Screen = require('test.functional.ui.screen')
      3 local exec_lua = n.exec_lua
      4 
      5 describe('decor perf', function()
      6  before_each(n.clear)
      7 
      8  it('can handle long lines', function()
      9    Screen.new(100, 101)
     10 
     11    local result = exec_lua(function()
     12      local ephemeral_pattern = {
     13        { 0, 4, 'Comment', 11 },
     14        { 0, 3, 'Keyword', 12 },
     15        { 1, 2, 'Label', 12 },
     16        { 0, 1, 'String', 21 },
     17        { 1, 3, 'Function', 21 },
     18        { 2, 10, 'Label', 8 },
     19      }
     20 
     21      local regular_pattern = {
     22        { 4, 5, 'String', 12 },
     23        { 1, 4, 'Function', 2 },
     24      }
     25 
     26      for _, list in ipairs({ ephemeral_pattern, regular_pattern }) do
     27        for _, p in ipairs(list) do
     28          p[3] = vim.api.nvim_get_hl_id_by_name(p[3])
     29        end
     30      end
     31 
     32      local text = ('abcdefghijklmnopqrstuvwxyz0123'):rep(333)
     33      local line_len = #text
     34      vim.api.nvim_buf_set_lines(0, 0, 0, false, { text })
     35 
     36      local ns = vim.api.nvim_create_namespace('decor_spec.lua')
     37      vim.api.nvim_buf_clear_namespace(0, ns, 0, -1)
     38      vim.api.nvim_win_set_cursor(0, { 1, 0 })
     39 
     40      local ps, pe
     41      local function add_pattern(pattern, ephemeral)
     42        ps = vim.uv.hrtime()
     43        local i = 0
     44        while i < line_len - 10 do
     45          for _, p in ipairs(pattern) do
     46            vim.api.nvim_buf_set_extmark(0, ns, 0, i + p[1], {
     47              end_row = 0,
     48              end_col = i + p[2],
     49              hl_group = p[3],
     50              priority = p[4],
     51              ephemeral = ephemeral,
     52            })
     53          end
     54          i = i + 5
     55        end
     56        pe = vim.uv.hrtime()
     57      end
     58 
     59      vim.api.nvim_set_decoration_provider(ns, {
     60        on_win = function()
     61          return true
     62        end,
     63        on_line = function()
     64          add_pattern(ephemeral_pattern, true)
     65        end,
     66      })
     67 
     68      add_pattern(regular_pattern, false)
     69 
     70      local total = {}
     71      local provider = {}
     72      for _ = 1, 100 do
     73        local tic = vim.uv.hrtime()
     74        vim.cmd 'redraw!'
     75        local toc = vim.uv.hrtime()
     76        table.insert(total, toc - tic)
     77        table.insert(provider, pe - ps)
     78      end
     79 
     80      return { total, provider }
     81    end)
     82 
     83    local total, provider = unpack(result)
     84    table.sort(total)
     85    table.sort(provider)
     86 
     87    local ms = 1 / 1000000
     88    local function fmt(stats)
     89      return string.format(
     90        'min, 25%%, median, 75%%, max:\n\t%0.1fms,\t%0.1fms,\t%0.1fms,\t%0.1fms,\t%0.1fms',
     91        stats[1] * ms,
     92        stats[1 + math.floor(#stats * 0.25)] * ms,
     93        stats[1 + math.floor(#stats * 0.5)] * ms,
     94        stats[1 + math.floor(#stats * 0.75)] * ms,
     95        stats[#stats] * ms
     96      )
     97    end
     98 
     99    print('\nTotal ' .. fmt(total) .. '\nDecoration provider: ' .. fmt(provider))
    100  end)
    101 
    102  it('can handle full screen of highlighting', function()
    103    Screen.new(100, 51)
    104 
    105    local result = exec_lua(function()
    106      local long_line = 'local a={' .. ('a=5,'):rep(22) .. '}'
    107      local lines = {}
    108      for _ = 1, 50 do
    109        table.insert(lines, long_line)
    110      end
    111      vim.api.nvim_buf_set_lines(0, 0, 0, false, lines)
    112      vim.api.nvim_win_set_cursor(0, { 1, 0 })
    113      vim.treesitter.start(0, 'lua')
    114 
    115      local total = {}
    116      for _ = 1, 100 do
    117        local tic = vim.uv.hrtime()
    118        vim.cmd 'redraw!'
    119        local toc = vim.uv.hrtime()
    120        table.insert(total, toc - tic)
    121      end
    122 
    123      return { total }
    124    end)
    125 
    126    local total = unpack(result)
    127    table.sort(total)
    128 
    129    local ms = 1 / 1000000
    130    local res = string.format(
    131      'min, 25%%, median, 75%%, max:\n\t%0.1fms,\t%0.1fms,\t%0.1fms,\t%0.1fms,\t%0.1fms',
    132      total[1] * ms,
    133      total[1 + math.floor(#total * 0.25)] * ms,
    134      total[1 + math.floor(#total * 0.5)] * ms,
    135      total[1 + math.floor(#total * 0.75)] * ms,
    136      total[#total] * ms
    137    )
    138    print('\nTotal ' .. res)
    139  end)
    140 
    141  it('can handle long lines with treesitter highlighting', function()
    142    Screen.new(100, 51)
    143 
    144    local result = exec_lua(function()
    145      local long_line = 'local a = { ' .. ('a = 5, '):rep(2000) .. '}'
    146      vim.api.nvim_buf_set_lines(0, 0, 0, false, { long_line })
    147      vim.api.nvim_win_set_cursor(0, { 1, 0 })
    148      vim.treesitter.start(0, 'lua')
    149 
    150      local total = {}
    151      for _ = 1, 50 do
    152        local tic = vim.uv.hrtime()
    153        vim.cmd 'redraw!'
    154        local toc = vim.uv.hrtime()
    155        table.insert(total, toc - tic)
    156      end
    157 
    158      return { total }
    159    end)
    160 
    161    local total = unpack(result)
    162    table.sort(total)
    163 
    164    local ms = 1 / 1000000
    165    local res = string.format(
    166      'min, 25%%, median, 75%%, max:\n\t%0.1fms,\t%0.1fms,\t%0.1fms,\t%0.1fms,\t%0.1fms',
    167      total[1] * ms,
    168      total[1 + math.floor(#total * 0.25)] * ms,
    169      total[1 + math.floor(#total * 0.5)] * ms,
    170      total[1 + math.floor(#total * 0.75)] * ms,
    171      total[#total] * ms
    172    )
    173    print('\nTotal ' .. res)
    174  end)
    175 end)