New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tui: emit some termcodes later (after startup) #7664

Merged
merged 1 commit into from Dec 1, 2017

Conversation

Projects
None yet
1 participant
@justinmk
Member

justinmk commented Dec 1, 2017

For some reason, enabling focus reporting during terminal setup, causes
slow rendering during Nvim startup on tmux 2.3 with the tmux
focus-events option enabled.

To workaround that issue, this commit defers the request.

closes #7649

Using script to record the terminal session (and vterm-dump to
post-process the result):

BEFORE this commit:

./build/bin/nvim -u NONE{CR}{LF}
{DECSM 1049}{DECSM 1}{ESC =}
{CUP *}{ED 2}{DECSM 2004}{DECSM 1004}{CSI 8,44,156 t}{CSI * r}
{CUP 1,1}
{CUP *}{ED 2}{DECSM 25}
{DECRM 25}{CSI 2   q}{CSI 2   q}
{CUP *}{ED 2}{LF}
{ESC (B}{SGR *}{SGR 94}~                                                                                                                                                           {CR}{LF}
~                                                                                                                                                           {CR}{LF}

AFTER this commit:

./build/bin/nvim -u NONE{CR}{LF}
{DECSM 1049}{DECSM 1}{ESC =}
{CUP *}{ED 2}{CSI 8,44,156 t}{CSI * r}
{CUP 1,1}
{CUP *}{ED 2}{DECSM 2004}{DECSM 1004}{DECSM 25}
{DECRM 25}{CSI 2   q}{CSI 2   q}
{CUP *}{ED 2}{LF}
{ESC (B}{SGR *}{SGR 94}~                                                                                                                                                           {CR}{LF}
~                                                                                                                                                           {CR}{LF}
...
tui: emit some termcodes later (after startup)
For some reason, enabling focus reporting during terminal setup, causes
slow rendering during Nvim startup on tmux 2.3 with the tmux
`focus-events` option enabled.

To workaround that issue, this commit defers the request.

closes #7649

init.vim:
    call plug#begin('~/.config/nvim/plugged')
    Plug 'morhetz/gruvbox'
    call plug#end()
    set background=light " background light just to see the effect more quickly
    colorscheme gruvbox
.tmux.conf:
    set -g focus-events on
    set-option -ga terminal-overrides ",xterm-256color:Tc"
    set-option -g default-terminal "screen-256color"

Using `script` to record the terminal session (and `vterm-dump` to
post-process the result):

BEFORE this commit:
    ./build/bin/nvim -u NONE{CR}{LF}
    {DECSM 1049}{DECSM 1}{ESC =}
    {CUP *}{ED 2}{DECSM 2004}{DECSM 1004}{CSI 8,44,156 t}{CSI * r}
    {CUP 1,1}
    {CUP *}{ED 2}{DECSM 25}
    {DECRM 25}{CSI 2   q}{CSI 2   q}
    {CUP *}{ED 2}{LF}
    {ESC (B}{SGR *}{SGR 94}~                                                                                                                                                           {CR}{LF}
    ~                                                                                                                                                           {CR}{LF}

AFTER this commit:
    ./build/bin/nvim -u NONE{CR}{LF}
    {DECSM 1049}{DECSM 1}{ESC =}
    {CUP *}{ED 2}{CSI 8,44,156 t}{CSI * r}
    {CUP 1,1}
    {CUP *}{ED 2}{DECSM 2004}{DECSM 1004}{DECSM 25}
    {DECRM 25}{CSI 2   q}{CSI 2   q}
    {CUP *}{ED 2}{LF}
    {ESC (B}{SGR *}{SGR 94}~                                                                                                                                                           {CR}{LF}
    ~                                                                                                                                                           {CR}{LF}
    ...

@justinmk justinmk merged commit 27f9b1c into neovim:master Dec 1, 2017

2 of 4 checks passed

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
coverage/coveralls Coverage pending from Coveralls.io
Details
QuickBuild Build pr-7664 finished with status SUCCESSFUL
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details

@justinmk justinmk deleted the justinmk:tui-deferred-startup branch Dec 1, 2017

justinmk added a commit to justinmk/neovim that referenced this pull request Dec 2, 2017

tui.c: request focus-reporting (fix regression) neovim#7670
ref neovim#7649
ref neovim#7664

27f9b1c caused a regression: it uses loop_schedule_deferred() to
defer emitting the "enable focus reporting" termcode. tui_main() never
processes `tui_loop.events` (which loop_schedule_deferred() depends on),
so the event was never actually processed.

But fixing that (by processing `tui_loop.events`) would bring back the
problem 27f9b1c tried to fix: it still emits the event too soon.

Instead, do a little dance: schedule the event on `main_loop` and then
forward it to `tui_loop`.

NOTE: after this commit, in tmux 2.3 with `focus-events` enabled,
FocusGained is fired on startup and when resuming from suspend.

Using `script` to record the terminal session (and `vterm-dump` to
post-process the result):

BEFORE:
    {DECSM 1049}{DECSM 1}{ESC =}
    {CUP *}{ED *}{DECSM 2004}{DECSM 1004}{CSI 1,43 r}
    {CUP 1,1}
    {CUP *}{ED *}{SM 34}{DECSM 25}
    {DECRM 25}{CSI 2   q}{CSI 2   q}
    {CUP *}{ED *}{LF}
    {SGR *}{LS1}{SGR 94}~
    ...

AFTER:
    {CUP *}{ED *}{CSI 1,43 r}
    {CUP 1,1}
    {CUP *}{ED *}{SM 34}{DECSM 25}
    {DECRM 25}{CSI 2   q}{CSI 2   q}
    {CUP *}{ED *}{DECSM 2004}{DECSM 1004}{LF}
    {SGR *}{LS1}{SGR 94}~
    ...

justinmk added a commit to justinmk/neovim that referenced this pull request Dec 11, 2017

tui: rework deferred-termcodes implementation
Try another approach to defer the termcodes. Seems less janky, but still
not perfect.

ref neovim#7664
ref neovim#7649
ref neovim#7664
ref 27f9b1c

justinmk added a commit to justinmk/neovim that referenced this pull request Dec 12, 2017

tui: defer termcodes using a timer
With this implementation there is no "jank" during startup.

Using the main_loop in any fashion is janky. Using only the TUI loop
emits the termcodes too soon, or requires bad hacks like counting
tui_flush invocations (9 seems to work).

ref neovim#7664
ref neovim#7649
ref neovim#7664
ref 27f9b1c

justinmk added a commit to justinmk/neovim that referenced this pull request Dec 13, 2017

tui: rework deferred-termcodes implementation
Try another approach to defer the termcodes. Seems less janky, but still
not perfect.

ref neovim#7664
ref neovim#7649
ref neovim#7664
ref 27f9b1c

justinmk added a commit to justinmk/neovim that referenced this pull request Dec 13, 2017

tui: defer termcodes using a timer
With this implementation there is no "jank" during startup.

Using the main_loop in any fashion is janky. Using only the TUI loop
emits the termcodes too soon, or requires bad hacks like counting
tui_flush invocations (9 seems to work).

ref neovim#7664
ref neovim#7649
ref neovim#7664
ref 27f9b1c

justinmk added a commit to justinmk/neovim that referenced this pull request Dec 13, 2017

tui: rework deferred-termcodes implementation
Try another approach to defer the termcodes. Seems less janky, but still
not perfect.

ref neovim#7664
ref neovim#7649
ref neovim#7664
ref 27f9b1c

justinmk added a commit to justinmk/neovim that referenced this pull request Dec 13, 2017

tui: defer termcodes using a timer
With this implementation there is no "jank" during startup.

Using the main_loop in any fashion is janky. Using only the TUI loop
emits the termcodes too soon, or requires bad hacks like counting
tui_flush invocations (9 seems to work).

ref neovim#7664
ref neovim#7649
ref neovim#7664
ref 27f9b1c

justinmk added a commit to justinmk/neovim that referenced this pull request Dec 15, 2017

tui: rework deferred-termcodes ... again
- Revert timer-based approach.
- Instead, call loop_poll_events() with a timeout in an "active" loop,
  to infer that "TUI startup activity has mostly finished", but also to
  enforce a mininum time (100 ms) before emitting "enable focus
  reporting" termcode. (If TUI startup takes longer than that minimum
  time, it's probably a slow environment anyways.)
- Tickle `main_loop` by sending a dummy event.  Without this, the
  initial "focus-gained" response from the terminal may not get
  processed until the user hits a key.

ref neovim#7220
ref neovim#7664
ref neovim#7649
ref neovim#7664
ref 27f9b1c

justinmk added a commit to justinmk/neovim that referenced this pull request Dec 16, 2017

tui: rework deferred-termcodes ... again
- Revert timer-based approach.
- Instead, call loop_poll_events() with a timeout in an "active" loop,
  to infer that "TUI startup activity has mostly finished", but also to
  enforce a mininum time (100 ms) before emitting "enable focus
  reporting" termcode. (If TUI startup takes longer than that minimum
  time, it's probably a slow environment anyways.)
- Tickle `main_loop` by sending a dummy event.  Without this, the
  initial "focus-gained" response from the terminal may not get
  processed until the user hits a key.

ref neovim#7720
ref neovim#7664
ref neovim#7649
ref neovim#7664
ref 27f9b1c

justinmk added a commit to justinmk/neovim that referenced this pull request Dec 16, 2017

tui: rework deferred-termcodes ... again
- Revert timer-based approach.
- Instead, call loop_poll_events() with a timeout in an "active" loop,
  to infer that "TUI startup activity has mostly finished", but also to
  enforce a mininum time (100 ms) before emitting "enable focus
  reporting" termcode. (If TUI startup takes longer than that minimum
  time, it's probably a slow environment anyways.)
- Tickle `main_loop` by sending a dummy event.  Without this, the
  initial "focus-gained" response from the terminal may not get
  processed until the user hits a key.

ref neovim#7720
ref neovim#7664
ref neovim#7649
ref neovim#7664
ref 27f9b1c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment