Skip to content

refactor: move hash database from wow-mpq to warcraft-rs CLI#51

Merged
danielsreichenbach merged 5 commits into
mainfrom
50-move-hash-database-to-warcraft-rs
Feb 22, 2026
Merged

refactor: move hash database from wow-mpq to warcraft-rs CLI#51
danielsreichenbach merged 5 commits into
mainfrom
50-move-hash-database-to-warcraft-rs

Conversation

@danielsreichenbach

Copy link
Copy Markdown
Member

Summary

Closes #50.

  • Move the hash database module from wow-mpq (format library) to warcraft-rs (CLI application)
  • Replace rusqlite with turso (async SQLite), making the CLI async via #[tokio::main]
  • Promote calculate_mpq_hashes and calculate_het_hashes to wow_mpq::crypto and re-export from crate root
  • Remove 4 dependencies from wow-mpq: rusqlite (bundled SQLite C compilation), directories, chrono, glob
  • Optimize bulk inserts with transaction batching, WAL mode, and prepared statement caching

Performance

Profiling with perf/flamegraph identified per-row fsync as the bottleneck. Three optimizations applied:

Archive Files Before After
art.MPQ (Cata) 185k ~6 min 15s
common.MPQ (TBC) 81k ~10 min 3.6s
Full import (5 clients) 715k hours 18 min

Tested against

All 5 WoW client versions with original MPQ archives:

  • Vanilla 1.12.1 (14 archives)
  • TBC 2.4.3 (12 archives)
  • WotLK 3.3.5a (18 archives)
  • Cata 4.3.4 (25 archives, including wow-update-* patches)
  • MoP 5.4.8 (58 archives, including wow-update-* patches)

714,916 unique filenames recorded. All db subcommands verified: status, lookup, list --use-db, --record-to-db.

Test plan

  • cargo clippy --workspace clean
  • cargo test --workspace passes
  • Manual: mpq db status shows database location and count
  • Manual: mpq list <archive> --record-to-db records filenames
  • Manual: mpq db lookup <filename> finds hash entries
  • Manual: mpq list <archive> --use-db resolves unnamed files
  • StormLib comparison on base.MPQ confirms matching file lists

The hash database maps filenames to MPQ hash values for file resolution
when archives lack listfiles. This is an application-level concern, not
a format parsing responsibility.

Move the database module from wow-mpq to warcraft-rs and replace
rusqlite with turso (async SQLite). This removes rusqlite (with bundled
SQLite C compilation), directories, chrono, and glob from wow-mpq.

Changes:
- Promote calculate_mpq_hashes/calculate_het_hashes to wow_mpq::crypto
- Create warcraft-rs/src/database/ with turso async API
- Make CLI async with #[tokio::main]
- Make mpq command dispatch, list_archive, execute_db_command async
- Add standalone list_with_db and record_listfile_to_db helpers
- Remove wow-mpq/src/database/ and related archive methods
- Remove rusqlite, directories, chrono, glob from wow-mpq deps
- Add tokio, turso, directories to warcraft-rs deps

Closes #50
Profiling with perf/flamegraph revealed per-row fsync as the dominant
bottleneck in store_filenames. Three optimizations applied:

- Wrap all inserts in a single BEGIN/COMMIT transaction
- Enable WAL journal mode and synchronous=NORMAL
- Use prepare_cached to reuse compiled SQL across rows
- Remove redundant SELECT existence check before each INSERT

Benchmarks on art.MPQ (185k filenames): from ~6 min down to ~15s.
Full import of all 5 WoW clients (714k filenames): ~18 min total.
Add flamegraph and inferno for performance profiling. Add node,
cargo-binstall, wasm-pack, mdbook-mermaid. Reorganize into sections.
@codecov

codecov Bot commented Feb 21, 2026

Copy link
Copy Markdown

The database module depends on turso and wow_mpq, which are only
available when the mpq feature is enabled. Gate the module declaration
and make turso/directories optional deps activated by the mpq feature.

Fixes no-default-features build failure in CI.
@danielsreichenbach
danielsreichenbach merged commit 346e829 into main Feb 22, 2026
15 of 17 checks passed
@danielsreichenbach
danielsreichenbach deleted the 50-move-hash-database-to-warcraft-rs branch February 22, 2026 02:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Move hash database from wow-mpq to warcraft-rs and replace rusqlite with turso

1 participant