Skip to content

Commit dcfa033

Browse files
Create benches for performance testing, remove profiler
## Details Attempt to measure actual user latency by moving cursor around and changing modes in unit test. The profile option is no longer needed as this is a more robust way to see what's happening. Fix module annotation on unit tests by adding blank line.
1 parent b512df7 commit dcfa033

20 files changed

+78
-114
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@
99
interchangeable. Notice of deprecation has been available for a month since
1010
[726c85c](https://github.com/MeanderingProgrammer/markdown.nvim/commit/726c85cb9cc6d7d9c85af6ab093e1ee53b5e3c82).
1111
- Ultimately removed in TODO
12+
- Remove `profile` field in favor of benches [2f21726](https://github.com/MeanderingProgrammer/markdown.nvim/commit/2f217266c6b416c4948ddb7e88a5db02670c75d5)
13+
- In order to fix:
14+
- Implement `parse` method instead of `render`, no direct translation
15+
- `profile` field was only meant for development, should not have any users
1216

1317
### Bug Fixes
1418

README.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,6 @@ Some of the more useful fields are discussed further down.
122122
require('render-markdown').setup({
123123
-- Whether Markdown should be rendered by default or not
124124
enabled = true,
125-
-- Whether to track performance metrics, should only be used for development
126-
profile = false,
127125
-- Maximum file size (in MB) that this plugin will attempt to render
128126
-- Any file larger than this will effectively be ignored
129127
max_file_size = 1.5,

benches/medium_spec.lua

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
---@module 'luassert'
2+
3+
local util = require('tests.util')
4+
local eq = assert.are.same
5+
local truthy = assert.truthy
6+
7+
---@param f fun()
8+
---@return number
9+
local function time(f)
10+
local start_ns = vim.uv.hrtime()
11+
f()
12+
return (vim.uv.hrtime() - start_ns) / 1e+6
13+
end
14+
15+
---@param keys string
16+
local function feed(keys)
17+
local escape = vim.api.nvim_replace_termcodes(keys, true, false, true)
18+
vim.api.nvim_feedkeys(escape, 'nx', false)
19+
end
20+
21+
describe('medium.md', function()
22+
it('default', function()
23+
local start_time = time(function()
24+
util.setup('temp/medium.md')
25+
end)
26+
eq(2998, #util.get_actual_marks())
27+
28+
local move_time = time(function()
29+
feed('3j')
30+
-- Unsure why, but the CursorMoved event needs to be triggered manually
31+
vim.api.nvim_exec_autocmds('CursorMoved', {})
32+
vim.wait(0)
33+
end)
34+
eq(3000, #util.get_actual_marks())
35+
36+
local refresh_time = time(function()
37+
feed('i')
38+
vim.wait(0)
39+
end)
40+
eq(3000, #util.get_actual_marks())
41+
42+
truthy(start_time > 400 and start_time < 500, 'expected start time (400, 500)')
43+
truthy(refresh_time > 400 and refresh_time < 500, 'expected refresh time (400, 500)')
44+
truthy(move_time > 1 and move_time < 5, 'expected move time (1, 5)')
45+
end)
46+
end)

doc/render-markdown.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,6 @@ Full Default Configuration ~
154154
require('render-markdown').setup({
155155
-- Whether Markdown should be rendered by default or not
156156
enabled = true,
157-
-- Whether to track performance metrics, should only be used for development
158-
profile = false,
159157
-- Maximum file size (in MB) that this plugin will attempt to render
160158
-- Any file larger than this will effectively be ignored
161159
max_file_size = 1.5,

justfile

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,16 @@ init := "tests/minimal.lua"
33
default: update test health
44

55
test:
6+
just busted "tests"
7+
8+
bench:
9+
just gen-medium
10+
just busted "benches"
11+
12+
[private]
13+
busted directory:
614
nvim --headless --noplugin -u {{init}} \
7-
-c "PlenaryBustedDirectory tests { minimal_init = '{{init}}', sequential=true }"
15+
-c "PlenaryBustedDirectory {{directory}} { minimal_init = '{{init}}', sequential = true, keep_going = false }"
816

917
health:
1018
nvim -c "checkhealth render-markdown" -- .
@@ -52,13 +60,17 @@ cat-log:
5260
cat ~/.local/state/nvim/render-markdown.log
5361

5462
gen-medium:
55-
just gen-file "1000" > temp/medium.md
63+
just gen-file "1000" "temp/medium.md"
5664

5765
gen-large:
58-
just gen-file "100000" > temp/large.md
66+
just gen-file "100000" "temp/large.md"
67+
68+
[private]
69+
gen-file lines path:
70+
{{path_exists(path)}} || just gen-file-content {{lines}} > {{path}}
5971

6072
[private]
61-
gen-file lines:
73+
gen-file-content lines:
6274
#!/usr/bin/env python
6375
for i in range({{lines}}):
6476
level = "#" * ((i % 6) + 1)

lua/render-markdown/init.lua

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ local M = {}
107107

108108
---@class render.md.UserConfig
109109
---@field public enabled? boolean
110-
---@field public profile? boolean
111110
---@field public max_file_size? number
112111
---@field public markdown_query? string
113112
---@field public markdown_quote_query? string
@@ -137,8 +136,6 @@ local M = {}
137136
M.default_config = {
138137
-- Whether Markdown should be rendered by default or not
139138
enabled = true,
140-
-- Whether to track performance metrics, should only be used for development
141-
profile = false,
142139
-- Maximum file size (in MB) that this plugin will attempt to render
143140
-- Any file larger than this will effectively be ignored
144141
max_file_size = 1.5,

lua/render-markdown/profiler.lua

Lines changed: 0 additions & 84 deletions
This file was deleted.

lua/render-markdown/state.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ function state.validate()
7676
local config = state.config
7777
append_errors('render-markdown', config, {
7878
enabled = { config.enabled, 'boolean' },
79-
profile = { config.profile, 'boolean' },
8079
max_file_size = { config.max_file_size, 'number' },
8180
markdown_query = { config.markdown_query, 'string' },
8281
markdown_quote_query = { config.markdown_quote_query, 'string' },

lua/render-markdown/types.lua

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,6 @@
9494

9595
---@class render.md.Config
9696
---@field public enabled boolean
97-
---@field public profile boolean
9897
---@field public max_file_size number
9998
---@field public markdown_query string
10099
---@field public markdown_quote_query string

lua/render-markdown/ui.lua

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
local logger = require('render-markdown.logger')
2-
local profiler = require('render-markdown.profiler')
32
local state = require('render-markdown.state')
43
local util = require('render-markdown.util')
54

@@ -31,26 +30,19 @@ end
3130
function M.schedule_render(buf, parse)
3231
local mode = vim.fn.mode(true)
3332
vim.schedule(function()
34-
if state.config.profile then
35-
profiler.profile(buf, function()
36-
return M.render(buf, mode, parse)
37-
end)
38-
else
39-
M.render(buf, mode, parse)
40-
end
33+
M.render(buf, mode, parse)
4134
end)
4235
end
4336

4437
---@private
4538
---@param buf integer
4639
---@param mode string
4740
---@param parse boolean
48-
---@return 'invalid'|'disable'|'parsed'|'movement'
4941
function M.render(buf, mode, parse)
5042
-- Check that buffer and associated window are valid
5143
local win = util.buf_to_win(buf)
5244
if not vim.api.nvim_buf_is_valid(buf) or not vim.api.nvim_win_is_valid(win) then
53-
return 'invalid'
45+
return
5446
end
5547
vim.api.nvim_buf_clear_namespace(buf, M.namespace, 0, -1)
5648

@@ -59,7 +51,6 @@ function M.render(buf, mode, parse)
5951
for name, value in pairs(state.config.win_options) do
6052
util.set_win(win, name, value.default)
6153
end
62-
return 'disable'
6354
else
6455
-- Set window options to rendered & perform render
6556
for name, value in pairs(state.config.win_options) do
@@ -85,12 +76,6 @@ function M.render(buf, mode, parse)
8576
vim.api.nvim_buf_set_extmark(buf, M.namespace, mark.start_row, mark.start_col, mark.opts)
8677
end
8778
end
88-
89-
if parsed then
90-
return 'parsed'
91-
else
92-
return 'movement'
93-
end
9479
end
9580
end
9681

0 commit comments

Comments
 (0)