Skip to content

Helio G95 performance build + fast game import + package rename (0.4.2 + 0.4.3) - #417

Closed
maxi000q wants to merge 3 commits into
mamcjr:mainfrom
maxi000q:main
Closed

maxi000q wants to merge 3 commits into
mamcjr:mainfrom
maxi000q:main

Conversation

@maxi000q

Copy link
Copy Markdown
Contributor

Note for the maintainer (please read first)

  • I renamed the app's package: com.botwrecomp.android → com.zbotw.recomp, so my fork installs beside the original app instead of over it. The final name is yours to pick. scripts/rename_package.sh (added in this PR) does the whole rename in one command — applicationId/namespace, the java source dirs, the 21 JNI symbol names, shortcuts.xml, the ACTION strings and the run scripts' adb paths. Set NEW_ID / NEW_J at the top and run it with whatever name you want for upstream, or tell me the name and I'll rebase this PR with it. If you'd rather have the rename as its own commit, say so and I'll split it before you merge.
  • README.md / README.pt-BR.md are removed in my fork (commit d0ae3f8). If you want them kept upstream, I'll restore them in this PR.

Summary

Two commits on top of 0.4.1-beta, all tuned for one device — Helio G95 (2x Cortex-A76 @ 2.05 GHz + 6x Cortex-A55, Mali-G76, 8 GB RAM). No UI, app-name or resolution changes; everything is internal.

  • 0.4.2 — Helio G95 performance build: the native (NCE) path tuned for this SoC — render thread pinned to the A76 cluster, console-accurate guest tick, Mali GPU progress waiting, A76-tuned runtime flags.
  • 0.4.3 — fast game import: the first import that took ~90 minutes on this device now finishes in minutes, and the game code then upgrades itself to -O1 in the background from the player's own session profile.

The 0.4.3 problem in detail: the import compiled every generated function at -O1 up front, under a 2-compiler cap, plus a cold scan — all before the player could reach the title screen. The fix: build everything at -O0 first so play starts in minutes, record which functions the player's session actually runs (the project's own fnprof profiler), then quietly rebuild just those hot functions at -O1 in the background while the game is not being watched.

What's changed

0.4.2 — Helio G95 performance build (native / NCE tuning)

  • runtime/g95_perf.c (new) — detects the SoC (mt6769 / mt6785), finds the A76 cluster from cpufreq, pins the render thread to it, sets a uclamp.min floor (512) on every runtime thread, and advises the game's code and stubs resident (madvise WILLNEED). A no-op on every other SoC; LARECOMP_NO_G95=1 restores stock behavior.
  • runtime/native.c — the guest counter scaled into the Switch's 19.2 MHz tick (64.64 fixed point, runtime read path only, no rewriter change), so game clocks and the frame pacer keep console time on a Helio counter rate. Native mode (NCE) is on by default; the menu toggle still wins.
  • runtime/nvn/vulkan/exec.c — the GPU progress waiter thread is on by default for Mali (a timeline value read blocks in the kernel until the GPU catches up — without it the render thread stalled after every submission); the transient ring uses 32 MB chunks on Mali (no device-local memory).
  • runtime/platform/android.c — the render-thread pin and the shared uclamp call go through the G95 profile first.
  • CMakeLists — the runtime is built with -O3 -march=armv8.2-a -mtune=cortex-a76 -ffp-contract=fast; march stays at plain v8.2 (no +lse / +fp16 / +dotprod) so every instruction also runs on the little A55 cores — no SIGILL.
  • versionCode 42.

0.4.3 — Fast game import + package rename

Fast first build (GameBuildOpts.fast, runtime/gamebuild.c)

  • Everything compiles at -O0 and the cold scan is skipped entirely — play starts in minutes.
  • Up to 6 compilers in parallel: the old 2-job cap was measured against -O1 memory, and -O0 jobs are far lighter; memory floors drop to 512 / 768 MB to match. LARECOMP_GAMEBUILD_MAX=<n> caps it.
  • The single-threaded Python generator — the other half of the import wait — is pinned to the A76 cores (g95_pin_pid_big in g95_perf.c) on Helio G90-family SoCs, where the -O0 compilers no longer need them.

