Skip to content
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

Significant input latency when processing output command even if no-op #6280

Open
pedrocr opened this issue May 18, 2021 · 3 comments
Open
Labels
bug Not working as intended

Comments

@pedrocr
Copy link
Contributor

pedrocr commented May 18, 2021

There is something in sway that creates significant input latency when output commands run, even if they're actually no-ops. To reproduce:

  • Start a new sway session with the default config
  • Run in a terminal while true; do sleep 1; swaymsg "output * dpms on"; done
  • Move the mouse or do some typing and notice the latency spikes whenever the output command runs

I noticed this because I had the following swayidle setup:

exec swayidle -w before-sleep '$lock' \
  timeout 5 'if pgrep --uid $(whoami) swaylock; then swaymsg "output * dpms off"; fi'\
  resume 'swaymsg "output * dpms on"'\

This results in very noticeable latency when typing or moving the mouse at any moment after 5 seconds as it runs the dpms on command unconditionally expecting it to be a no-op. It's common to see these kinds of warnings in the logs because of this:

[ERROR] client bug: timer event5 trackpoint: scheduled expiry is in the past (-91ms), your system is too slow

And the pointer lag is very noticeable because of this.

Edit: removed the part about XWayland. Although the presence of XWayland increases the latency it was already there before that. The problem is the output command not ending up as a no-op and reconfiguring inputs instead.

@pedrocr pedrocr added the bug Not working as intended label May 18, 2021
@pedrocr
Copy link
Contributor Author

pedrocr commented May 18, 2021

Seems like the input reconfigure is happening here:

sway/sway/config/output.c

Lines 482 to 489 in 12e223e

// Reconfigure all devices, since input config may have been applied before
// this output came online, and some config items (like map_to_output) are
// dependent on an output being present.
input_manager_configure_all_inputs();
// Reconfigure the cursor images, since the scale may have changed.
input_manager_configure_xcursor();
return true;
}

and it happens because nothing in the output command chain avoids no-op changes and this input reconfigure is unconditional. From the discussion around #5629 I think assuming this for the wlroots changes is fine as they will be no-ops down in the wlroots code but the sway part of the output config will still run and cause this kind of side effect.

A potential solution for this would be to keep a struct output_config current_config; in struct sway_output and bail out early from apply_output_config() if the new config is the same as the old one.

pedrocr added a commit to pedrocr/sway that referenced this issue May 18, 2021
When an output command doesn't actually change anything in the output
config the processing will still all be done and cause other changes.
Notably if you run a command like:

	output * dpms on

even if it does nothing it will still cause all the inputs to be
reconfigured and very noticeable amounts of input latency to occur.

To fix this save the current output config in the output data and on
configure, if the config is the same just return without doing anything
else.

Fixes swaywm#6280
pedrocr added a commit to pedrocr/sway that referenced this issue May 18, 2021
When an output command doesn't actually change anything in the output
config the processing will still all be done and cause other changes.
Notably if you run a command like:

	output * dpms on

even if it does nothing it will still cause all the inputs to be
reconfigured and very noticeable amounts of input latency to occur.

To fix this save the current output config in the output data and on
configure, if the config is the same just return without doing anything
else.

Fixes swaywm#6280
@mstoeckl
Copy link
Contributor

mstoeckl commented May 19, 2021

It may also be helpful to understand what makes input_manager_configure_all_inputs(); slow, specifically. Running while true; do sleep 1; swaymsg "output * dpms on"; done, and looking at the debug logs for a terminal, I see each reconfigure sends the same keymap, 8 times each, even though nothing has changed. This happens for every client.

[1180301.653] [email protected](1, fd 14, 53374)
[1180305.868] [email protected]_info(26, 599)
[1180305.896] [email protected](1, fd 15, 53374)
[1180309.988] [email protected]_info(26, 599)
[1180310.051] [email protected](1, fd 16, 53374)
[1180314.103] [email protected]_info(26, 599)
[1180315.415] [email protected](1, fd 17, 53374)
[1180334.764] [email protected]_info(26, 599)
[1180334.850] [email protected](1, fd 18, 53374)
[1180339.043] [email protected]_info(26, 599)
[1180349.525] [email protected](1, fd 19, 53374)
[1180353.956] [email protected]_info(26, 599)
[1180354.021] [email protected](1, fd 20, 53374)
[1180357.837] [email protected]_info(26, 599)
[1180731.594] [email protected](1, fd 14, 53374)
[1180743.227] [email protected]_info(26, 599)

@rpigott
Copy link
Member

rpigott commented May 19, 2021

That would be one per keyboard input device, I guess.

pedrocr added a commit to pedrocr/sway that referenced this issue May 19, 2021
When an output command doesn't actually change anything in the output
config the processing will still all be done and cause other changes.
Notably if you run a command like:

	output * dpms on

even if it does nothing it will still cause all the inputs to be
reconfigured and very noticeable amounts of input latency to occur.

To fix this save the current output config in the output data and on
configure, if the config is the same just return without doing anything
else.

Fixes swaywm#6280
pedrocr added a commit to pedrocr/sway that referenced this issue May 19, 2021
When an output command doesn't actually change anything in the output
config the processing will still all be done and cause other changes.
Notably if you run a command like:

	output * dpms on

even if it does nothing it will still cause all the inputs to be
reconfigured and very noticeable amounts of input latency to occur.

To fix this save the current output config in the output data and on
configure, if the config is the same just return without doing anything
else.

Fixes swaywm#6280
pedrocr added a commit to pedrocr/sway that referenced this issue May 19, 2021
When an output command doesn't actually change anything in the output
config the processing will still all be done and cause other changes.
Notably if you run a command like:

	output * dpms on

even if it does nothing it will still cause all the inputs to be
reconfigured and very noticeable amounts of input latency to occur.

To fix this save the current output config in the output data and on
configure, if the config is the same just return without doing anything
else.

Fixes swaywm#6280
pedrocr added a commit to pedrocr/sway that referenced this issue May 19, 2021
When an output command doesn't actually change anything in the output
config the processing will still all be done and cause other changes.
Notably if you run a command like:

	output * dpms on

even if it does nothing it will still cause all the inputs to be
reconfigured and very noticeable amounts of input latency to occur.

To fix this save the current output config in the output data and on
configure, if the config is the same just return without doing anything
else.

Fixes swaywm#6280
pedrocr added a commit to pedrocr/sway that referenced this issue May 19, 2021
When an output command doesn't actually change anything in the output
config the processing will still all be done and cause other changes.
Notably if you run a command like:

	output * dpms on

even if it does nothing it will still cause all the inputs to be
reconfigured and very noticeable amounts of input latency to occur.

To fix this save the current output config in the output data and on
configure, if the config is the same just return without doing anything
else.

Fixes swaywm#6280
pedrocr added a commit to pedrocr/sway that referenced this issue Jul 10, 2021
When an output command doesn't actually change anything in the output
config the processing will still all be done and cause other changes.
Notably if you run a command like:

	output * dpms on

even if it does nothing it will still cause all the inputs to be
reconfigured and very noticeable amounts of input latency to occur.

To fix this save the current output config in the output data and on
configure, if the config is the same just return without doing anything
else.

Fixes swaywm#6280
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Not working as intended
Development

No branches or pull requests

3 participants