Skip to content

Attempt to optimize charmaps#1954

Merged
Rangi42 merged 3 commits intogbdev:masterfrom
Rangi42:optimize-charmap
Apr 17, 2026
Merged

Attempt to optimize charmaps#1954
Rangi42 merged 3 commits intogbdev:masterfrom
Rangi42:optimize-charmap

Conversation

@Rangi42
Copy link
Copy Markdown
Contributor

@Rangi42 Rangi42 commented Apr 16, 2026

This came up in discussion regarding https://burntsushi.net/transducers/.

There are a lot of possible ways we could optimize our charmap data structure and algorithms. So far this PR only implements one, and hasn't tried measuring whether it's even a reliable improvement yet.

@Rangi42 Rangi42 added this to the 1.0.2 milestone Apr 16, 2026
@Rangi42 Rangi42 requested a review from ISSOtm April 16, 2026 22:55
@Rangi42 Rangi42 added rgbasm This affects RGBASM optimization This increases performance or decreases size labels Apr 16, 2026
@Rangi42 Rangi42 marked this pull request as draft April 16, 2026 22:55
@Rangi42
Copy link
Copy Markdown
Contributor Author

Rangi42 commented Apr 16, 2026

Tested this on data/maps/map_data.asm from polishedcrystal, which has a lot of the game's text. Comparing 5 runs of time rgbasm -Weverything -Wtruncation=1 -E -Q8 -P includes.asm -DDEBUG -o data/maps/map_data.o data/maps/map_data.asm with a truncated mean (mean after discarding min and max):

  • current: [26.599s, 26.669s, 28.228s, 28.877s, 29.631s] = avg 27.925s
  • this PR: [26.492s, 26.502s, 26.619s, 27.149s, 27.834s] = avg 26.757s (1.04x speedup)

Not sure if this is significant, but it's at least not harming performance so far.

Also, to measure maximum RAM usage, /usr/bin/time -v rgbasm ... reports the "Maximum resident set size (kbytes)":

  • current: [34700, 34704, 34704, 34708, 34728] = avg 34705 KB
  • this PR: [32480, 32480, 32480, 32480, 32480] = avg 32480 KB (1.07x improvement)

@Rangi42 Rangi42 marked this pull request as ready for review April 17, 2026 19:12
Rangi42 added 3 commits April 17, 2026 15:15
This should save memory at the cost of O(n) instead of O(1) access,
which should be okay because the `next` vector is generally small.
@Rangi42 Rangi42 merged commit 71dfab3 into gbdev:master Apr 17, 2026
25 checks passed
@Rangi42 Rangi42 deleted the optimize-charmap branch April 17, 2026 19:39
Copy link
Copy Markdown
Member

@ISSOtm ISSOtm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR looks no worse than the previous implementation, but I'm thinking that this entire module is starved for comments, heh.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

optimization This increases performance or decreases size rgbasm This affects RGBASM

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants