perf(prof): the Linux samplers name frames from the loaded objects' segments, read once, not dladdr #3155

Merged
HumanBean merged 2 commits from decohered/Longshot:perf/sampler-module-spans into main 2026-12-04 06:49:55 +00:00
Contributor

Summary

Using the slow-frame recorder (which samples every 4ms), the Linux samplers spent 13.9% of the process's CPU samples on my Steam Machine just doing dladdr to name frames.

  • dladdr takes the loader's lock and walks the object's exported symbols, for every frame of every sample (14,500 of them in longshot_vk.so)

Now we have a table of all the loaded objects, sorted by their segments, and we can use binary search to find the module for any given frame. If we encounter an address that isn't in our table, we read it again, but we'll only do this once per second at most.

  • A module gets one of the sample keys' 63 slots only when a frame is found in it, so the slots are the modules sampled; slot 63 stays "?"
  • A hit on a table read a second ago or more looks at the loader's counts of objects loaded and unloaded, and reads the table again when they changed
  • HOS_SLOW_FRAMES_EVERY_MS is read from the environment once, too; the sampler asked for it every sweep

Start with module_of in host/posix/prof.c, then tests/test_prof_modules.py.

Testing

Tested: I've had this in every build I've played on my Steam Machine since. The slow-frame files name their frames the same as they used to.

  • Steam Machine: Navi 33 8 GB, SteamOS 3.10.1, kernel 7.3.1-valve3

  • tests/test_prof_modules.py, tests/test_prof_walk_fault.py, tests/test_slow_frames.py and tests/test_profiling_mode.py pass with gcc and clang

  • After review (5a469b911), tests/test_prof_modules.py also unloads a library and loads another, perhaps where it was, and loads 70 objects; the code before it fails the unload

  • The game builds whole at 5a469b911 on Linux.

  • mise run test on Linux at 095ca3866: 863 pass, 13 skip (Windows only or a device it needs), 19 fail. The same 19 fail on main @ 299ed5b70 with the same tools (the toolchain from nixpkgs; mise's pinned one isn't set up here), so none come from this change.

    The 19

    byte_compile_tracked, f2i_immediate, global_load_16, native_suatom, test_check_cache, test_checks_container, test_cloth_kernels, test_dav1d_av1, test_fsr_uniform_ownership, test_game_module_imports, test_lifter, test_lifter_semantics, test_linux_pressure, test_loaded_modules_drop, test_native_zstd, test_program_cache_cleanup, test_program_cache_one_variant, test_thinlto_tls, test_ui_renderer

Still to test:

  • None: the samplers are Linux-only, and Tested covers Linux.

Measurements

Verdict: Naming a frame no longer calls dladdr, which took 13.9% of the process's CPU samples on my Steam Machine with the slow-frame recorder on.

Before: main @ 299ed5b70 After: this PR @ 095ca3866
dladdr calls to name a frame 1 0

Risks

If a library is loaded after the table was read, it will be picked up on the next miss, so a frame in it might be unnamed for up to a second. Players will never see this though, since the samplers only run when the profiler or slow-frame recorder is active.

  • A library unloaded is still named for its old span until the next look at the loader's counts, a second at most

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named).
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A check under tests/ that reads changed source is updated, not weakened.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

🤖 Generated with Claude Code

