Skip to content

Commit 2d2b30f

Browse files
chore: avoid calling tree:parse() when computing concealed ranges
## Details I want to eventually take advantage of the async parsing capabilities added to neovim. This gets easier if I limit where the `parse` function is called to a single place. To do this I just need to remove the only other place it's called which is as part of calculating concealed regions. Honestly not sure why that's there since we parse, iterate, then parse and iterate again? Seems like the first call should do, though maybe I'm forgetting the context behind this behavior. If it's a problem I can add a test for it and add it back, but it seems safe enough. Following this I'll experiment with moving some of the logic to callbacks to make the transition easier. Minor other changes: - When logging runtime include a name and better align the output. - For the benchmark tests do not include the amount of time it takes to run the callback, meaning feeding keys and kicking off an autocommand. How long this stuff takes is out of our control and leads to less consistent results. Update the thresholds based on this new approach.
1 parent 0d3bf2b commit 2d2b30f

File tree

8 files changed

+18
-16
lines changed

8 files changed

+18
-16
lines changed

benches/medium_spec.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ local util = require('benches.util')
55
describe('medium.md', function()
66
it('default', function()
77
local base_marks = 85
8-
util.less_than(util.setup('temp/medium.md'), 35)
8+
util.less_than(util.setup('temp/medium.md'), 20)
99
util.num_marks(base_marks)
1010

11-
util.less_than(util.move_down(3), 20)
11+
util.less_than(util.move_down(3), 0.5)
1212
util.num_marks(base_marks + 2)
1313

14-
util.less_than(util.insert_mode(), 20)
14+
util.less_than(util.insert_mode(), 5)
1515
util.num_marks(base_marks + 2)
1616
end)
1717
end)

benches/medium_table_spec.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ local util = require('benches.util')
55
describe('medium-table.md', function()
66
it('default', function()
77
local base_marks = 341
8-
util.less_than(util.setup('temp/medium-table.md'), 120)
8+
util.less_than(util.setup('temp/medium-table.md'), 100)
99
util.num_marks(base_marks)
1010

11-
util.less_than(util.move_down(1), 20)
11+
util.less_than(util.move_down(1), 0.5)
1212
util.num_marks(base_marks + 2)
1313

14-
util.less_than(util.insert_mode(), 25)
14+
util.less_than(util.insert_mode(), 15)
1515
util.num_marks(base_marks + 2)
1616
end)
1717
end)

benches/readme_spec.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ local util = require('benches.util')
55
describe('README.md', function()
66
it('default', function()
77
local base_marks = 113
8-
util.less_than(util.setup('README.md'), 60)
8+
util.less_than(util.setup('README.md'), 40)
99
util.num_marks(base_marks)
1010

11-
util.less_than(util.move_down(1), 20)
11+
util.less_than(util.move_down(1), 0.5)
1212
util.num_marks(base_marks + 2)
1313

14-
util.less_than(util.insert_mode(), 20)
14+
util.less_than(util.insert_mode(), 10)
1515
util.num_marks(base_marks + 2)
1616
end)
1717
end)

benches/util.lua

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,11 @@ end
3636
---@param callback fun()
3737
---@return number
3838
function M.time(callback)
39-
local start = vim.uv.hrtime()
4039
callback()
40+
local start_time = vim.uv.hrtime()
4141
vim.wait(0)
42-
return (vim.uv.hrtime() - start) / 1e+6
42+
local end_time = vim.uv.hrtime()
43+
return (end_time - start_time) / 1e+6
4344
end
4445

4546
---@private

lua/render-markdown/core/conceal.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,6 @@ function Conceal:compute()
138138
if parser == nil then
139139
return
140140
end
141-
self.context:parse(parser)
142141
parser:for_each_tree(function(tree, language_tree)
143142
self:compute_tree(language_tree:lang(), tree:root())
144143
end)

lua/render-markdown/core/ui.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ function M.update(buf, win, event, change)
107107
M.run_update(buf, win, change)
108108
end
109109
if parse and state.log_runtime then
110-
update = Env.runtime(update)
110+
update = Env.runtime('update', update)
111111
end
112112

113113
if parse and config.debounce > 0 then

lua/render-markdown/health.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ local state = require('render-markdown.state')
55
local M = {}
66

77
---@private
8-
M.version = '8.3.3'
8+
M.version = '8.3.4'
99

1010
function M.check()
1111
M.start('version')

lua/render-markdown/lib/env.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,17 @@ function M.file_size_mb(file)
4444
return stats.size / (1024 * 1024)
4545
end
4646

47+
---@param name string
4748
---@param callback fun()
4849
---@return fun()
49-
function M.runtime(callback)
50+
function M.runtime(name, callback)
5051
return function()
5152
local start_time = Compat.uv.hrtime()
5253
callback()
5354
local end_time = Compat.uv.hrtime()
5455
local elapsed = (end_time - start_time) / 1e+6
55-
vim.print(string.format('Runtime (ms): %.1f', elapsed))
56+
assert(elapsed < 1000)
57+
vim.print(string.format('%8s : %5.1f ms', name:upper(), elapsed))
5658
end
5759
end
5860

0 commit comments

Comments
 (0)