dnkl/foot
41
2.0k
Fork
You've already forked foot
243

Text reflow is too slow #504

Closed
opened 2021年05月10日 19:52:54 +02:00 by dnkl · 5 comments
Owner
Copy link

Run (削除) ls --hyperlink=always /usr/bin (削除ここまで) ls /use/bin a couple of times, then grab the corner of the terminal window and resize the window back and forth. It is slow. Or if initially fast, gets slower and slower and slower.

(削除) The reason is the inefficient remapping of OSC-8 start and endpoints when reflowing text. (削除ここまで)

Labling as a bug, because this is just too slow.

Run ~~`ls --hyperlink=always /usr/bin`~~ `ls /use/bin` a couple of times, then grab the corner of the terminal window and resize the window back and forth. It is _slow_. Or if initially fast, gets slower and slower and slower. ~~The reason is the inefficient remapping of OSC-8 start and endpoints when reflowing text.~~ Labling as a bug, because this is just too slow.
dnkl changed title from (削除) OSC-8 hyperlinks makes text reflow slooow (削除ここまで) to Text reflow is too slow 2021年05月11日 10:18:28 +02:00
Author
Owner
Copy link

While OSC-8 doesn't make things faster, reflow is way too slow even without them.

This needs to be addressed.

While OSC-8 doesn't make things faster, reflow is way too slow even without them. This needs to be addressed.
Author
Owner
Copy link

wcwidth() is a major issue here.

We should be able to avoid
it completely and use our SPACERs instead.

`wcwidth()` is a major issue here. We should be able to avoid it completely and use our SPACERs instead.
Author
Owner
Copy link

I think there are several things that needs to be done here, but the first one should be getting rid of wcwidth().

The way to do this is by using CELL_MULT_COL_SPACER. Unfortunately, we cannot do that as of today. It is used in two ways: first, it's printed after a multi-column character, as a sort of padding (also makes it possible to detect multi-column characters given a random cell in the grid). But it is also used as padding before multi-column characters, as padding, to ensure a multi-column character isn't printed on/over the right margin.

This makes it very difficult to use it while reflowing the grid.

I think the best way to solve this is by redefining CELL_MULT_COL_SPACER, from a single value, to being a base value, to which we add the number of remaining spacers, including itself.

So if we have a character whose wcwidth is 4, we'd print <c> <4> <3> <2> <1>. The pre-pad variant could use the base value itself. So if the application prints a double-width character in the last column, what we'd actually end up printing is:

 <0>
<c> <1>

That way, we always know what a spacer means. And then we should be able to use this instead of having to call wcwidth() while reflowing the grid.

And please rename it to CELL_SPACER!

Next, the reflow logic currently "collects" empty cells, and only emits them under certain conditions. However, when we do emit them, they are treated as regular cells. I.e. we run lots of logic that inspects the Unicode point and does multi-column handling. This is completely unnecessary; we know all the properties of an empty cell. Make use of this.

After that, we can start looking at the handling of URIs, and tracking points in general.

I think there are several things that needs to be done here, but the first one should be getting rid of `wcwidth()`. The way to do this is by using `CELL_MULT_COL_SPACER`. Unfortunately, we cannot do that as of today. It is used in two ways: first, it's printed **after** a multi-column character, as a sort of padding (also makes it possible to detect multi-column characters given a random cell in the grid). But it is also used as padding **before** multi-column characters, as padding, to ensure a multi-column character isn't printed on/over the right margin. This makes it very difficult to use it while reflowing the grid. I think the best way to solve this is by redefining `CELL_MULT_COL_SPACER`, from a single value, to being a base value, to which we add the number of remaining spacers, including itself. So if we have a character whose wcwidth is 4, we'd print `<c> <4> <3> <2> <1>`. The pre-pad variant could use the base value itself. So if the application prints a double-width character in the last column, what we'd actually end up printing is: ``` <0> <c> <1> ``` That way, we always know what a spacer _means_. And then we should be able to use this instead of having to call `wcwidth()` while reflowing the grid. And please rename it to `CELL_SPACER`! Next, the reflow logic currently "collects" empty cells, and only emits them under certain conditions. However, when we _do_ emit them, they are treated as regular cells. I.e. we run lots of logic that inspects the Unicode point and does multi-column handling. This is completely unnecessary; we **know** all the properties of an empty cell. Make use of this. After that, we can start looking at the handling of URIs, and tracking points in general.
dnkl added this to the 1.8.0 milestone 2021年05月27日 09:40:52 +02:00
Author
Owner
Copy link