## Summary Using the slow-frame recorder (which samples every 4ms), the Linux samplers spent 13.9% of the process's CPU samples on my Steam Machine just doing dladdr to name frames. - `dladdr` takes the loader's lock and walks the object's exported symbols, for every frame of every sample (14,500 of them in `longshot_vk.so`) Now we have a table of all the loaded objects, sorted by their segments, and we can use binary search to find the module for any given frame. If we encounter an address that isn't in our table, we read it again, but we'll only do this once per second at most. - A module gets one of the sample keys' 63 slots only when a frame is found in it, so the slots are the modules sampled; slot 63 stays "?" - A hit on a table read a second ago or more looks at the loader's counts of objects loaded and unloaded, and reads the table again when they changed - `HOS_SLOW_FRAMES_EVERY_MS` is read from the environment once, too; the sampler asked for it every sweep Start with `module_of` in `host/posix/prof.c`, then `tests/test_prof_modules.py`. ## Testing **Tested:** I've had this in every build I've played on my Steam Machine since. The slow-frame files name their frames the same as they used to. - Steam Machine: Navi 33 8 GB, SteamOS 3.10.1, kernel 7.3.1-valve3 - `tests/test_prof_modules.py`, `tests/test_prof_walk_fault.py`, `tests/test_slow_frames.py` and `tests/test_profiling_mode.py` pass with gcc and clang - After review (5a469b911), `tests/test_prof_modules.py` also unloads a library and loads another, perhaps where it was, and loads 70 objects; the code before it fails the unload - The game builds whole at 5a469b911 on Linux. - `mise run test` on Linux at 095ca3866: 863 pass, 13 skip (Windows only or a device it needs), 19 fail. The same 19 fail on main @ 299ed5b70 with the same tools (the toolchain from nixpkgs; mise's pinned one isn't set up here), so none come from this change. <details><summary>The 19</summary> byte_compile_tracked, f2i_immediate, global_load_16, native_suatom, test_check_cache, test_checks_container, test_cloth_kernels, test_dav1d_av1, test_fsr_uniform_ownership, test_game_module_imports, test_lifter, test_lifter_semantics, test_linux_pressure, test_loaded_modules_drop, test_native_zstd, test_program_cache_cleanup, test_program_cache_one_variant, test_thinlto_tls, test_ui_renderer </details> **Still to test:** - None: the samplers are Linux-only, and Tested covers Linux. ## Measurements **Verdict:** Naming a frame no longer calls `dladdr`, which took 13.9% of the process's CPU samples on my Steam Machine with the slow-frame recorder on. | | Before: main @ 299ed5b70 | After: this PR @ 095ca3866 | |---|---|---| | `dladdr` calls to name a frame | 1 | 0 | ## Risks If a library is loaded after the table was read, it will be picked up on the next miss, so a frame in it might be unnamed for up to a second. Players will never see this though, since the samplers only run when the profiler or slow-frame recorder is active. - A library unloaded is still named for its old span until the next look at the loader's counts, a second at most ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [x] `mise run test` passes (any failure that also fails on `main` is named). - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A check under `tests/` that reads changed source is updated, not weakened. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
perf(prof): the Linux samplers name frames from the loaded objects' segments, read once, not dladdr
Some checks failed
PR description / Title and description (pull_request_target) Has been cancelled
CI / What the change needs (pull_request) Has been cancelled
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Has been cancelled
CI / Third-party parts and guide screenshots (pull_request) Has been cancelled
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Has been cancelled
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Has been cancelled
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Has been cancelled
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Has been cancelled
CI / Website build and checks (pull_request) Has been cancelled
095ca38663
module_of called dladdr for every frame of every sample: the loader's lock and
a walk of the object's exported symbols (14,500 in longshot_vk.so). With the
slow-frame recorder's sweep every 4 ms that was 13.9% of the process's CPU
samples on the Steam Machine. The loaded objects' segments are now read once
with dl_iterate_phdr into a sorted table and looked up by binary search; an
address in no object reads them again at most once a second. The sweep's
interval is read from the environment once.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Fable 5.2 <[email protected]>
Owner
@review
BeanBot left a comment

Recommendation: Request changes. The module cache can misidentify frames after libraries are unloaded or replaced, and its fixed capacity can leave sampled modules unnamed. The new test also cannot run on Windows; the claimed performance gain remains unmeasured against the base.

The change replaces per-frame Linux dladdr calls with a cached segment lookup and caches the slow-frame sampling interval. It reduces repeated lookup work, but introduces module-lifetime and capacity problems in diagnostic output.

Blocking (3): must change before merging.

  1. L1 host/posix/prof.c:311: A cache hit never checks whether the object has been unloaded or replaced, and module_add also reuses an old name solely by base address. (more on the line) Do: Track loader changes and rebuild the active spans and module identities when objects are loaded or unloaded, while preserving any identities needed by accumulated samples. Add an unload and address-reuse test.
  2. L2 host/posix/prof.c:273: The first enumeration consumes the 64 module slots for every loaded object, including objects that are never sampled, and slots are never reclaimed. (more on the line) Do: Use a dynamically sized active-object table or otherwise ensure every loaded segment can be represented; test with more than 64 loaded objects and a late-loaded object.
  3. L5 tests/test_prof_modules.py:20: The Linux-only test is discovered on Windows without a platform skip and attempts to compile and run a program using Linux dynamic-loader headers and APIs. (more on the line) Do: Declare a Windows RUN_ALL_SKIP and guard direct invocation on unsupported platforms, as the other Linux sampler test does.

