Skip to content

Commit ac319eb

Browse files
committed
fix(pick)!: increase default config.delay.async from 10 to 100
Details: - Having 10ms as a default ensures the smoothest async experience, since it results in essentially 100 FPS responsiveness. However, this is a bit too much for "force redraw during `getchar()`" and can result into constant 1-2% CPU load just when picker does nothing. This is the biggest load, but it adds up and can have visible effect if the picker is left open in the background after switching to a different process. - This also makes it "less smooth" of a feeling to type when the picker is busy. However, should still be good enough while consuming slightly less resources (due to less frequent checks). If it causes visible issues, the two more complex solutions here are: - Add new `config.delay.poke` to separate `async` for redraw and `check` for throttled poking. - Make upstream Neovim PR to allow `getchar()` / `getcharstr()` to not block redraw (at least behind the new option). Related to #2306
1 parent 0268c18 commit ac319eb

File tree

5 files changed

+17
-8
lines changed

5 files changed

+17
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ There are following change types:
6666

6767
- Allow `source.preview` to directly set another buffer into picker's main window. The recommended way is still to adjust the provided `buf_id` buffer, but there is now a workaround if this is not reasonably possible.
6868

69+
### Refine
70+
71+
- Increase default value `config.delay.async` from 10 to 100. This should reduce CPU load (as there will be less forced `:redraw` calls for every picker) while still being small enough to feel smooth typing when the picker is busy.
72+
6973
## mini.surround
7074

7175
### Expand

doc/mini-pick.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,7 @@ milliseconds of idle time.
207207
control over their side effects. As a result, regular mappings don't work
208208
here and picker's window needs to be current as long as it is shown.
209209
Changing window focus leads to automatic picker stop (after small delay).
210+
Not picker related redraws are forced every `config.delay.async` milliseconds.
210211
- Any picker is non-blocking but waits to return the chosen item. Example:
211212
`file = MiniPick.builtin.files()` allows other actions to be executed when
212213
picker is shown while still assigning `file` with value of the chosen item.
@@ -707,7 +708,7 @@ Defaults ~
707708
-- Delays (in ms; should be at least 1)
708709
delay = {
709710
-- Delay between forcing asynchronous behavior
710-
async = 10,
711+
async = 100,
711712

712713
-- Delay between computation start and visual feedback about it
713714
busy = 50,

lua/mini/pick.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@
203203
--- control over their side effects. As a result, regular mappings don't work
204204
--- here and picker's window needs to be current as long as it is shown.
205205
--- Changing window focus leads to automatic picker stop (after small delay).
206+
--- Not picker related redraws are forced every `config.delay.async` milliseconds.
206207
--- - Any picker is non-blocking but waits to return the chosen item. Example:
207208
--- `file = MiniPick.builtin.files()` allows other actions to be executed when
208209
--- picker is shown while still assigning `file` with value of the chosen item.
@@ -795,7 +796,7 @@ MiniPick.config = {
795796
-- Delays (in ms; should be at least 1)
796797
delay = {
797798
-- Delay between forcing asynchronous behavior
798-
async = 10,
799+
async = 100,
799800

800801
-- Delay between computation start and visual feedback about it
801802
busy = 50,

readmes/mini-pick.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ Here are code snippets for some common installation methods (use only one):
237237
-- Delays (in ms; should be at least 1)
238238
delay = {
239239
-- Delay between forcing asynchronous behavior
240-
async = 10,
240+
async = 100,
241241

242242
-- Delay between computation start and visual feedback about it
243243
busy = 50,

tests/test_pick.lua

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ T['setup()']['creates `config` field'] = function()
272272
-- Check default values
273273
local expect_config = function(field, value) eq(child.lua_get('MiniPick.config.' .. field), value) end
274274

275-
expect_config('delay.async', 10)
275+
expect_config('delay.async', 100)
276276
expect_config('delay.busy', 50)
277277

278278
expect_config('mappings.caret_left', '<Left>')
@@ -606,10 +606,12 @@ T['start()']['respects `source.items`'] = function()
606606
stop()
607607

608608
-- Problematic items
609-
child.lua_notify('_G.res = MiniPick.start({ source = { items = { vim.uv.new_timer() } } })')
610-
eq(child.lua_get('vim.tbl_map(type, MiniPick.get_picker_items())'), { 'userdata' })
611-
type_keys('<CR>')
612-
eq(child.lua_get('type(_G.res)'), 'userdata')
609+
if child.fn.has('nvim-0.10') == 1 then
610+
child.lua_notify('_G.res = MiniPick.start({ source = { items = { vim.uv.new_timer() } } })')
611+
eq(child.lua_get('vim.tbl_map(type, MiniPick.get_picker_items())'), { 'userdata' })
612+
type_keys('<CR>')
613+
eq(child.lua_get('type(_G.res)'), 'userdata')
614+
end
613615
end
614616

615617
T['start()']['correctly computes stritems'] = function()
@@ -1636,6 +1638,7 @@ end
16361638
T['default_preview()']['can be used in outside preview window'] = function()
16371639
-- This is not a module's capabilitiy per se, but something it should allow
16381640
local item = { path = real_file('b.txt'), lnum = 5, text = 'b.txt' }
1641+
child.lua('MiniPick.config.delay.async = 1')
16391642
start_with_items({ item })
16401643

16411644
local buf_id = child.api.nvim_create_buf(false, true)

0 commit comments

Comments
 (0)