test(libSceIcu): convert the scalar sweep in runs instead of one call per scalar #26783

Merged
cozejarr merged 2 commits from upstream-pr/26783 into main 2026-11-25 04:28:25 +00:00
cozejarr commented 2026-11-24 21:34:13 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by cozejarr on 2026-11-24T21:34:13Z.


What

guest_icu_utf_conversions runs close to its 10 s TIMEOUT and times out under parallel load. Scalars() converts each of the 1,112,064 Unicode scalars with three separate calls (u_strFromUTF8, u_strToUTF8, u_strFromUTF8Lenient), about 3.3 million calls. Since #25526, the two strict conversions copy their operands through guest memory on every call, so the sweep alone takes about 7.4 s on Windows. The whole test took 9.03 s in a full ctest -j12 run on main on Windows. On a 4-core Linux container it took 9.5 s on its own and timed out at 10.15 s in a full ctest -j4 run on main at 5f04682cef.

This PR converts the scalars in runs of about 8 KiB of UTF-8, 535 runs in all. Each run goes through all three directions, and the test compares every unit, the length and the terminator. The two strict directions get room for exactly the result plus its terminator, and a canary after it is checked. u_strFromUTF8Lenient needs a capacity sized from the UTF-8 source, so it gets that capacity (bytes + 1) plus one element beyond it, and every element after the terminator, including the one past the capacity, must be untouched. The single-scalar checks, with their canaries, still run for the scalars at every UTF-8 and UTF-16 width boundary (0, 1, 7f, 80, 7ff, 800, d7ff, e000, fffd, ffff, 10000, 10ffff). Every scalar is still converted and compared exactly. The runs also span several pages, so the page-sized chunks GuestCopyIn reads now split multibyte sequences, which the one-scalar calls never did. The library is not changed.