Should fix (3): not blocking, but worth doing before merging.

  • L3 host/posix/prof.c:264: The 64th module collides with the sampler's existing unknown-module sentinel, index 63. (more on the line) Do: Use a distinct sentinel in the sample key or reserve index 63, and test an unknown frame when the table is full.
  • L4 host/posix/prof.c:278: The mutex protects writes to nmods, but the periodic HOS_SAMPLE report reads nmods without that mutex while another sampler or HOS_WATCH can refresh the table. (more on the line) Do: Protect the report's module-table reads with the same mutex, or publish an immutable snapshot with proper synchronization.
  • L6 tests/test_prof_modules.py:96: Direct test runs ignore CC, and compiler commands containing arguments are passed as one executable name. (more on the line) Do: Default to CC when set and parse the compiler command using the repository's compiler-command helper before appending the flags.

Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)

  • L7: The reported reduction in calls does not quantify the performance benefit or the effect of the new locked lookup and refreshes on sampling and frame pacing. When: With slow-frame recording enabled, each frame lookup now takes a mutex and misses can enumerate and sort all loaded segments. The PR provides no comparable after-run showing the net CPU or frame-time effect. Do: Measure base and head on the same Linux scene and settings with the recorder active, using multiple interleaved runs; report sampler CPU and average and 1% low FPS or frame times, including refresh behavior.

@fix can do L1, L2, L3, L4, L5 and L6.

Checks: Still running: 11 checks.

More: does it help, other systems, switches, what was read

Does it help: Unproven. The PR reports that dladdr accounted for 13.9% of process CPU samples on the base and that calls per frame fall from one to zero. It does not report comparable before-and-after sampler CPU, frame-rate, or frame-time measurements over multiple runs.

Other systems: The lookup serves HOS_SAMPLE, HOS_SAMPLE_ALL, slow-frame recording, profiling mode, and HOS_WATCH on Linux. The interval cache is shared host code used by the Windows sampler too. The reported game run covers one AMD SteamOS machine; it does not establish the effect on other Linux systems or frame pacing.

Switches: HOS_SLOW_FRAMES_EVERY_MS remains default 4 ms, clamped to at least 1 ms; its value is now cached on first use. No switch was added or removed.

Reviewed: 095ca38663 against 299ed5b704: Read AGENTS.md, CONTRIBUTING.md, docs/dev/standards.md, the PR template, the commit and complete diff, host/posix/prof.c, host/slow_frames.c, and tests/test_prof_modules.py. Traced sampler and watch callers, module loading, the test runner, and the related fault test. Skimmed references to diagnostic consumers and other library unloads. docs/review-checklist.md and ../Tooling/AGENTS.md were absent. No recorded runs, translations, or generated files were changed.; nothing run (a code review).

Checked and fine:

  • The commit records AI assistance trailers.
  • The diff contains no game-derived files, generated outputs, third-party changes, or renderer API changes.
  • The interval getter is called by the single slow-frame sampler thread in the traced startup paths.
  • The late-load test exercises the intended one-second miss refresh for an object at a previously unused address.

Testing: No commands from the project were run, as requested. The author reports Linux game and test runs; CI checks were still running in the supplied results.

Overlaps and merge order: Unknown; the network was closed and no overlap information was supplied.


Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

