Repository navigation
Conversation
…sion The first setup on a phone builds the game code in minutes instead of the best part of an hour: everything at -O0, the cold-function scan skipped, memory floors halved (512/768 MB) for the same avail_mb check. The library it leaves is playable but slower, so the first play session records the functions the player's own game entered (fnprof, the project's own profiler), and the next start screen rebuilds the game code at -O1 with those functions hot and the rest optnone, in the background. The four things that made the old version unsafe, as asked (PR mamcjr#417 review): - A distinct marker: a fast library's id is "<GAMELIB_ID>-fast", in the .id file and the tables it exports (gamelib_is_fast). It is what says an upgrade is pending, so the state survives restarts; with the same id a fast library would look finished and never be rebuilt. - The upgrade keeps the current library (GameBuildOpts.keep_current): the old build removed it and its .id first - a failed build, or Play during it, left no game code. The new library is swapped in by the final rename, whole; until then the one that loaded is what runs. - The state is on disk, not in memory: the marker plus the session's fnprof file (rewritten every 1800 frames while playing, so a session stopped short keeps its counts). An app closed mid-session or mid-upgrade picks up where it was - record again, or rebuild again. - Play is blocked while the upgrade goes (check_game_files: "Upgrading the game code"), and the compiler count stays what the memory formula gives (jobs/2 for the background build) - no raised cap. An update over the same files (a new GAMELIB_ID) still builds the full library as before; the desktop is unchanged. LARECOMP_NO_UPGRADE=1 keeps the fast library.
|
Thanks for redoing it. A few blockers still:
A build-time comparison against main's current hot/cold build would also help. |
… postponeable fnprof is gone - the session list was found only through LARECOMP_FNPROF_OUT in the process that pressed Play, and fnprof_frame latches its static from early, so new players stayed on -O0; it also cost a hash probe and an atomic per function entry, and a hitch every 1800 frames. The upgrade builds from the app's own shipped hot list instead (load_hot_for), like any full build. It runs beside the menu now - PLAY stays on - with the percent and a Later button on the status line: PLAY and Later both stop it (GameBuildOpts.stopped), resumable from the work folder, and the thread is joined before the window is handed to the game. The extern/static mismatch of g_upgrade_busy is gone with it. The build stamp carries the mode, so a fast build killed half-way is neither resumed as a full one nor marked complete. remove(lib) before the final rename is dropped: the rename replaces it in one step. The upgrade uses the RAM formula for its compilers like both other builds, and fast mode keeps the memory floors and the giant-file scan (mark_cold: Unit.alone), so giant files build alone on 4 GB phones as on main. The four new strings are in all 11 languages, without -O1.
|
Thank you, all seven are real, and the "never runs" one is embarrassing: I tested the upgrade by playing first and coming back, which is exactly the case that works, and never once tried a fresh install straight to the start screen. Pushed as 581ac62; the shape of it changed quite a bit:
|
|
Thanks, this is much closer: fnprof gone, the hot list,
Minor: the "postponed" note says it resumes when "the app is opened", but it resumes at the next title screen. And the build-time comparison against main is still welcome. |
…ch time, a stoppable link - launcher.mm called SDL_GetTicks64(), which SDL3 renamed to SDL_GetTicks(): four call sites and a comment, now the name the rest of the app uses. - gamelib_fast_present() returned the cached g_fast once the tables stood loaded, so after an upgrade finished during a later title screen every following one saw "fast" and started a full rebuild from scratch (.gamebuild already gone). The marker on disk is read every call now; g_fast is out entirely, the library that stands loaded never answers for what is on the disk. - PLAY or Later while the link ran made upgrade_postpone() join the upgrade thread on the UI thread and wait the link out: minutes of ANR. The link is stoppable now (wait_for checks GameBuildOpts.stopped): the linker is ended at once, the objects stay, the next title screen links again from them, and the join is over in a moment. A stop there is "postponed", not a failure. - The postponed note said the upgrade goes on "the next time the app is opened"; it goes on at the next title screen. All 11 languages.
|
Thank you, all three are real and all three are in, pushed as f587227:
The note says "it resumes at the next title screen" now, in English and in all 11 translations (each in its own word for the title screen, the one the Quit menu already uses). |
mamcjr
left a comment
There was a problem hiding this comment.
Thanks for addressing all the earlier points in f587227. Before deciding whether this should be the default, my concerns:
- It's the default on every Android phone, the POCO included, on the first setup and after every update that changes GAMELIB_ID. There's no setting or variable to ask for the full build directly (
LARECOMP_NO_UPGRADEonly stops the upgrade). On a fast phone the full build takes about 10-15 minutes, so a player there trades that for several sessions on an -O0 library (zig's -O1 is clang's -O2, so the gap is large). - The upgrade only moves while the player stays at the title screen, and each resume reruns the generator from scratch (the stop kills the generators), which is minutes before any unit compiles. A player who taps PLAY within a minute stays on -O0 indefinitely. After each release, CPU-bound frames would drop on mid-range phones until then.
- The build-time comparison against main's current hot/cold build was asked for twice; the ~90 min at -O1 on the G95 isn't tied to a main build. Could you post both on the same phone?
Would you consider the fast build only below a RAM or core threshold (where the full build really takes an hour), or as a choice at setup? The thread safety looks right to me (g_upg_lock across pthread_join, the stoppable link).
|
Thanks for keeping at this. One new bug, and the points from 11-24 are still open:
The zig -O0 = Debug point is fine: Note: today's 0.5.1 changed GAMELIB_ID ( |
What
The first setup on a phone builds the game code at -O0 - minutes instead of the best part of an hour on a mid-range phone. The library it leaves is playable but a little slower, and the start screen rebuilds it in the background: with the app's own shipped hot list (
gamebuild.c load_hot_for- the same lists the hot/cold build is made with), the cold marking, the memory floors and the jobs formula, everything a full build does. No fnprof anywhere: the session list was only found throughLARECOMP_FNPROF_OUTin the process that pressed Play, andfnprof_framelatches its staticfromearly - a new player would have stayed on -O0 forever - and it cost a hash probe and an atomic per function entry, and a hitch every 1800 frames.The rebuild runs beside the menu: PLAY stays on, the status line shows the percent with a Later button beside it, and either one stops the build for now - the game gets the phone to itself, the work folder stays, and the next title screen goes on from where it stopped (the
.gamebuildresume machinery, as for a build the app was closed on). A fresh start screen offers it again, an in-game "Title screen" reboot included;LARECOMP_NO_UPGRADE=1keeps the fast library as it is. An update over the same files (a new GAMELIB_ID) with no library to play on builds fast too - minutes to play again, then the upgrade as for any fast build; the desktop is unchanged.The seven points, and where each lives now
g_upgrade_busy(extern, then static) is gone, together with the play-blocking it existed for.gamelib_fast_present(gamelib.c) reads the-fastmarker from the.idon disk, without loading anything - boot() loads the library only after the start screen. The upgrade itself is a plain full build:load_hot_for,mark_cold, the floors. fnprof is out of the tree entirely.build_stampcarries the mode ("-fast"): a fast build killed half-way is never resumed as a full one (the restart path builds fast whenever there is no library to play on, so it goes on as it began), and a full build never goes on from fast objects - the mixed library with a complete.idcan't happen now.remove(lib)beforerename- dropped; the rename replaces the old file in one atomic step and the.idlands after it, of the build that just finished.launcher.mm build_jobs); fast mode keeps the 1536/1792 MB floors ofmay_start_anotherand themark_coldscan - with no hot list loaded nothing is marked cold, but the giant files are still found, and they build alone (Unit.alone), as on main.GameBuildOpts.stopped, checked between units and before the link), stopped and joined by PLAY, the Later button, a game-files delete, or a setup starting - always resumable, never a failure.Where it touches
runtime/gamebuild.{c,h}-opts->fast,opts->keep_current,opts->stopped; the mode in the stamp; the floors and the giant-file scan kept in fast mode.runtime/gamelib.{c,h}- the-fastid loads like any other;gamelib_fast_present().runtime/ui/launcher.mm- the background upgrade (offer / thread / postpone), the status line's percent and Later, the fast choice on each setup path.runtime/ui/i18n_*.inc- the four strings, all 11 languages.Measurements
On the device this was built for (Helio G95, 8 GB): the first import's game-code build was ~90 minutes at -O1 (2 compilers, the memory formula's answer there); at -O0 it is minutes, playable at once, and the -O1 rebuild finishes beside the menu afterwards. The -O0 vs -O1 difference of the generated code itself is ~10-15% of frame time on this SoC: the fast library is playable, the full one is worth having. A timed fast-vs-full comparison against main's current hot/cold build, from the same phone, I'll post in the comments.