Tested

  • Windows 11, WinLibs GCC, on main 5f04682cef: guest_icu_utf_conversions goes from 7.39 to 7.45 s (3 runs) down to 0.08 s (5 runs). All 95 guest_icu* tests pass.
  • Linux (Debian container, 4 cores, GCC, Release), same base: 0.06 s (3 runs), down from 9.5 s alone. All 95 guest_icu* tests pass.
  • The runs still catch a bug in a single scalar. I made two temporary library changes, neither committed. With UtfConversions.cpp decoding U+5432 as U+5433, the test fails with "scalar run UTF-8 decode". With it encoding a wrong lead byte for U+ABCD, the test fails with "scalar run UTF-16 encode".
  • Added after review (0ad66daf9fc): the check of the lenient buffer's tail. On Linux the test passes 3 of 3 in 0.06 s, and with that check's expected value changed it fails with "scalar run lenient tail", so the check runs.
  • After rebasing onto c2a0c13039f (since 5f04682cef, main changed no ICU files), on Linux: 95 of 95 guest_icu* tests pass, and the test takes 0.06 s (3 runs).
  • tools/check_conventions.py and tools/debt_fold.py --check pass.

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 and the licence notice of code adapted from upstream (see AGENTS.md)
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed under Silent stubs in their library's technical debt file
  • 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
  • Fixes: none
  • Unblocks: none
  • GPUs tested: n/a
  • AI-assisted: yes

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:5480713697 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26783). Originally posted by [cozejarr](https://github.com/cozejarr) on 2026-11-24T21:34:13Z. --- ### What `guest_icu_utf_conversions` runs close to its 10 s `TIMEOUT` and times out under parallel load. `Scalars()` converts each of the 1,112,064 Unicode scalars with three separate calls (`u_strFromUTF8`, `u_strToUTF8`, `u_strFromUTF8Lenient`), about 3.3 million calls. Since #25526, the two strict conversions copy their operands through guest memory on every call, so the sweep alone takes about 7.4 s on Windows. The whole test took 9.03 s in a full `ctest -j12` run on `main` on Windows. On a 4-core Linux container it took 9.5 s on its own and timed out at 10.15 s in a full `ctest -j4` run on `main` at `5f04682cef`. This PR converts the scalars in runs of about 8 KiB of UTF-8, 535 runs in all. Each run goes through all three directions, and the test compares every unit, the length and the terminator. The two strict directions get room for exactly the result plus its terminator, and a canary after it is checked. `u_strFromUTF8Lenient` needs a capacity sized from the UTF-8 source, so it gets that capacity (bytes + 1) plus one element beyond it, and every element after the terminator, including the one past the capacity, must be untouched. The single-scalar checks, with their canaries, still run for the scalars at every UTF-8 and UTF-16 width boundary (`0`, `1`, `7f`, `80`, `7ff`, `800`, `d7ff`, `e000`, `fffd`, `ffff`, `10000`, `10ffff`). Every scalar is still converted and compared exactly. The runs also span several pages, so the page-sized chunks `GuestCopyIn` reads now split multibyte sequences, which the one-scalar calls never did. The library is not changed. ### Tested - Windows 11, WinLibs GCC, on `main` `5f04682cef`: `guest_icu_utf_conversions` goes from 7.39 to 7.45 s (3 runs) down to 0.08 s (5 runs). All 95 `guest_icu*` tests pass. - Linux (Debian container, 4 cores, GCC, Release), same base: 0.06 s (3 runs), down from 9.5 s alone. All 95 `guest_icu*` tests pass. - The runs still catch a bug in a single scalar. I made two temporary library changes, neither committed. With `UtfConversions.cpp` decoding U+5432 as U+5433, the test fails with "scalar run UTF-8 decode". With it encoding a wrong lead byte for U+ABCD, the test fails with "scalar run UTF-16 encode". - Added after review (`0ad66daf9fc`): the check of the lenient buffer's tail. On Linux the test passes 3 of 3 in 0.06 s, and with that check's expected value changed it fails with "scalar run lenient tail", so the check runs. - After rebasing onto `c2a0c13039f` (since `5f04682cef`, `main` changed no ICU files), on Linux: 95 of 95 `guest_icu*` tests pass, and the test takes 0.06 s (3 runs). - `tools/check_conventions.py` and `tools/debt_fold.py --check` pass. ### 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) and the licence notice of code adapted from upstream (see AGENTS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed under Silent stubs in their library's [technical debt](https://github.com/boykopovar/AnyPS5/tree/main/docs/dev/debt) file - [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] Fixes: none - [x] Unblocks: none - [x] GPUs tested: n/a - [x] AI-assisted: yes 🤖 Generated with [Claude Code](https://claude.com/claude-code)
mihiii1337 commented 2026-11-24 21:57:26 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-24T21:57:26Z.

Review: COMMENTED


The batching is sound and independently removes the Windows timeout risk at exact head 2e22f7b8510ec2e7bfc2bf50bf9f1bc6eb625196. I count all 1,112,064 non-surrogate scalars in 535 non-empty runs, plus the 12 deliberate boundary probes. Counted U+0000 remains covered. In a clean WinLibs Release build, guest_icu_utf_conversions passed 5/5; after the cold run the reported test time was 0.05 s in each of four runs (the cold run itself was 0.88 s). A local one-scalar expected-value mutation at U+5432 failed at scalar run UTF-8 decode; after byte-exact restoration and rebuild, the test passed again at 0.11 s.

One small coverage/description correction is worth making before merge. The strict run directions check the terminator and the immediately following canary, but the lenient run checks only its terminator. Because that API currently requires capacity based on the UTF-8 source length, its buffer is intentionally larger than the UTF-16 result, so the PR description's “room for exactly the result plus its terminator” is not true for this direction. Please give the lenient vector one extra element beyond the declared capacity and verify the untouched tail (at minimum the element immediately after the terminator and the canary just beyond the passed capacity), then describe that capacity rule accurately.

The causality sentence should also distinguish the paths: #25526 added checked guest copies to the two strict conversions; the lenient conversion's guest-pointer change is still open in #22460. The measured improvement remains valid.

I found no duplicate batching PR. #22460 touches this fixture in non-overlapping hunks.

AI-assisted: yes (OpenAI Codex); exact head/base/blob, loop counts and bounds, build output, CTest runs, negative-control failure, and byte-exact restoration were checked directly.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6048055996 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26783#pullrequestreview-6048055996). Originally posted by [mihiii1337](https://github.com/mihiii1337) on 2026-11-24T21:57:26Z. **Review:** COMMENTED --- The batching is sound and independently removes the Windows timeout risk at exact head `2e22f7b8510ec2e7bfc2bf50bf9f1bc6eb625196`. I count all 1,112,064 non-surrogate scalars in 535 non-empty runs, plus the 12 deliberate boundary probes. Counted U+0000 remains covered. In a clean WinLibs Release build, `guest_icu_utf_conversions` passed 5/5; after the cold run the reported test time was 0.05 s in each of four runs (the cold run itself was 0.88 s). A local one-scalar expected-value mutation at U+5432 failed at `scalar run UTF-8 decode`; after byte-exact restoration and rebuild, the test passed again at 0.11 s. One small coverage/description correction is worth making before merge. The strict run directions check the terminator and the immediately following canary, but the lenient run checks only its terminator. Because that API currently requires capacity based on the UTF-8 source length, its buffer is intentionally larger than the UTF-16 result, so the PR description's “room for exactly the result plus its terminator” is not true for this direction. Please give the lenient vector one extra element beyond the declared capacity and verify the untouched tail (at minimum the element immediately after the terminator and the canary just beyond the passed capacity), then describe that capacity rule accurately. The causality sentence should also distinguish the paths: #25526 added checked guest copies to the two strict conversions; the lenient conversion's guest-pointer change is still open in #22460. The measured improvement remains valid. I found no duplicate batching PR. #22460 touches this fixture in non-overlapping hunks. AI-assisted: yes (OpenAI Codex); exact head/base/blob, loop counts and bounds, build output, CTest runs, negative-control failure, and byte-exact restoration were checked directly.
mihiii1337 commented 2026-11-24 22:09:09 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by mihiii1337 on 2026-11-24T22:09:09Z.

Review: APPROVED


Both review points are resolved at exact head 0ad66daf9fc405f3a7df34df952d944d5261deca.

The lenient run now keeps its required source-length-based capacity, allocates one additional element beyond that capacity, and verifies every element after the terminator through the out-of-capacity canary. The PR description now correctly attributes the checked guest copies to the two strict conversions added by #25526 and explains the lenient capacity rule separately.

I rebuilt the exact changed test blob (b6e8f684bcb7ac2932adfbf13b2c243d21bad1a5) in the same clean Windows WinLibs Release review build. guest_icu_utf_conversions passed 5/5 at the new head (0.05–0.12 s reported test time). As a negative control, I locally changed the first lenient tail element after the terminator; the test failed at scalar run lenient tail. After byte-exact restoration and rebuild, it passed again at 0.12 s.

The earlier full-coverage check still holds: all 1,112,064 non-surrogate scalars are converted in 535 non-empty runs, with 12 separate boundary probes. No production code changes.

AI-assisted: yes (OpenAI Codex); exact head/blob, diff, loop coverage, capacity/tail bounds, Windows build, five positive runs, negative control, and byte-exact restoration were checked directly.

<!-- greyfinch-sync:boykopovar/AnyPS5:review:6048190587 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/26783#pullrequestreview-6048190587). Originally posted by [mihiii1337](https://github.com/mihiii1337) on 2026-11-24T22:09:09Z. **Review:** APPROVED --- Both review points are resolved at exact head `0ad66daf9fc405f3a7df34df952d944d5261deca`. The lenient run now keeps its required source-length-based capacity, allocates one additional element beyond that capacity, and verifies every element after the terminator through the out-of-capacity canary. The PR description now correctly attributes the checked guest copies to the two strict conversions added by #25526 and explains the lenient capacity rule separately. I rebuilt the exact changed test blob (`b6e8f684bcb7ac2932adfbf13b2c243d21bad1a5`) in the same clean Windows WinLibs Release review build. `guest_icu_utf_conversions` passed 5/5 at the new head (0.05–0.12 s reported test time). As a negative control, I locally changed the first lenient tail element after the terminator; the test failed at `scalar run lenient tail`. After byte-exact restoration and rebuild, it passed again at 0.12 s. The earlier full-coverage check still holds: all 1,112,064 non-surrogate scalars are converted in 535 non-empty runs, with 12 separate boundary probes. No production code changes. AI-assisted: yes (OpenAI Codex); exact head/blob, diff, loop coverage, capacity/tail bounds, Windows build, five positive runs, negative control, and byte-exact restoration were checked directly.
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!26783
No description provided.