**Recommendation: Request changes.** The module cache can misidentify frames after libraries are unloaded or replaced, and its fixed capacity can leave sampled modules unnamed. The new test also cannot run on Windows; the claimed performance gain remains unmeasured against the base. The change replaces per-frame Linux dladdr calls with a cached segment lookup and caches the slow-frame sampling interval. It reduces repeated lookup work, but introduces module-lifetime and capacity problems in diagnostic output. **Blocking (3)**: must change before merging. 1. **L1** `host/posix/prof.c:311`: A cache hit never checks whether the object has been unloaded or replaced, and module_add also reuses an old name solely by base address. (more on the line) **Do:** Track loader changes and rebuild the active spans and module identities when objects are loaded or unloaded, while preserving any identities needed by accumulated samples. Add an unload and address-reuse test. 2. **L2** `host/posix/prof.c:273`: The first enumeration consumes the 64 module slots for every loaded object, including objects that are never sampled, and slots are never reclaimed. (more on the line) **Do:** Use a dynamically sized active-object table or otherwise ensure every loaded segment can be represented; test with more than 64 loaded objects and a late-loaded object. 3. **L5** `tests/test_prof_modules.py:20`: The Linux-only test is discovered on Windows without a platform skip and attempts to compile and run a program using Linux dynamic-loader headers and APIs. (more on the line) **Do:** Declare a Windows RUN_ALL_SKIP and guard direct invocation on unsupported platforms, as the other Linux sampler test does. **Should fix (3)**: not blocking, but worth doing before merging. - **L3** `host/posix/prof.c:264`: The 64th module collides with the sampler's existing unknown-module sentinel, index 63. (more on the line) **Do:** Use a distinct sentinel in the sample key or reserve index 63, and test an unknown frame when the table is full. - **L4** `host/posix/prof.c:278`: The mutex protects writes to nmods, but the periodic HOS_SAMPLE report reads nmods without that mutex while another sampler or HOS_WATCH can refresh the table. (more on the line) **Do:** Protect the report's module-table reads with the same mutex, or publish an immutable snapshot with proper synchronization. - **L6** `tests/test_prof_modules.py:96`: Direct test runs ignore CC, and compiler commands containing arguments are passed as one executable name. (more on the line) **Do:** Default to CC when set and parse the compiler command using the repository's compiler-command helper before appending the flags. **Testing before merging (1)** (runs on the systems it can change; it doesn't hold the recommendation) - **L7**: The reported reduction in calls does not quantify the performance benefit or the effect of the new locked lookup and refreshes on sampling and frame pacing. *When:* With slow-frame recording enabled, each frame lookup now takes a mutex and misses can enumerate and sort all loaded segments. The PR provides no comparable after-run showing the net CPU or frame-time effect. **Do:** Measure base and head on the same Linux scene and settings with the recorder active, using multiple interleaved runs; report sampler CPU and average and 1% low FPS or frame times, including refresh behavior. `@fix` can do L1, L2, L3, L4, L5 and L6. **Checks:** Still running: 11 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven. The PR reports that dladdr accounted for 13.9% of process CPU samples on the base and that calls per frame fall from one to zero. It does not report comparable before-and-after sampler CPU, frame-rate, or frame-time measurements over multiple runs. **Other systems:** The lookup serves HOS_SAMPLE, HOS_SAMPLE_ALL, slow-frame recording, profiling mode, and HOS_WATCH on Linux. The interval cache is shared host code used by the Windows sampler too. The reported game run covers one AMD SteamOS machine; it does not establish the effect on other Linux systems or frame pacing. **Switches:** HOS_SLOW_FRAMES_EVERY_MS remains default 4 ms, clamped to at least 1 ms; its value is now cached on first use. No switch was added or removed. **Reviewed:** 095ca38663e1 against 299ed5b704e5: Read AGENTS.md, CONTRIBUTING.md, docs/dev/standards.md, the PR template, the commit and complete diff, host/posix/prof.c, host/slow_frames.c, and tests/test_prof_modules.py. Traced sampler and watch callers, module loading, the test runner, and the related fault test. Skimmed references to diagnostic consumers and other library unloads. docs/review-checklist.md and ../Tooling/AGENTS.md were absent. No recorded runs, translations, or generated files were changed.; nothing run (a code review). **Checked and fine:** - The commit records AI assistance trailers. - The diff contains no game-derived files, generated outputs, third-party changes, or renderer API changes. - The interval getter is called by the single slow-frame sampler thread in the traced startup paths. - The late-load test exercises the intended one-second miss refresh for an object at a previously unused address. **Testing:** No commands from the project were run, as requested. The author reports Linux game and test runs; CI checks were still running in the supplied results. **Overlaps and merge order:** Unknown; the network was closed and no overlap information was supplied. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
@ -268,3 +276,3 @@
mods[nmods].base = *base;
mods[nmods].base = base;
snprintf(mods[nmods].name, sizeof mods[nmods].name, "%s", b ? b + 1 : n);
return nmods++;
Member

