PE: preallocate symbol_key in CodeViewInfo #529

Closed
github-bot wants to merge 1 commit from github-bot/gh-529 into main AGit
Owner

@⁠pushkarreddyy on GitHub · 2026-11-24 04:30 UTC · original
pushkarreddyy:perf/pe-symbol-key-alloc → main · +19 −3 · 1 files · 1 commits · closed without merging

Motivation

When constructing symbol lookup keys in CodeViewInfo::symbol_key(), the previous implementation used format! repeatedly:

  1. format!("{d1:08X}{d2:04X}{d3:04X}")
  2. format!("{b:02X}") within an 8-iteration loop, calling push_str on each byte
  3. format!("{:X}", self.age) and another push_str

This caused multiple intermediate string allocations and reallocations on each symbol key lookup.

Solution

  • Preallocate the destination String with capacity 40 using String::with_capacity(40).
  • Use core::fmt::Write to format hexadecimal values directly into the buffer with zero intermediate heap allocations.
  • Add unit test symbol_key_matches_pdb_convention verifying symbol key format conformance.

No game files used.

**@⁠pushkarreddyy** on GitHub · 2026-11-24 04:30 UTC · [original](https://github.com/Marvisak/VIctory/pull/529) `pushkarreddyy:perf/pe-symbol-key-alloc` → `main` · +19 −3 · 1 files · 1 commits · closed without merging ## Motivation When constructing symbol lookup keys in `CodeViewInfo::symbol_key()`, the previous implementation used `format!` repeatedly: 1. `format!("{d1:08X}{d2:04X}{d3:04X}")` 2. `format!("{b:02X}")` within an 8-iteration loop, calling `push_str` on each byte 3. `format!("{:X}", self.age)` and another `push_str` This caused multiple intermediate string allocations and reallocations on each symbol key lookup. ## Solution - Preallocate the destination `String` with capacity 40 using `String::with_capacity(40)`. - Use `core::fmt::Write` to format hexadecimal values directly into the buffer with zero intermediate heap allocations. - Add unit test `symbol_key_matches_pdb_convention` verifying symbol key format conformance. No game files used.
# Conflicts:
#	crates/victory-pe/src/image.rs
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:07:16 +00:00
Author
Owner

@⁠pushkarreddyy on GitHub · 2026-11-24 04:51 UTC · original

### Technical Verification & Implementation Details

Context & Root Cause

In crates/victory-pe/src/image.rs, CodeViewInfo::symbol_key() used repeated format! heap allocations:

  1. Initial GUID formatting via format!.
  2. Loop over 8 GUID bytes calling format!("{b:02X}") and push_str on each byte.
  3. Formatting age with format!("{:X}") and push_str.
    This caused multiple heap allocations per symbol key lookup.

Changes & Diff

  • Preallocated the destination string with String::with_capacity(40).
  • Formatted components directly into the buffer using core::fmt::Write.
  • Added unit test symbol_key_matches_pdb_convention.

Git Log Line & Verification

ext 9cf9f2f PE: preallocate symbol_key in CodeViewInfo crates/victory-pe/src/image.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-)

  • Passes cargo xtask policy (Rule #1 compliance, zero game assets).
  • Formatted with rustfmt --edition 2024.
**@⁠pushkarreddyy** on GitHub · 2026-11-24 04:51 UTC · [original](https://github.com/Marvisak/VIctory/pull/529#issuecomment-7122400121) ### Technical Verification & Implementation Details #### Context & Root Cause In `crates/victory-pe/src/image.rs`, `CodeViewInfo::symbol_key()` used repeated `format!` heap allocations: 1. Initial GUID formatting via `format!`. 2. Loop over 8 GUID bytes calling `format!("{b:02X}")` and `push_str` on each byte. 3. Formatting age with `format!("{:X}")` and `push_str`. This caused multiple heap allocations per symbol key lookup. #### Changes & Diff - Preallocated the destination string with `String::with_capacity(40)`. - Formatted components directly into the buffer using `core::fmt::Write`. - Added unit test `symbol_key_matches_pdb_convention`. #### Git Log Line & Verification ` ext 9cf9f2f PE: preallocate symbol_key in CodeViewInfo crates/victory-pe/src/image.rs | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) ` - Passes `cargo xtask policy` (Rule #1 compliance, zero game assets). - Formatted with `rustfmt --edition 2024`.
Author
Owner

@⁠pushkarreddyy on GitHub · 2026-11-24 06:15 UTC · original

Thank you @⁠LAKSHYA-cmd-tech for the Windows 11 review and verification! Appreciate the confirmation on the test suite and clippy pass.

**@⁠pushkarreddyy** on GitHub · 2026-11-24 06:15 UTC · [original](https://github.com/Marvisak/VIctory/pull/529#issuecomment-7123739734) Thank you @⁠LAKSHYA-cmd-tech for the Windows 11 review and verification! Appreciate the confirmation on the test suite and clippy pass.
Author
Owner

@⁠pushkarreddyy on GitHub · 2026-11-24 06:23 UTC · original

### Ready for Merge
Verified and approved on Windows 11 by @⁠LAKSHYA-cmd-tech (all unit tests passing, zero Clippy warnings, asset policy passing).

@⁠Marvisak: Ready for maintainer review and merge when you have time!

**@⁠pushkarreddyy** on GitHub · 2026-11-24 06:23 UTC · [original](https://github.com/Marvisak/VIctory/pull/529#issuecomment-7123887716) ### Ready for Merge Verified and approved on Windows 11 by @⁠LAKSHYA-cmd-tech (all unit tests passing, zero Clippy warnings, asset policy passing). @⁠Marvisak: Ready for maintainer review and merge when you have time!
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:16 UTC · original · edited 2026-11-25 02:22 UTC

Automated triage for the maintainers.

This PR rewrites CodeViewInfo::symbol_key (crates/victory-pe/src/image.rs) to write! into a preallocated String instead of using format!. Its only caller is the inspect command (apps/victory/src/inspect.rs), which prints the key once per run, so saving a few allocations there has no measurable effect. The output is unchanged.

The rebased head also does not compile. There is an extra } after the new symbol_key_matches_pdb_convention test at the end of the file, and CI is failing (check).

A test for the key format alone would be fine to add, but as a PR this is a no-value change. This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the triage: proposed close label.


Generated by Claude Code

**@⁠Marvisak** on GitHub · 2026-11-25 01:16 UTC · [original](https://github.com/Marvisak/VIctory/pull/529#issuecomment-7149381677) · edited 2026-11-25 02:22 UTC <!-- victory-triage v1 head=963f29a1114cfaeecf4051ccd91baa2ed6676700 verdict=proposed-close at=2026-11-25T02:20:29Z --> Automated triage for the maintainers. This PR rewrites `CodeViewInfo::symbol_key` (`crates/victory-pe/src/image.rs`) to `write!` into a preallocated `String` instead of using `format!`. Its only caller is the `inspect` command (`apps/victory/src/inspect.rs`), which prints the key once per run, so saving a few allocations there has no measurable effect. The output is unchanged. The rebased head also does not compile. There is an extra `}` after the new `symbol_key_matches_pdb_convention` test at the end of the file, and CI is failing (`check`). A test for the key format alone would be fine to add, but as a PR this is a no-value change. This PR will be closed in 48 hours unless the author pushes a change or a maintainer removes the `triage: proposed close` label. --- _Generated by [Claude Code](https://claude.ai/code)_
github-bot closed this pull request 2026-11-26 15:19:49 +00:00
Author
Owner

@⁠LAKSHYA-cmd-tech on GitHub · 2026-11-24 04:57 UTC · original · approved these changes

Verified on Windows 11:

  • All 8 \ ictory-pe\ tests pass, including the new \symbol_key_matches_pdb_convention.
  • Clippy clean; preallocated \String::with_capacity(40)\ and \core::fmt::Write\ eliminate intermediate allocations.
  • Asset policy passes.
**@⁠LAKSHYA-cmd-tech** on GitHub · 2026-11-24 04:57 UTC · [original](https://github.com/Marvisak/VIctory/pull/529#pullrequestreview-6033884398) · **approved these changes** Verified on Windows 11: - All 8 \ ictory-pe\ tests pass, including the new \symbol_key_matches_pdb_convention\. - Clippy clean; preallocated \String::with_capacity(40)\ and \core::fmt::Write\ eliminate intermediate allocations. - Asset policy passes.
Author
Owner

@⁠catminou4 on GitHub · 2026-11-24 11:49 UTC · original · reviewed

Test-merge with current main (ffe310e) is clean. cargo test -p victory-pe --locked (macOS arm64, rustc 1.98.1): 4 passed / 4 failed — but the 4 failures are image::tests::{parses_own_test_binary, rejects_iat_outside_image, rva_to_file_offset_maps_entry_point, rva_to_file_offset_rejects_offsets_past_4_gib}, and I verified the same 4 fail on unmodified main. So this PR introduces no regression; its own symbol_key preallocation test passes.

Side finding for the maintainer: those image::tests look Windows-assuming — parses_own_test_binary parses the test executable as a PE, but on macOS/Linux the test binary is Mach-O/ELF. They probably need a #[cfg(windows)] gate (or a bundled fixture). Not this PR's problem, but main is red on non-Windows for victory-pe.

**@⁠catminou4** on GitHub · 2026-11-24 11:49 UTC · [original](https://github.com/Marvisak/VIctory/pull/529#pullrequestreview-6038653347) · **reviewed** Test-merge with current main (`ffe310e`) is clean. `cargo test -p victory-pe --locked` (macOS arm64, rustc 1.98.1): **4 passed / 4 failed** — but the 4 failures are `image::tests::{parses_own_test_binary, rejects_iat_outside_image, rva_to_file_offset_maps_entry_point, rva_to_file_offset_rejects_offsets_past_4_gib}`, and I verified the **same 4 fail on unmodified main**. So this PR introduces no regression; its own `symbol_key` preallocation test passes. Side finding for the maintainer: those `image::tests` look Windows-assuming — `parses_own_test_binary` parses the test executable as a PE, but on macOS/Linux the test binary is Mach-O/ELF. They probably need a `#[cfg(windows)]` gate (or a bundled fixture). Not this PR's problem, but main is red on non-Windows for victory-pe.
Author
Owner

@⁠pushkarreddyy on GitHub · 2026-11-26 15:18 UTC · original

Closing this PR after reviewing the triage feedback:

  • CodeViewInfo::symbol_key is only called once per inspect run, so preallocating the String has no measurable impact and produces identical output.

Thank you for the review.

AI-assisted: yes (Gemini 4 Neon)

**@⁠pushkarreddyy** on GitHub · 2026-11-26 15:18 UTC · [original](https://github.com/Marvisak/VIctory/pull/529#issuecomment-7196092588) Closing this PR after reviewing the triage feedback: - `CodeViewInfo::symbol_key` is only called once per `inspect` run, so preallocating the `String` has no measurable impact and produces identical output. Thank you for the review. AI-assisted: yes (Gemini 4 Neon)

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!529
No description provided.