Live data from Hacker News

Fixing stutters in Papers Please on Linux

blog.jhm.dev

51–60 of 202 posts

Re: Fixing stutters in Papers Please on Linux

#51

From the description of the problem (a freeze every 3 seconds) I knew exactly what it was. You can fix it by simply upgrading SDL as they fixed this bug 2 years ago. https://github.com/spurious/SDL-mirror/commit/59728f9802c786...

Why is udev not used in this case?

Because this is the fallback when you compile without udev support

Re: Fixing stutters in Papers Please on Linux

#52
post #8

Why is the engine even checking input devices so often? Shouldn't the input device be registered via settings and then assumed to exist when the game runs? It seems wasteful to check all input devices every few seconds.

SDL wants to support hotplugging where you can plug a controller in after you have already started the game.

Operating systems let you know when a device change has happened. You can even cache this where you pool the first time for the initial set of data and then you just check when a device is plugged in to update your knowledge of the state of the world.

I would imagine that’s what’s done if you’re running udev but maybe SDL doesn’t do that.

Re: Fixing stutters in Papers Please on Linux

#53
post #14
post #4

Earlier quoted context omitted.

This is one of the reasons I use Gentoo in my desktops: you can run a "stable" (as in old) system, but pull a more recent version of a library or application if you need it. For example, I remember having problems accessing files that I had stored in my mobile phone. Solution: updating libmtp and libmtp only. I suppose you can't do this in a distro such as Debian without upgrading half the packages. Are there more di…

If you are advanced enough to run Gentoo, you should be able to use Debian and force an install of (or re-compile yourself) a new package of the newer version, working around the fact that the official newer version would otherwise require other new packages.

You could. But the amount of time it takes is significantly more than yay -S or emerge vs the hell that this poses on Debian (not to mention the dependency hell you can run into)

Re: Fixing stutters in Papers Please on Linux

#54
post #8

Why is the engine even checking input devices so often? Shouldn't the input device be registered via settings and then assumed to exist when the game runs? It seems wasteful to check all input devices every few seconds.

SDL should probably use inotify() on linux so the kernel can let it know when /dev/input has changed rather than polling it.

SDL has three methods for detecting input devices [1]: udev, inotify, and, as a fallback, enumerating /dev/input.

It seems like Papers, Please uses a statically linked version of SDL, without udev or inotify support compiled in.

1: https://github.com/libsdl-org/SDL/blob/d0de4c625ad26ef540166...

Re: Fixing stutters in Papers Please on Linux

#55

Earlier quoted context omitted.

Why is udev not used in this case?

Because this is the fallback when you compile without udev support

I can guess that, but I was wondering why ... Is there a distro without udev? The steam/whatever sandbox does not support udev?

Re: Fixing stutters in Papers Please on Linux

#56
post #7

The issue has been identified before, but seems like it stalled: https://gitlab.freedesktop.org/libinput/libinput/-/issues/50... , https://patchwork.kernel.org/project/linux-input/patch/20201... .

What the proposed patch does is delay a specific latent operation to an asynchronous context so that close() doesn’t block on that operation (which is freeing some memory).

The proposed patch isn’t a comprehensive fix, it admits there are still other sources of relatively high close() latency.

So that got me thinking, there is no way to fix this “bug” because there is no specification on how long close() should take to complete. As far as we are promised in user-land, close() is not an instantaneous operation. close() is a blocking operation! Even worse, it’s an IO operation.

So now I think the bug is in the application. If you want to avoid the latency of close() you should do it asynchronously in another thread. This is similar to the rule that you should not do blocking IO on the main thread in an event-loop based application.

Re: Fixing stutters in Papers Please on Linux

#57

Earlier quoted context omitted.

A lot of games will automatically switch between keyboard and gamepad when a gamepad is connected. Perhaps this is some automatic background function that SDL handles.

Windows uses a similar polling-based approach, with a warning that you shouldn't poll for new gamepads every frame for performance reasons: https://docs.microsoft.com/en-us/windows/win32/xinput/gettin... In general, "notifying the program when a new device has become available" seems to be a surprisingly difficult problem. I've encountered trouble with multiple device types across multiple platforms.

There’s a reason Plug’n’Play and USB were big deals back then. The concept of plugging in a new peripheral and it just working, without rebooting, was rather revolutionary. Even though the former was more aptly called “Plug’n’Pray” in the early years…

Re: Fixing stutters in Papers Please on Linux

#58

Earlier quoted context omitted.

SDL wants to support hotplugging where you can plug a controller in after you have already started the game.

Operating systems let you know when a device change has happened. You can even cache this where you pool the first time for the initial set of data and then you just check when a device is plugged in to update your knowledge of the state of the world. I would imagine that’s what’s done if you’re running udev but maybe SDL doesn’t do that.

As has been noted in another subthread, SDL can do this but apparently the particular statically linked version shipped with Papers Please is compiled without udev or inotify support and has to fallback to manual checking.

Re: Fixing stutters in Papers Please on Linux

#59

Earlier quoted context omitted.

From one of the printouts in the post, it seems that Papers Please is using a bundled and statically linked SDL. So it would be the game developer that would have to update the version of the SDL library. The binary patching done seems like a good-enough alternative in the meantime. I have the feeling such bundling of dependencies is fairly common when porting games for Linux.

SDL has its own "dynapi" layer, where you can override it with your own copy of SDL even if it was statically linked: https://github.com/libsdl-org/SDL/blob/main/docs/README-dyna...

Just pray they didn't alter SDL like factorio does: https://news.ycombinator.com/item?id=27246164

Re: Fixing stutters in Papers Please on Linux

#60

Wait, why is `close` in libpthread.so?

I believe that a few libc functions are reimplemented in libpthread, the idea being that if you don’t link to pthreads, you don’t need the overhead (locking, etc.) that is needed in multithreaded situations. Feels a bit antiquated now…

As for why close specifically though, that’s a good question. I wonder if it has something to do with special libc treatment of the standard fds or anything like that.

Post reply on HN