HLE: find an import's implementation by name, not by scanning every module #141

Closed
github-bot wants to merge 1 commit from gh-pr/141/head into gh-pr/141/base
Owner

@⁠TG0000 on GitHub · 2026-11-24 00:54 UTC · original
TG0000:perf/hle-import-index → main · +320 −6 · 1 files · 1 commits · closed without merging

What

registry::lookup binds every title import we implement and serves GetProcAddress on host modules (host_override). For each call it walked all modules, and each module's serves lower-cased the DLL name into a new String before testing its patterns. Then it compared the name against every export of the serving modules. A miss paid the full cost, and every import we leave to the host is a miss.

The registry is now indexed once, by export name, in registry order, keeping the first export of a name in each module. A lookup:

  1. hashes the name with FNV-1a (the keys are our own export names, so the default hasher's resistance to chosen keys buys nothing);
  2. tests the DLL patterns of only the modules that export that name (nearly always one), case-insensitively and without allocating.

The result doesn't change: the first serving module in registry order wins, and within it the first export with that name. HleModule::serves and the other callers are untouched, and only crates/victory-hle/src/registry.rs changes.

Numbers

Release build, one core. The benchmark looks up every registry export under each DLL name that serves it (upper-cased, API sets with a version suffix), plus one host-only miss per DLL name. That's 605 lookups, best of 5, over 3 runs:

ns per import
scan (before) 444–489
index (after) 41–46
speedup 10.3x–11.8x

To run it: cargo test --release -p victory-hle registry_lookup_throughput -- --ignored --nocapture

Tests

  • The index matches the old scan for every DLL pattern (as written, upper-cased, versioned API sets, unserved names, empty and 200-byte names) crossed with every export name plus misses. This runs on the real registry and on overlapping synthetic modules (exact and prefix patterns serving the same DLL, one name exported by two modules, one name exported twice by a single module, a module with no DLLs).
  • matches agrees with HleModule::serves on mixed-case, non-ASCII, empty and prefix-boundary names.
  • Every registry pattern is lower case, which the case-insensitive match relies on.
  • 300 modules sharing one export name keep registry order.
  • An ignored throughput benchmark.

Checked with:

  • cargo test --workspace --exclude victory-gpu: all pass.
  • cargo clippy -p victory-hle --all-targets: no warnings in the touched file.
  • cargo xtask policy: OK.
  • cargo fmt --check on the file: clean.

victory-gpu's tests don't build on current main (9aef3d9): crates/victory-gpu/src/host.rs defines mod tests twice (lines 252 and 1974). This PR doesn't touch that crate, so I left it out of the workspace run.

Doesn't overlap any open PR.

This PR is AI-assisted (Claude). It was tested on Windows 11 with the MSVC stable toolchain, using unit tests and a synthetic release benchmark. No game data is involved and nothing needed a GPU.

🤖 Generated with Claude Code

**@⁠TG0000** on GitHub · 2026-11-24 00:54 UTC · [original](https://github.com/Marvisak/VIctory/pull/141) `TG0000:perf/hle-import-index` → `main` · +320 −6 · 1 files · 1 commits · closed without merging ## What `registry::lookup` binds every title import we implement and serves `GetProcAddress` on host modules (`host_override`). For each call it walked all modules, and each module's `serves` lower-cased the DLL name into a new `String` before testing its patterns. Then it compared the name against every export of the serving modules. A miss paid the full cost, and every import we leave to the host is a miss. The registry is now indexed once, by export name, in registry order, keeping the first export of a name in each module. A lookup: 1. hashes the name with FNV-1a (the keys are our own export names, so the default hasher's resistance to chosen keys buys nothing); 2. tests the DLL patterns of only the modules that export that name (nearly always one), case-insensitively and without allocating. The result doesn't change: the first serving module in registry order wins, and within it the first export with that name. `HleModule::serves` and the other callers are untouched, and only `crates/victory-hle/src/registry.rs` changes. ## Numbers Release build, one core. The benchmark looks up every registry export under each DLL name that serves it (upper-cased, API sets with a version suffix), plus one host-only miss per DLL name. That's 605 lookups, best of 5, over 3 runs: | | ns per import | |---|---| | scan (before) | 444–489 | | index (after) | 41–46 | | speedup | **10.3x–11.8x** | To run it: `cargo test --release -p victory-hle registry_lookup_throughput -- --ignored --nocapture` ## Tests - The index matches the old scan for every DLL pattern (as written, upper-cased, versioned API sets, unserved names, empty and 200-byte names) crossed with every export name plus misses. This runs on the real registry and on overlapping synthetic modules (exact and prefix patterns serving the same DLL, one name exported by two modules, one name exported twice by a single module, a module with no DLLs). - `matches` agrees with `HleModule::serves` on mixed-case, non-ASCII, empty and prefix-boundary names. - Every registry pattern is lower case, which the case-insensitive match relies on. - 300 modules sharing one export name keep registry order. - An ignored throughput benchmark. Checked with: - `cargo test --workspace --exclude victory-gpu`: all pass. - `cargo clippy -p victory-hle --all-targets`: no warnings in the touched file. - `cargo xtask policy`: OK. - `cargo fmt --check` on the file: clean. `victory-gpu`'s tests don't build on current `main` (9aef3d9): `crates/victory-gpu/src/host.rs` defines `mod tests` twice (lines 252 and 1974). This PR doesn't touch that crate, so I left it out of the workspace run. Doesn't overlap any open PR. This PR is AI-assisted (Claude). It was tested on Windows 11 with the MSVC stable toolchain, using unit tests and a synthetic release benchmark. No game data is involved and nothing needed a GPU. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
Each import the title binds, and each GetProcAddress on a host module,
went through registry::lookup: every module lower-cased the DLL name into
a fresh String to test its patterns, then every export of the serving
modules was compared by name. A miss, which every import we leave to the
host is, paid for all of it.

The registry is now indexed once by export name, in registry order, with
the first export of a name in each module. A lookup hashes the name (FNV,
the keys are our own export names), and only the modules exporting it test
their patterns, case-insensitively and without allocating. The first
serving module and its first export still win, as in the scan.

Release, one core, every registry export under each DLL name that serves
it plus one host-only miss per name (605 lookups, best of 5, 3 runs):
scan 444-489 ns, index 41-46 ns per import (10.3x-11.8x).

Tests: the index against the old scan for every DLL pattern (as written,
upper-cased, versioned API sets) by every export name and misses, on the
registry and on overlapping synthetic modules; pattern matching against
HleModule::serves; registry patterns are lower case; 300 modules sharing
a name keep registry order; an ignored throughput benchmark.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 03:52:00 +00:00
github-bot closed this pull request 2026-11-26 03:52:00 +00:00
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-24 04:33 UTC · original

Tested head 2f6efc1933109d4aa5e6ad4320edb8bc63086683 with cargo test -p victory-hle --lib registry -- --test-threads=1: 7 passed, 0 failed, 1 ignored (the ignored case is a benchmark; 84 unrelated tests were filtered out). Coverage includes indexed lookup agreeing with a full scan, preserving module/export order, case-insensitive patterns, and first-serving-module precedence (registry.rs). This is unit coverage; title import resolution was not exercised in a runtime.

**@⁠jeremygold02** on GitHub · 2026-11-24 04:33 UTC · [original](https://github.com/Marvisak/VIctory/pull/141#issuecomment-7122132501) Tested head `2f6efc1933109d4aa5e6ad4320edb8bc63086683` with `cargo test -p victory-hle --lib registry -- --test-threads=1`: **7 passed, 0 failed, 1 ignored** (the ignored case is a benchmark; 84 unrelated tests were filtered out). Coverage includes indexed lookup agreeing with a full scan, preserving module/export order, case-insensitive patterns, and first-serving-module precedence ([`registry.rs`](https://github.com/Marvisak/VIctory/blob/2f6efc1933109d4aa5e6ad4320edb8bc63086683/crates/victory-hle/src/registry.rs)). This is unit coverage; title import resolution was not exercised in a runtime.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!141
No description provided.