L4 (should fix): The mutex protects writes to nmods, but the periodic HOS_SAMPLE report reads nmods without that mutex while another sampler or HOS_WATCH can refresh the table.

When: With HOS_SAMPLE and HOS_WATCH enabled together, the watch thread can add a newly loaded module while the sample thread evaluates mi < nmods. The unsynchronized read and write form a C data race.

Do: Protect the report's module-table reads with the same mutex, or publish an immutable snapshot with proper synchronization.

**L4** (should fix): The mutex protects writes to nmods, but the periodic HOS_SAMPLE report reads nmods without that mutex while another sampler or HOS_WATCH can refresh the table. *When:* With HOS_SAMPLE and HOS_WATCH enabled together, the watch thread can add a newly loaded module while the sample thread evaluates mi < nmods. The unsynchronized read and write form a C data race. **Do:** Protect the report's module-table reads with the same mutex, or publish an immutable snapshot with proper synchronization.
@ -257,1 +262,3 @@
static Module mods[64];
typedef struct { uintptr_t lo, hi; int mod; } Span;
enum { MAX_MODS = 64, MAX_SPANS = 512 };
static Module mods[MAX_MODS];
Member

L3 (should fix): The 64th module collides with the sampler's existing unknown-module sentinel, index 63.

When: Once the enumeration fills all 64 entries, an unknown frame is encoded with index 63 and the periodic HOS_SAMPLE report prints the name of mods[63] instead of '?'.

Do: Use a distinct sentinel in the sample key or reserve index 63, and test an unknown frame when the table is full.

**L3** (should fix): The 64th module collides with the sampler's existing unknown-module sentinel, index 63. *When:* Once the enumeration fills all 64 entries, an unknown frame is encoded with index 63 and the periodic HOS_SAMPLE report prints the name of mods[63] instead of '?'. **Do:** Use a distinct sentinel in the sample key or reserve index 63, and test an unknown frame when the table is full.
@ -265,2 +272,2 @@
if (nmods >= 64) return -1;
const char *n = d.dli_fname && d.dli_fname[0] ? d.dli_fname : "longshot";
if (mods[i].base == base) return i;
if (nmods >= MAX_MODS) return -1;
Member

L2 (blocking): The first enumeration consumes the 64 module slots for every loaded object, including objects that are never sampled, and slots are never reclaimed.

When: With more than 64 loaded objects, a frame in an object later in the loader list returns '?' on every refresh. Previously slots were consumed only by modules actually encountered in samples, so the same frame could be named.

Do: Use a dynamically sized active-object table or otherwise ensure every loaded segment can be represented; test with more than 64 loaded objects and a late-loaded object.

