Timing...

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Andrew Davie

One screen - an underwater one with heaps of conglomerate and mines, is slowing down terribly. I added a "cumulative time cost" recorder for the objects in a level, as it's being played. Here's the report of the top 10 most expensive objects...

boo@MacBoo WenHop-Planet-Pluto % python3 tools/update_budget_from_csv.py --cumulative-report globals_WenHopPlanetPluto_20260920_160752.csv
top 10 characters by per-frame cumulative T1TC cost:
   1. CH_CONGLOMERATE                   49825  (debug[127])
   2. CH_WATER                          31812  (debug[60])
   3. CH_ROCK                           23856  (debug[10])
   4. CH_MINE_CHAIN                     23659  (debug[144])
   5. CH_DOGE_ROLL                      12664  (debug[215])
   6. CH_MINE                            6979  (debug[143])
   7. CH_MELLON_HUSK                     4562  (debug[19])
   8. CH_DOGE_00                         4240  (debug[12])
   9. CH_MINE_CHAIN_DESTROYED            2771  (debug[213])
  10. CH_CONGLOMERATE_DETACH             1821  (debug[220])
boo@MacBoo WenHop-Planet-Pluto %

I can see here that the CH_WATER is costing a fair bit - something I actually rewrote but forgot to take the old water processing out.  So right there that's 31K cycles/frame saved.  And the conglomerate - well, that's a bit steep for something that effectively does nothing in that level.

I'll see if I can improve those times!  A very useful analysis.

Andrew Davie

Here's a post-optimisation timing block.  The water is gone, as noted.
The others - good improvements throughout.  Note these are per-game-frame times for all objects of the given type (so, a cumulative per-game-frame cost in cycles).  Add them all up and you get the total cost in terms of processing for all objects on the board. Note these are the top 10, of course.

top 10 characters by per-frame cumulative T1TC cost:
   1. CH_CONGLOMERATE                   31908  (debug[126])
   2. CH_ROCK                           22811  (debug[10])
   3. CH_MINE_CHAIN                     22301  (debug[143])
   4. CH_DOGE_ROLL                      12347  (debug[214])
   5. CH_MINE                            6643  (debug[142])
   6. CH_DOGE_00                         5255  (debug[12])
   7. CH_MINE_CHAIN_DESTROYED            5222  (debug[212])
   8. CH_MELLON_HUSK                     4552  (debug[19])
   9. CH_DUST_ROCK_1                     2702  (debug[29])
  10. CH_DUST_ROCK_0                     2702  (debug[28])

Andrew Davie

#2
Additionally, these are the top 20 maximum per-TV-frame costs for processing creatures.  The processing code will only process the given creature if there are at least this many cycles still unused in the VB/OS - wherever the creature is currently being processed.  Typically there's (say) 100K cycles in each of VB and OS - but other systems must run every frame; for example drawing the complex screen takes something like 70K cycles, drawing the 3 digit score takes about 22K cycles. That doesn't leave a lot for the character processing.  So, reducing these numbers is a good idea.

// Last updated: 2026-09-21 00:59 AEST
static const unsigned short budget[] = {

    [CH_MELLON_HUSK] = _B + 12149,                   // -- updated 2026-09-20 21:03 AEST
    [CH_CHAIN_PENDING] = _B + 6174,                  // -- updated 2026-09-20 21:02 AEST
    [CH_CRACKED_BRICK] = _B + 4321,                  // -- updated 2026-09-20 19:50 AEST
    [CH_PEBBLE1] = _B + 4167,                        // -- updated 2026-09-20 21:04 AEST
    [CH_GEODOGE_FALLING] = _B + 3461,                // -- updated 2026-09-20 21:18 AEST
    [CH_PUSH_DOWN] = _B + 2880,                      // -- updated 2026-09-20 20:50 AEST
    [CH_PUSH_UP] = _B + 2875,                        // -- updated 2026-09-20 20:50 AEST
    [CH_MINE_CHAIN_DESTROYED] = _B + 2837,           // -- updated 2026-09-20 19:27 AEST
    [CH_DOGE_FALLING] = _B + 2810,                   // -- updated 2026-09-20 19:50 AEST
    [CH_ROCK_FALLING] = _B + 2720,                   // -- updated 2026-09-20 20:32 AEST
    [CH_ACME_EXPLOSION_TRIGGER] = _B + 2679,         // -- updated 2026-09-21 00:59 AEST (+22)
    [CH_ROCK_BONUS_FALLING] = _B + 2576,             // -- updated 2026-09-20 19:33 AEST
    [CH_IMMOVABLE_FALLING] = _B + 2566,              // -- updated 2026-09-20 19:40 AEST
    [CH_ANCHOR_FALLING] = _B + 2560,                 // -- updated 2026-09-20 19:40 AEST
    [CH_CONGLOMERATE_DETACH] = _B + 2417,            // -- updated 2026-09-20 19:47 AEST
    [CH_ZAP_PENDING_STAR] = _B + 2396,               // -- updated 2026-09-20 19:33 AEST
    [CH_ZAP_PENDING_FRAG] = _B + 2390,               // -- updated 2026-09-20 19:33 AEST
    [CH_STAR] = _B + 2165,                           // -- updated 2026-09-20 19:33 AEST
    [CH_DOGE_ROLL] = _B + 2150,                      // -- updated 2026-09-20 19:50 AEST
    [CH_MINE] = _B + 2078,                           //

I have the build tools manage this table automatically; every time I hit Ctrl-G in the emulator, a CSV file with all the debug timings (well, all globals actually) is written to the project directory. Next time I do a build, this is detected and the above timings updated if there are any changes. The tool also sorts them highest-first so I can easily focus my optimisation efforts where it really counts.  Kind of a balance between the above table, and the cumulative times in the previously shown tables.

Andrew Davie

Video shows current speed of the slowest level.  "Slowest" because it takes the longest number of TV-frames to complete a single game-frame. I have no idea (honestly!) how many that is; I just look at how the gameplay feels and how fast things are moving.

It's not too bad, but you see the player movement "stagger". That needs to be smoother.