perf(libc): set TZ once on Linux #2031

Merged
Aryansh1520 merged 2 commits from upstream-pr/2031 into main 2026-10-10 06:08:28 +00:00
Aryansh1520 commented 2026-10-09 05:31:41 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Aryansh1520 on 2026-10-09T05:31:41Z.


What

Without TZ, glibc's localtime and mktime run tzset on every call, and each tzset re-checks /etc/localtime. PPSA28997 (God of War Sons of Sparta) calls them every frame during its intro, which then spent most of its time there and played back far below speed. libc now sets TZ to :/etc/localtime when it is unset and calls tzset once at load, so the zone file is read once. A TZ set by the user is left as it is. Windows is unchanged.

Tested

  • Linux (CachyOS, kernel 7.2), GCC: PPSA28997's intro plays at normal speed; local times are unchanged.
  • tools/check_conventions.py --base origin/main passes.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes
<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4796418870 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2031). Originally posted by [Aryansh1520](https://github.com/Aryansh1520) on 2026-10-09T05:31:41Z. --- ### What Without `TZ`, glibc's `localtime` and `mktime` run `tzset` on every call, and each `tzset` re-checks `/etc/localtime`. PPSA28997 (God of War Sons of Sparta) calls them every frame during its intro, which then spent most of its time there and played back far below speed. libc now sets `TZ` to `:/etc/localtime` when it is unset and calls `tzset` once at load, so the zone file is read once. A `TZ` set by the user is left as it is. Windows is unchanged. ### Tested - Linux (CachyOS, kernel 7.2), GCC: PPSA28997's intro plays at normal speed; local times are unchanged. - `tools/check_conventions.py --base origin/main` passes. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes
MarcZX10 commented 2026-10-09 05:37:14 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T05:37:14Z.


The optimization and evidence are Linux/glibc-specific, but #ifndef _WIN32 also runs this initializer on macOS. That changes the process environment there and forces an explicit /etc/localtime zone-file path without Darwin validation. Could you gate this with __linux__ (or provide a macOS behavior test and evidence) so the change only affects the platform described in the PR? I’m holding approval pending that.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6075008082 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2031#issuecomment-6075008082). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T05:37:14Z. --- The optimization and evidence are Linux/glibc-specific, but `#ifndef _WIN32` also runs this initializer on macOS. That changes the process environment there and forces an explicit `/etc/localtime` zone-file path without Darwin validation. Could you gate this with `__linux__` (or provide a macOS behavior test and evidence) so the change only affects the platform described in the PR? I’m holding approval pending that.
Aryansh1520 commented 2026-10-09 05:47:01 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Aryansh1520 on 2026-10-09T05:47:01Z.


Agreed. The initializer is now behind #ifdef __linux__, so macOS and Windows are unchanged and the change only affects the platform the PR describes.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6075120259 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2031#issuecomment-6075120259). Originally posted by [Aryansh1520](https://github.com/Aryansh1520) on 2026-10-09T05:47:01Z. --- Agreed. The initializer is now behind `#ifdef __linux__`, so macOS and Windows are unchanged and the change only affects the platform the PR describes.
MarcZX10 commented 2026-10-09 05:55:37 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by MarcZX10 on 2026-10-09T05:55:37Z.

Review: COMMENTED


Thanks for limiting the initializer to __linux__. I built exact head 631654b6 on Linux with GCC 12 and ran guest_time_conversion with TZ unset; it passed 1/1 in 0.46 s. Conventions and git diff --check pass. GitHub currently reports no checks on this head, so please get the required CI jobs running (or have a maintainer approve any held workflow) before merge. I will hold approval until checks are visible.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:5466244910 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2031#pullrequestreview-5466244910). Originally posted by [MarcZX10](https://github.com/MarcZX10) on 2026-10-09T05:55:37Z. **Review:** COMMENTED --- Thanks for limiting the initializer to `__linux__`. I built exact head `631654b6` on Linux with GCC 12 and ran `guest_time_conversion` with `TZ` unset; it passed 1/1 in 0.46 s. Conventions and `git diff --check` pass. GitHub currently reports no checks on this head, so please get the required CI jobs running (or have a maintainer approve any held workflow) before merge. I will hold approval until checks are visible.
oneandonlydean commented 2026-10-09 09:22:50 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by oneandonlydean on 2026-10-09T09:22:50Z.


Could you add numbers for the PPSA28997 intro, main against main plus this (fps or frame time over a few runs)? Perf changes need before/after figures for the change itself (#218).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6078128834 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2031#issuecomment-6078128834). Originally posted by [oneandonlydean](https://github.com/oneandonlydean) on 2026-10-09T09:22:50Z. --- Could you add numbers for the PPSA28997 intro, main against main plus this (fps or frame time over a few runs)? Perf changes need before/after figures for the change itself (#218).
Aryansh1520 commented 2026-10-09 10:36:58 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by Aryansh1520 on 2026-10-09T10:36:58Z.


PPSA28997, Linux (CachyOS, kernel 7.2), GCC, same build with and without this change: the time from the Sony logo to the Santa Monica logo drops from about 2 minutes to about 15–20 seconds, which is normal speed. Without it, the intro plays far below speed the whole time because localtime/mktime re-read the zone each frame.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6079203993 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2031#issuecomment-6079203993). Originally posted by [Aryansh1520](https://github.com/Aryansh1520) on 2026-10-09T10:36:58Z. --- PPSA28997, Linux (CachyOS, kernel 7.2), GCC, same build with and without this change: the time from the Sony logo to the Santa Monica logo drops from about 2 minutes to about 15–20 seconds, which is normal speed. Without it, the intro plays far below speed the whole time because `localtime`/`mktime` re-read the zone each frame.
popcoder565 commented 2026-10-09 15:46:15 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by popcoder565 on 2026-10-09T15:46:15Z.


Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head 631654b6, merged onto main d70b8998 in one build with 38 other PRs that had no Windows run.

  • The change is Linux-only, so on Windows this only checks that it builds.
  • Full ctest in that build: 519 of 519. That needed local fixes to three other PRs in the batch that don't build or pass on Windows: #1611, #1796 and #1824 (reported there).

No title was run.

🤖 Addressed by Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6084268826 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2031#issuecomment-6084268826). Originally posted by [popcoder565](https://github.com/popcoder565) on 2026-10-09T15:46:15Z. --- Native Windows run, since no Windows results were posted. Setup: Windows 10 (19045), MinGW-w64 GCC 15.2.0 (WinLibs r7), Release. Head `631654b6`, merged onto `main` d70b8998 in one build with 38 other PRs that had no Windows run. - The change is Linux-only, so on Windows this only checks that it builds. - Full ctest in that build: 519 of 519. That needed local fixes to three other PRs in the batch that don't build or pass on Windows: #1611, #1796 and #1824 (reported there). No title was run. _🤖 Addressed by [Claude Code](https://claude.com/claude-code)_
adriadam10 commented 2026-10-10 06:08:25 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by adriadam10 on 2026-10-10T06:08:25Z.


Checked the diff against glibc (tzset_internal has no early return when TZ is unset, so every localtime/mktime re-reads the zone file), built the libc tests on Linux and ran them (42/43; guest_time_conversion passes, the one not run is guest_wcsrtombs, whose executable isn't in the scoped build). Numbers for PPSA28997 are in the thread, Linux-only gating is in, and Windows builds per @popcoder565. Merging.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6094506229 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/2031#issuecomment-6094506229). Originally posted by [adriadam10](https://github.com/adriadam10) on 2026-10-10T06:08:25Z. --- Checked the diff against glibc (`tzset_internal` has no early return when `TZ` is unset, so every `localtime`/`mktime` re-reads the zone file), built the libc tests on Linux and ran them (42/43; `guest_time_conversion` passes, the one not run is `guest_wcsrtombs`, whose executable isn't in the scoped build). Numbers for PPSA28997 are in the thread, Linux-only gating is in, and Windows builds per @popcoder565. Merging.
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!2031
No description provided.