perf: Steam's web helper runs its GPU, audio and zygote work inside one process (#566)

This commit is contained in:
Kurt Himebauch authored and GitHub committed 2026-10-14 01:01:49 -04:00
1 parent 6211faf6bc
commit 3fe03c0a88
5 files changed
+151 -5

No files matched your search

+1 -1
View File
@@ -60,7 +60,7 @@ class BinfmtPreloadTest(unittest.TestCase):
cls.library = cls.tmp / "libbinfmt.so"
subprocess.run(["gcc", "-shared", "-fPIC", "-O2", "-Wall", "-Wextra", "-Werror", "-DBINFMT_TEST",
'-DBINFMT_HANDLER="%s"' % cls.handler, "-o", str(cls.library),
"-pthread"] + [str(PRELOAD / name) for name in ("binfmt.c", "net.c", "udevmon.c", "pathcache.c")] + ["-ldl"],
"-pthread"] + [str(PRELOAD / name) for name in ("binfmt.c", "net.c", "udevmon.c", "pathcache.c", "webhelper.c")] + ["-ldl"],
check=True)
source = cls.tmp / "program.c"
source.write_text(PROGRAM)
+1 -1
View File
@@ -16,7 +16,7 @@ class CdpGuardTest(unittest.TestCase):
def setUpClass(cls):
cls.build = tempfile.TemporaryDirectory()
cls.library = Path(cls.build.name) / "net.so"
subprocess.run(["cc", "-shared", "-fPIC", "-O2", str(SOURCE), str(SOURCE.parent / "binfmt.c"), "-x", "c", "-", "-ldl",
subprocess.run(["cc", "-shared", "-fPIC", "-O2", str(SOURCE), str(SOURCE.parent / "binfmt.c"), str(SOURCE.parent / "webhelper.c"), "-x", "c", "-", "-ldl",
"-o", str(cls.library)],
input=b"int bl_udevmon_stand_in(int fd) { return 0; }", check=True, capture_output=True)
+69
View File
@@ -0,0 +1,69 @@
import os
from pathlib import Path
import shutil
import subprocess
import tempfile
import unittest
PRELOAD = Path(__file__).resolve().parents[1] / "linuxfs/preload"
PROGRAM = r"""
#include <stdio.h>
char *const *bl_webhelper_argv(const char *path, char *const argv[]);
int main(int argc, char **argv) {
char *const *out = bl_webhelper_argv(argv[1], argv + 1);
for (int i = 0; out[i]; i++) printf("%s\n", out[i]);
return 0;
}
"""
WEBHELPER = "/root/.local/share/Steam/steamrtarm64/steamwebhelper"
@unittest.skipUnless(shutil.which("cc"), "needs cc")
class WebhelperPreloadTest(unittest.TestCase):
@classmethod
def setUpClass(cls):
cls.tmp = Path(tempfile.mkdtemp())
source = cls.tmp / "program.c"
source.write_text(PROGRAM)
cls.program = cls.tmp / "program"
subprocess.run(["cc", "-O2", "-Wall", "-Werror", "-o", str(cls.program), str(source),
str(PRELOAD / "webhelper.c")], check=True)
@classmethod
def tearDownClass(cls):
shutil.rmtree(cls.tmp, ignore_errors=True)
def argv(self, *args, spec=None):
env = {k: v for k, v in os.environ.items() if k != "BL_WEBHELPER_ARGS"}
if spec is not None:
env["BL_WEBHELPER_ARGS"] = spec
result = subprocess.run([str(self.program), *args], env=env, capture_output=True, text=True, check=True)
return result.stdout.splitlines()
def test_the_browser_process_keeps_its_helpers_in_process(self):
out = self.argv(WEBHELPER, "-lang=en_US", "--enable-features=A", "--no-sandbox", "--disable-features=B,C")
self.assertEqual(out, [WEBHELPER, "-lang=en_US", "--no-sandbox", "--no-zygote", "--in-process-gpu",
"--enable-features=A", "--disable-features=B,C,AudioServiceOutOfProcess"])
def test_feature_lists_are_added_when_steam_passes_none(self):
out = self.argv(WEBHELPER, spec="+X -Y")
self.assertEqual(out, [WEBHELPER, "--enable-features=X", "--disable-features=Y"])
def test_child_processes_and_other_programs_are_left_alone(self):
child = [WEBHELPER, "--type=renderer", "--enable-features=A"]
self.assertEqual(self.argv(*child), child)
other = ["/usr/bin/steam", "--enable-features=A"]
self.assertEqual(self.argv(*other), other)
def test_stock_turns_it_off(self):
args = [WEBHELPER, "--enable-features=A"]
self.assertEqual(self.argv(*args, spec="stock"), args)
def test_an_empty_setting_means_the_default(self):
self.assertIn("--no-zygote", self.argv(WEBHELPER, spec=""))
if __name__ == "__main__":
unittest.main()