Background -O1 upgrade (runtime/ui/launcher.mm)

  • During the first play session, fnprof (the project's own function-entry profiler) records the functions the player's game actually entered — negligible overhead.
  • The next time the start screen shows, the game code is rebuilt in the background from that list — hot functions at -O1, the rest optnone — while the currently-loaded library stays untouched until the new one is complete; a failed upgrade changes nothing.
  • Full frame rate after the upgrade, no waiting at any point. LARECOMP_NO_UPGRADE=1 disables the whole scheme (the fast library is then simply kept).

Package rename — see the maintainer note above: com.zbotw.recomp everywhere (applicationId/namespace, java package, the 21 JNI names, shortcuts.xml, ACTION strings, run scripts' adb paths), plus scripts/rename_package.sh.

versionCode 43.

Why this shape

  • -O0 everywhere would cost too much performance long-term; -O1 everywhere is what made imports take an hour and a half. Profiling the actually-played session (instead of a synthetic cold scan) gives exactly the small set of functions that need -O1.
  • The 6-compiler limit is not arbitrary: -O0 jobs have a much smaller memory footprint than -O1 jobs, so the old 2-job ceiling — calibrated for -O1 — left the SoC idle during import.
  • Pinning the generator to the A76 cluster works because at -O0 the compilers stop competing for those cores; the single-threaded generator was the serial bottleneck.

Compatibility

  • Existing imported games stay valid: GAMELIB_ID (the hash that decides whether the game code must be rebuilt) is unchanged — the generator and its flags are untouched — so an app update does not force a re-import.
  • The renamed package installs beside the old one (a different applicationId is a different app to Android).
  • Desktop behavior is unchanged, and every new behavior has an env off-switch:
Env Effect
LARECOMP_NO_G95=1 stock behavior on Helio G90-family SoCs (no pinning, no uclamp)
LARECOMP_GAMEBUILD_MAX=<n> cap parallel compilers
LARECOMP_NO_UPGRADE=1 keep the fast -O0 library, never auto-upgrade

Testing

  • 0.4.2 and 0.4.3 built as release APKs (~86 MB); package and version verified with aapt2, all 21 renamed JNI symbols confirmed with llvm-nm, the new env strings confirmed present in libmain.so.
  • On the device this was built for (Helio G95, 8 GB): the first import that took about 90 minutes now finishes in minutes, and the -O1 upgrade completes in the background during normal play.
  • The run scripts (run_boot.sh, run_burst.sh, run_frames.sh, …) were updated to the new adb package paths.

PR stats

2 commits, 37 files, +579 / −496 (395 of the deletions are the two removed READMEs).

maxi000q and others added 3 commits November 14, 2026 21:38
Native mode (the game's own code on the CPU), tuned for one device:
Helio G95 (2x A76 @ 2.05 GHz + 6x A55 @ 2.0 GHz), Mali-G76, 8 GB RAM.
No UI, name or resolution changes; everything is internal.

- runtime/g95_perf.c (new): detects the SoC (mt6769/mt6785), finds the
  A76 cluster from cpufreq, pins the render thread to it, sets a
  uclamp.min floor (512) for every runtime thread, advises the game's
  code and stubs resident (madvise WILLNEED). No-op on any other SoC.
- runtime/native.c: the guest counter scaled into the Switch's 19.2 MHz
  tick (64.64 fixed-point, runtime's read path only - no rewriter
  change), so game clocks and the frame pacer keep console time on a
  Helio counter rate; native mode on by default (the menu toggle still
  wins).
- runtime/nvn/vulkan/exec.c: GPU progress waiter thread on by default
  for Mali (a timeline value read blocks in the kernel until the GPU
  catches up - the render thread stalled after every submission);
  transient ring 32 MB chunks on Mali (no device-local memory).
- platform/android.c: the render thread pin and the shared uclamp call
  go through the G95 profile first.
- CMakeLists: -O3, -march=armv8.2-a -mtune=cortex-a76,
  -ffp-contract=fast for the runtime; march stays at plain v8.2 (no
  +lse/+fp16/+dotprod) so every instruction also runs on the little
  A55 cores - no SIGILL.
- version 0.4.2 (versionCode 42); README.md / README.pt-BR.md removed.
…t build, minutes not hours) + background -O1 upgrade from the played session's own hot list

- Package rename everywhere: applicationId/namespace com.zbotw.recomp, java package and the 21 JNI
  names (Java_com_zbotw_recomp_*), shortcuts.xml, ACTION strings, the run scripts' adb paths.
- gamebuild: fast mode (GameBuildOpts.fast) - everything at -O0, no cold scan; up to 6 compilers at
  once (the 2-job cap was measured against -O1 memory) with 512/768 MB floors; LARECOMP_GAMEBUILD_MAX.
- The generator (single-threaded Python, the other half of the wait) pinned to the A76 cores on a
  Helio G90 family SoC (g95_pin_pid_big), where the -O0 compilers don't need them.
- After the first play session: fnprof (the project's own profiler) records the functions the
  player's game entered; the next start screen rebuilds the game code at -O1 in the background with
  that list (hot at -O1, the rest optnone) - full frame rate, no waiting. LARECOMP_NO_UPGRADE=1 off.
…lickering

The pass barrier was ALL_COMMANDS -> ALL_COMMANDS at every pass boundary, the most
expensive thing to ask of a tiler between two render passes (Mali-G76: it drains the
whole pipeline, hundreds of times a frame). LARECOMP_VK_NO_PASS_BARRIER=1 measured its
cost - a large fps gain - at the price of flickering: passes read targets whose stores
were not yet visible and wrote ones still being sampled.

- pass_barrier (begin_pass): what the previous pass / dispatch / copy wrote, made
  visible with narrow stage / access masks (attachment stores -> attachment loads,
  sampling, tests, vertex / index reads; compute -> the same + indirect; transfer ->
  the same) - the same dependencies, none of the drain. Nothing written since the
  last barrier: no barrier at all.
- Writers tracked in the main command buffer: pass stores (vk_end_pass), dispatches,
  texture copies / blits / resolves / uploads, readbacks, feedback snapshots, alias
  and arena copies, the post passes. Reset by a full barrier there and by a waited-on
  submission; kept across the async chunk submissions inside a frame (that missing
  link was the flickering).
- LARECOMP_VK_PASS_BARRIER: 0 none (as NO_PASS_BARRIER), 1 scoped (default),
  2 the old full barrier. versionCode 44.
@mamcjr

mamcjr commented Nov 16, 2026

Copy link
Copy Markdown
Owner

Thanks for sharing all this work on the Helio G95. As it is, I can't merge it: besides the conflicts, the package rename and the README removal are things upstream keeps as they are, and a few changes would break other phones. Some of the ideas are worth having, though, as separate small PRs on current main:

Would be welcome as their own PR:

  • The Mali GPU-progress waiter on by default, with fps numbers on Mali. Main has reworked that spot since 0.4.1 (Turnip default, per-submission fences), so it needs redoing there.

  • A fast first game-code build at -O0, upgraded to -O1 in the background. Main has nothing like it. The current version isn't safe yet:

    • gamebuild_run deletes the current library and its .id at the start, so a failed upgrade, or Play during it, leaves no game code.
    • The -O0 library carries the same GAMELIB_ID, so it looks complete and is never rebuilt.
    • The upgrade state lives only in memory, so it's lost when the app is closed.
    • Fast mode raises the jobs to 6 even where the RAM formula gave 2, which risks low-memory kills on 4 GB phones.

    A distinct marker for the -O0 library, a build into a temp file that's swapped in at the end, a saved upgrade state, and Play blocked during the rebuild would make it mergeable.

  • Narrow barriers between passes on tilers, as a careful rewrite. The current 9d62822 replaces 12 real vkCmdCopy* / vkCmdBlitImage / vkCmdResolveImage calls with pass_note_writers(...), including uploads, readbacks and the feedback snapshots, so those copies no longer happen at all (that may be why the flicker went away). The masks also miss colour/depth writes and fragment-shader storage writes, and vk_wait_seq clears tracked writes for commands not yet submitted.

Won't come in:

  • Counter scaling in native.c: main does it since e9d2375. The PR's factor is inverted ((f << 64) / 19.2 MHz multiplies by f / 19.2M, so a 13 MHz counter runs at ~8.8 MHz instead of 19.2), and the game's inline mrs reads stay raw.
  • Native mode on by default: a global change, and with it build_game_code builds nothing.
  • The G95 profile:
    • Main already pins the render thread (LARECOMP_RENDER_BIG) and has LARECOMP_UCLAMP_MIN as an opt-in. uclamp.min 512 on every thread costs power and heat with no measured gain.
    • Also, MT6769 is the G85 family; the G95 is MT6785.
  • -O3 -mtune=cortex-a76 -ffp-contract=fast for every phone: -ffp-contract=fast changes float results in the runtime's own math.
  • The rename script, the README removal and the version bumps.

If you send any of the first three, please base it on current main and include the measurements.

@maxi000q

Copy link
Copy Markdown
Contributor Author

Thank you for taking the time to go through it in that much detail - the counter-scaling factor inversion, the MT6769/G95 mix-up and the uclamp note were all news to me, and the jobs point about the 2-vs-6 calibration was exactly right.

Understood on the rename, the README removal, the version bumps and the NCE-by-default: they're gone. #417 is closed - I'll keep my fork's package name local to it.

The three you said would be welcome, redone on current main as separate PRs:

  • The Mali GPU-progress waiter, on by default - Mali: the GPU-progress waiter thread on by default #466. Redone against the Turnip/per-submission-fence layout: Mali slots into the existing default (vk_driver_is_mali in device.c), the fences and the no-timeline-signalling path are yours untouched. Numbers in the PR.
  • The fast first build, made safe - Fast first game-code build (-O0), upgraded to -O1 from the played session #467. A distinct -fast marker in the library's id (both the .id file and the tables it exports), the upgrade built into the temp file and swapped in by the final rename with the current library kept (keep_current), the state on disk (marker + the session's fnprof file, rewritten every 1800 frames), PLAY blocked while the rebuild goes, and the compiler count left to the memory formula (cores/2, no raised cap).
  • The narrow pass barriers, as a careful rewrite - Scoped pass barriers: the dependency without the ALL_COMMANDS drain #468. Every vkCmdCopy* / Blit / Resolve stays a real call (the old version replacing them with bookkeeping was the flicker's real cause, wasn't it) - pass_note_writers is a one-line note after each; the masks now carry colour/depth writes and fragment-shader storage writes; and vk_wait_seq clears only the submissions that completed (pass_writers_seq), never commands recorded after the waited-on one.

All three carry the measurements from the G95. If you'd rather have any of them smaller (say, the barrier PR without the dchain change, or the fast build without the launcher wiring), say so and I'll split them.

@maxi000q maxi000q closed this Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants