Skip to content

perf: optimize SNES identifier to read only ~66KB instead of full file#4

Merged
wizzomafizzo merged 1 commit intomainfrom
perf/snes-read-optimization
Dec 10, 2025
Merged

perf: optimize SNES identifier to read only ~66KB instead of full file#4
wizzomafizzo merged 1 commit intomainfrom
perf/snes-read-optimization

Conversation

@wizzomafizzo
Copy link
Member

Summary

  • Optimize SNES identifier to read only the necessary header data (~66KB max) instead of the entire ROM file (256KB-6MB)
  • Detect SMC header presence by checking file size rather than reading the full file first
  • Provides approximately 100x reduction in I/O for SNES files

Background

The SNES identifier was reading the entire ROM file when it only needs to read up to the HiROM header location (0xFFC0 + 32 bytes). This matches the behavior of the original Python GameID implementation.

Changes

  • Calculate read offset to skip 512-byte SMC header if present (detected via size % 1024 == 512)
  • Only read up to snesHiROMHeaderStart + snesHeaderSize bytes (~66KB)
  • ID generation remains identical to before

Test plan

  • All existing unit tests pass
  • Lint passes with 0 issues
  • Tested against real SNES ROM files in ZIP archives

The SNES identifier was reading the entire ROM file (256KB-6MB) when it
only needs to read up to the HiROM header location (0xFFC0 + 32 bytes).

Changes:
- Detect SMC header presence by checking file size (size % 1024 == 512)
- Calculate read offset to skip SMC header if present
- Only read up to ~66KB max instead of the full file

This provides approximately 100x reduction in I/O for SNES files while
maintaining identical ID generation, matching the original Python GameID
behavior.
@codecov
Copy link

codecov bot commented Dec 10, 2025

Codecov Report

❌ Patch coverage is 77.77778% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
identifier/snes.go 77.77% 1 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@wizzomafizzo wizzomafizzo merged commit 2b224dd into main Dec 10, 2025
10 checks passed
@wizzomafizzo wizzomafizzo deleted the perf/snes-read-optimization branch December 10, 2025 09:32
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.

1 participant