Commit 51160f1
fix(render): handle large messages when calculating line width (#283)
Some misbehaving plugin code was sending very large messages to
`vim.notify()`, which would trigger an exception when calculating the
max line width for rendering:
```
[...]/notify/render/default.lua:6: too many results to unpack
```
To fix this, I updated the implementation to calculate the max line
width in-place. This ultimately ends up being much more efficient because
it is not creating a new table with `vim.tbl_map()`.
Here's some benchmark data:
https://gist.github.com/flrgh/349aecd8ca35d20cf0526ec8b218657c
In the large input benchmarks, the new function is ~2x faster. For small
inputs (which are probably most common for `vim.notify()`), the speedup
is even larger at 3-4x.
Other changes:
1. I noticed the same snippet appeared in multiple render modules, so
I factored it out into `notify.util.max_line_width()` and added a
unit test
2. I updated the calculation to use `vim.api.nvim_strwidth()` when
available (see #247).
Co-authored-by: Rónán Carrigan <rcarriga@tcd.ie>1 parent 85b90b6 commit 51160f1
File tree
4 files changed
+35
-6
lines changed- lua/notify
- render
- util
- tests/unit
4 files changed
+35
-6
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | 6 | | |
6 | | - | |
7 | | - | |
8 | | - | |
| 7 | + | |
| 8 | + | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
3 | 4 | | |
4 | 5 | | |
5 | | - | |
6 | | - | |
7 | | - | |
| 6 | + | |
| 7 | + | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
| |||
117 | 119 | | |
118 | 120 | | |
119 | 121 | | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
120 | 137 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
181 | 181 | | |
182 | 182 | | |
183 | 183 | | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
184 | 196 | | |
185 | 197 | | |
186 | 198 | | |
| |||
0 commit comments