Skip to content

Conversation

@JaskRendix
Copy link
Contributor

@JaskRendix JaskRendix commented Aug 26, 2024

PR introduces a performance enhancement to decode_gid, improves test coverage, and adds a lightweight benchmark script to measure decoding speed at scale.

Changes included:

  • updated decode_gid to use a flag cache: avoids redundant TileFlags instantiations for repeated GIDs and preserves identical behavior while improving speed
  • Added unit tests to cover: cache reuse (identity check), combinations and edge cases for all flag permutations and unpack_gids robustness against empty, malformed, and truncated input
  • introduced 2 benchmark scripts

Benchmarks

  1. bench_decode_gid.py
    Benchmarks decoding performance with and without caching:
  • Measures decoding time across GID sizes (1K to 1M)
  • Example results (Python 3.12.3, pygame-ce 2.5.5):
 GID Count |   No Cache |  With Cache |  Speedup
--------------------------------------------------
      1000 | 0.0025s | 0.0027s |    0.92x
      5000 | 0.0059s | 0.0048s |    1.23x
     10000 | 0.0141s | 0.0042s |    3.35x
     50000 | 0.0580s | 0.0207s |    2.80x
    100000 | 0.1213s | 0.0426s |    2.85x
    250000 | 0.2698s | 0.1155s |    2.34x
    500000 | 0.5592s | 0.2202s |    2.54x
   1000000 | 1.0043s | 0.4050s |    2.48x
  1. bench_tmx_maps.py
    Benchmarks actual TMX map parsing using files in /apps/data/:
  • Measures average load time per map
  • Reports tile count, layer count, and tileset usage
    Map Name             | Avg Time (s) | Layers | Tilesets | Tiles
    ----------------------------------------------------------------
    acid0.tmx            |     0.0026   |   14   |     4     |   60
    iso.tmx              |     0.0091   |    6   |     2     |  300
    mapbig1.tmx          |     0.0269   |    4   |     6     |  150
    

@joereynolds
Copy link

Out of curiosity did you profile/time this at any point?
Curious how big of an affect this has on loading a map

@JaskRendix JaskRendix force-pushed the gid-and-tests branch 2 times, most recently from 4e4be5c to d1d2726 Compare February 28, 2025 15:06
@JaskRendix JaskRendix force-pushed the gid-and-tests branch 2 times, most recently from ad0f329 to 3847c1d Compare July 24, 2025 11:48
@JaskRendix JaskRendix changed the title gid and tests Optimize decode_gid with flag caching + Add tests and benchmark Jul 24, 2025
@JaskRendix JaskRendix closed this Oct 5, 2025
@JaskRendix JaskRendix deleted the gid-and-tests branch October 15, 2025 13:49
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