With all the PRs above applied (1, 2, 3, and the not-yet-merged 4), reflow times have gone from:

  • 16K scrollback, lots of OSC-8 URIs: ~40ms → 15ms
  • 16K scrollback, no OSC-8 URIs: ~22ms → 7ms

This is very unscientific. I'm just filling the scrollback with while true; do ls --hyperlink=always /usr/bin; done, and while true; do ls --hyperlink=none /usr/bin; done respectively, and then manually resizing window, in roughly the same way.

The times mentioned above are "visual" means. That is; I'm looking at a long list of reflow times and picking what appears to be the mean value.

With all the PRs above applied (1, 2, 3, and the not-yet-merged 4), reflow times have gone from: * 16K scrollback, **lots** of OSC-8 URIs: ~40ms → 15ms * 16K scrollback, **no** OSC-8 URIs: ~22ms → 7ms This is very unscientific. I'm just filling the scrollback with `while true; do ls --hyperlink=always /usr/bin; done`, and `while true; do ls --hyperlink=none /usr/bin; done` respectively, and then manually resizing window, in roughly the same way. The times mentioned above are "visual" means. That is; I'm looking at a long list of reflow times and picking what appears to be the mean value.
Author
Owner
Copy link

OSC-less output is now reflowed in what I'd say are very reasonable times. OSC-filled output is still sluggish on slower systems, but at least much better than before.

OSC-less output is now reflowed in what I'd say are very reasonable times. OSC-filled output is still sluggish on slower systems, but at least much better than before.
Sign in to join this conversation.
No Branch/Tag specified
master
osc-5522
sixel-heap-buffer-overflow
releases/1.27
releases/1.26
releases/1.25
releases/1.24
multi-cursor
releases/1.23
pixman-16f-2
releases/1.22
releases/1.21
releases/1.20
releases/1.19
releases/1.18
releases/1.17
releases/1.16
releases/1.15
releases/1.14
releases/1.13
releases/1.12
releases/1.11
releases/1.10
releases/1.9
releases/1.8
releases/1.7
releases/1.6
releases/1.5
releases/1.4
releases/1.3
releases/1.2
releases/1.1
releases/1.0
1.27.0
1.26.1
1.26.0
1.25.0
1.24.0
1.23.1
1.23.0
1.22.3
1.22.2
1.22.1
1.22.0
1.21.0
1.20.2
1.20.1
1.20.0
1.19.0
1.18.1
1.18.0
1.17.2
1.17.1
1.17.0
1.16.2
1.16.1
1.16.0
1.15.3
1.15.2
1.15.1
1.15.0
1.14.0
1.13.1
1.13.0
1.12.1
1.12.0
1.11.0
1.10.3
1.10.2
1.10.1
1.10.0
1.9.2
1.9.1
1.9.0
1.8.2
1.8.1
1.8.0
1.7.2
1.7.1
1.7.0
1.6.4
1.6.3
1.6.2
1.6.1
1.6.0
1.5.4
1.5.3
1.5.2
1.5.1
1.5.0
1.4.4
1.4.3
1.4.2
1.4.1
1.4.0
1.3.0
1.2.3
1.2.2
1.2.1
1.2.0
1.1.0
1.0.0
0.9.0
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
dnkl/foot#504
Reference in a new issue
dnkl/foot
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?