**L2** (blocking): The first enumeration consumes the 64 module slots for every loaded object, including objects that are never sampled, and slots are never reclaimed. *When:* With more than 64 loaded objects, a frame in an object later in the loader list returns '?' on every refresh. Previously slots were consumed only by modules actually encountered in samples, so the same frame could be named. **Do:** Use a dynamically sized active-object table or otherwise ensure every loaded segment can be represented; test with more than 64 loaded objects and a late-loaded object.
@ -272,0 +308,4 @@
}
if (lo > 0 && pc < spans[lo - 1].hi) found = spans[lo - 1].mod;
else if (!pass && (!nspans || hos_now_ns() - spans_read_ns >= 1000000000LL)) {
nspans = 0;
Member

L1 (blocking): A cache hit never checks whether the object has been unloaded or replaced, and module_add also reuses an old name solely by base address.

When: After a sampled library is unloaded, its spans remain in the table. If another library is mapped at that address, its frames hit the old span and are attributed to the old library indefinitely; even a later refresh retains the old name when the base is reused.

Do: Track loader changes and rebuild the active spans and module identities when objects are loaded or unloaded, while preserving any identities needed by accumulated samples. Add an unload and address-reuse test.

**L1** (blocking): A cache hit never checks whether the object has been unloaded or replaced, and module_add also reuses an old name solely by base address. *When:* After a sampled library is unloaded, its spans remain in the table. If another library is mapped at that address, its frames hit the old span and are attributed to the old library indefinitely; even a later refresh retains the old name when the base is reused. **Do:** Track loader changes and rebuild the active spans and module identities when objects are loaded or unloaded, while preserving any identities needed by accumulated samples. Add an unload and address-reuse test.
@ -0,0 +17,4 @@
from srccut import between # noqa: E402
RUN_ALL_ARGS = ["--cc", "{cc}"]
Member

L5 (blocking): The Linux-only test is discovered on Windows without a platform skip and attempts to compile and run a program using Linux dynamic-loader headers and APIs.

When: A Windows run of tests/run_all.py selects this test and invokes the Windows compiler on dlfcn.h, link.h, dl_iterate_phdr, and ELF-specific flags, so the check fails instead of being skipped.

Do: Declare a Windows RUN_ALL_SKIP and guard direct invocation on unsupported platforms, as the other Linux sampler test does.

**L5** (blocking): The Linux-only test is discovered on Windows without a platform skip and attempts to compile and run a program using Linux dynamic-loader headers and APIs. *When:* A Windows run of tests/run_all.py selects this test and invokes the Windows compiler on dlfcn.h, link.h, dl_iterate_phdr, and ELF-specific flags, so the check fails instead of being skipped. **Do:** Declare a Windows RUN_ALL_SKIP and guard direct invocation on unsupported platforms, as the other Linux sampler test does.
@ -0,0 +93,4 @@
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument("--cc", default="cc")
args = parser.parse_args()
source = (ROOT / "host/posix/prof.c").read_text(encoding="utf-8")
Member

L6 (should fix): Direct test runs ignore CC, and compiler commands containing arguments are passed as one executable name.

When: With CC set to clang, running the documented command still uses cc; with the runner passing a value such as 'ccache clang', subprocess attempts to execute a file with that entire name.

Do: Default to CC when set and parse the compiler command using the repository's compiler-command helper before appending the flags.

**L6** (should fix): Direct test runs ignore CC, and compiler commands containing arguments are passed as one executable name. *When:* With CC set to clang, running the documented command still uses cc; with the runner passing a value such as 'ccache clang', subprocess attempts to execute a file with that entire name. **Do:** Default to CC when set and parse the compiler command using the repository's compiler-command helper before appending the flags.
Author
Contributor

Thanks, these were good catches -- all six are fixed in 5a469b911.

The slots were the one that really mattered.

  • Every loaded object took a slot at the first read, so past 64 objects the rest were never named; now an object gets a slot only when a frame lands in it, and the slots stop at 63, under the "?"
  • A hit checks the loader's load and unload counts at most once a second and reads the table again when they've changed, so an unloaded library isn't named for its old span
  • The report reads the slot count with acquire, and the test skips off Linux and takes CC

I added the unload to the test, too: it unloads a library, loads another one possibly in the same location, then loads 70 more. The old code fails it.

Thanks, these were good catches -- all six are fixed in 5a469b911. The slots were the one that really mattered. - Every loaded object took a slot at the first read, so past 64 objects the rest were never named; now an object gets a slot only when a frame lands in it, and the slots stop at 63, under the "?" - A hit checks the loader's load and unload counts at most once a second and reads the table again when they've changed, so an unloaded library isn't named for its old span - The report reads the slot count with acquire, and the test skips off Linux and takes `CC` I added the unload to the test, too: it unloads a library, loads another one possibly in the same location, then loads 70 more. The old code fails it.
fix(prof): the module table's slots go to the modules sampled, and an unloaded library is read again (#3155 review)
Some checks are pending
CI / What the change needs (pull_request) Blocked by required conditions
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Blocked by required conditions
CI / Third-party parts and guide screenshots (pull_request) Blocked by required conditions
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Blocked by required conditions
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Blocked by required conditions
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
PR description / Title and description (pull_request_target) Successful in 6s
5a469b9110
Review of #3155 (BeanBot, L1-L6).

L2, L3: every object the first read found took one of the 64 module slots, so
with more than 64 loaded a frame in a later one stayed "?", and a 64th slot
was the sample keys' "?" (63). The objects are now a table of their own, and
a module gets a slot only when a frame is found in it, as dladdr's naming
did; the slots are 63, under the "?".

L1: a hit on the span of a library unloaded since named it still. A hit on a
table read a second ago or more now looks at the loader's counts of objects
loaded and unloaded (dlpi_adds, dlpi_subs; once a second at most) and reads
the segments again when they changed. A slot is the same module only for the
same base and name, so one loaded where another was gets its own.

L4: the report reads the slot count with acquire, module_add publishes it
with release.

L5, L6: test_prof_modules is skipped off Linux (RUN_ALL_SKIP and a direct
run), and takes CC, parsed by compiler_command.parse_compiler.

test_prof_modules: a library unloaded and another loaded, perhaps where it
was (named for what is there now, in a slot of its own; the old code names
the unloaded one); 70 objects loaded, the last named, the slots running out
at 63 and never 63.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Owner
@review
BeanBot left a comment

Recommendation: Approve. The code is ready: only testing is left. The slot allocation, unload handling, synchronization and test portability issues are addressed. The claimed performance gain still needs a before-and-after measurement of sampler cost and frame pacing. Recommend approval; not approved on the forge.

Linux profiling and slow-frame recording name sampled frames from cached loaded-object segments instead of calling dladdr for every frame. The fix assigns slots only to sampled modules and refreshes stale mappings, at the cost of a locked lookup and periodic loader checks whose performance impact is not yet quantified.

Testing before merging (1) (runs on the systems it can change; it doesn't hold the recommendation)

  • L7: The reported reduction in calls does not quantify the performance benefit or the effect of the new locked lookup and refreshes on sampling and frame pacing. When: With slow-frame recording enabled, each frame lookup now takes a mutex and misses can enumerate and sort all loaded segments. The PR provides no comparable after-run showing the net CPU or frame-time effect. Do: Measure base and head on the same Linux scene and settings with the recorder active, using multiple interleaved runs; report sampler CPU and average and 1% low FPS or frame times, including refresh behavior.

Since the last review (on 095ca38663)
Resolved: L1 (A cache hit never checks whether the object has been unloaded or replaced, and module_add…); L2 (The first enumeration consumes the 64 module slots for every loaded object, including obje…); L3 (The 64th module collides with the sampler's existing unknown-module sentinel, index 63.); L4 (The mutex protects writes to nmods, but the periodic HOS_SAMPLE report reads nmods without…); L5 (The Linux-only test is discovered on Windows without a platform skip and attempts to compi…); L6 (Direct test runs ignore CC, and compiler commands containing arguments are passed as one e…)
Still open: L7 (The reported reduction in calls does not quantify the performance benefit or the effect of…)

Checks: Still running: 11 checks.

More: does it help, other systems, switches, what was read

Does it help: Unproven. The author reports dladdr accounted for 13.9% of process CPU samples before the change, and calls per frame fell from one to zero; those figures do not quantify the net benefit or frame-pacing effect.

Other systems: The module lookup affects Linux profiling, slow-frame recording and HOS_WATCH; Windows uses a separate lookup. The shared slow-frame interval cache also runs on Windows. The author reports Linux game use, a Linux build, and passing focused tests with gcc and clang; the net timing effect remains unmeasured.

Switches: HOS_SLOW_FRAMES_EVERY_MS keeps its 4 ms default and minimum of 1 ms, but is now read once. It remains a diagnostic setting; no new player switch is added.

Reviewed: 5a469b9110 against 299ed5b704: Read AGENTS.md, CONTRIBUTING.md, the pull request template, the changed module lookup and test, host/slow_frames.c, and the compiler-command helper. Reviewed both diffs and commit summaries; the remaining profiler code and associated callers were skimmed. Tooling's separate rules were unavailable in the supplied checkout.; nothing run (a code review).

Checked and fine:

  • The unload test checks the old address and the replacement library after a loader-count refresh.
  • The many-object test verifies lazy slot allocation and that index 63 is not assigned.
  • The reported full-suite failures are also reported on the base with the same tools.

Testing: No commands that build or run project code were executed. The author reports focused Linux tests with gcc and clang, a Linux game build, and in-game use; CI is still running.

Overlaps and merge order: Not checked; network access is closed.


Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.

**Recommendation: Approve.** The code is ready: only testing is left. The slot allocation, unload handling, synchronization and test portability issues are addressed. The claimed performance gain still needs a before-and-after measurement of sampler cost and frame pacing. Recommend approval; not approved on the forge. Linux profiling and slow-frame recording name sampled frames from cached loaded-object segments instead of calling dladdr for every frame. The fix assigns slots only to sampled modules and refreshes stale mappings, at the cost of a locked lookup and periodic loader checks whose performance impact is not yet quantified. **Testing before merging (1)** (runs on the systems it can change; it doesn't hold the recommendation) - **L7**: The reported reduction in calls does not quantify the performance benefit or the effect of the new locked lookup and refreshes on sampling and frame pacing. *When:* With slow-frame recording enabled, each frame lookup now takes a mutex and misses can enumerate and sort all loaded segments. The PR provides no comparable after-run showing the net CPU or frame-time effect. **Do:** Measure base and head on the same Linux scene and settings with the recorder active, using multiple interleaved runs; report sampler CPU and average and 1% low FPS or frame times, including refresh behavior. **Since the last review** (on 095ca38663e1) Resolved: L1 (A cache hit never checks whether the object has been unloaded or replaced, and module_add…); L2 (The first enumeration consumes the 64 module slots for every loaded object, including obje…); L3 (The 64th module collides with the sampler's existing unknown-module sentinel, index 63.); L4 (The mutex protects writes to nmods, but the periodic HOS_SAMPLE report reads nmods without…); L5 (The Linux-only test is discovered on Windows without a platform skip and attempts to compi…); L6 (Direct test runs ignore CC, and compiler commands containing arguments are passed as one e…) Still open: L7 (The reported reduction in calls does not quantify the performance benefit or the effect of…) **Checks:** Still running: 11 checks. <details> <summary>More: does it help, other systems, switches, what was read</summary> **Does it help:** Unproven. The author reports dladdr accounted for 13.9% of process CPU samples before the change, and calls per frame fell from one to zero; those figures do not quantify the net benefit or frame-pacing effect. **Other systems:** The module lookup affects Linux profiling, slow-frame recording and HOS_WATCH; Windows uses a separate lookup. The shared slow-frame interval cache also runs on Windows. The author reports Linux game use, a Linux build, and passing focused tests with gcc and clang; the net timing effect remains unmeasured. **Switches:** HOS_SLOW_FRAMES_EVERY_MS keeps its 4 ms default and minimum of 1 ms, but is now read once. It remains a diagnostic setting; no new player switch is added. **Reviewed:** 5a469b911042 against 299ed5b704e5: Read AGENTS.md, CONTRIBUTING.md, the pull request template, the changed module lookup and test, host/slow_frames.c, and the compiler-command helper. Reviewed both diffs and commit summaries; the remaining profiler code and associated callers were skimmed. Tooling's separate rules were unavailable in the supplied checkout.; nothing run (a code review). **Checked and fine:** - The unload test checks the old address and the replacement library after a loader-count refresh. - The many-object test verifies lazy slot allocation and that index 63 is not assigned. - The reported full-suite failures are also reported on the base with the same tools. **Testing:** No commands that build or run project code were executed. The author reports focused Linux tests with gcc and clang, a Linux game build, and in-game use; CI is still running. **Overlaps and merge order:** Not checked; network access is closed. </details> --- <sub>Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.</sub>
HumanBean deleted branch perf/sampler-module-spans 2026-12-04 06:49:55 +00:00
Some checks are pending
CI / What the change needs (pull_request) Blocked by required conditions
CI / Lint (pre-commit, ShellCheck, actionlint) (pull_request) Blocked by required conditions
CI / Third-party parts and guide screenshots (pull_request) Blocked by required conditions
CI / Rust (rustfmt, clippy, cargo test, end to end) (pull_request) Blocked by required conditions
CI / Host C for Windows (llvm-mingw, compile only) (pull_request) Blocked by required conditions
CI / Renderer build check (Windows, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Renderer build check (Linux, compile --only renderer, without and with FSR 4) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 1/2) (pull_request) Blocked by required conditions
CI / Game-free checks (run_all.py, part 2/2) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
PR description / Title and description (pull_request_target) Successful in 6s
Some workflows are waiting to be reviewed.
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
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
MagicBeanDev/Longshot!3155
No description provided.