PE: preallocate symbol_key in CodeViewInfo #529

Closed
pushkarreddyy wants to merge 1 commit from upstream-pr/529 into main
pushkarreddyy commented 2026-11-24 04:30:55 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-24T04:30:55Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:issue:6574649734 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/529). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-11-24T04:30:55Z. --- ## 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.
LAKSHYA-cmd-tech commented 2026-11-24 06:53:33 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T04:57:21Z.

Review: APPROVED


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.
<!-- greyfinch-sync:Marvisak/VIctory:review:6033884398 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/529#pullrequestreview-6033884398). Originally posted by [LAKSHYA-cmd-tech](https://github.com/LAKSHYA-cmd-tech) on 2026-11-24T04:57:21Z. **Review:** APPROVED --- 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.
pushkarreddyy commented 2026-11-24 06:55:53 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-24T04:51:24Z.


### 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.
<!-- greyfinch-sync:Marvisak/VIctory:comment:7122400121 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/529#issuecomment-7122400121). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-11-24T04:51:24Z. --- ### 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 commented 2026-11-24 06:56:17 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-24T06:15:03Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123739734 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/529#issuecomment-7123739734). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-11-24T06:15:03Z. --- Thank you @LAKSHYA-cmd-tech for the Windows 11 review and verification! Appreciate the confirmation on the test suite and clippy pass.
pushkarreddyy commented 2026-11-24 06:56:20 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-24T06:23:43Z.


### 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!

<!-- greyfinch-sync:Marvisak/VIctory:comment:7123887716 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/529#issuecomment-7123887716). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-11-24T06:23:43Z. --- ### 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!
catminou4 commented 2026-11-24 12:03:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-24T11:49:31Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6038653347 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/529#pullrequestreview-6038653347). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-24T11:49:31Z. **Review:** COMMENTED --- 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.
Marvisak commented 2026-11-25 02:05:49 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:16:32Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7149381677 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/529#issuecomment-7149381677). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T01:16:32Z. --- <!-- 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)_
upstream-sync closed this pull request 2026-11-26 16:04:13 +00:00
pushkarreddyy commented 2026-11-26 16:05:03 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-26T15:18:59Z.


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)

<!-- greyfinch-sync:Marvisak/VIctory:comment:7196092588 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/529#issuecomment-7196092588). Originally posted by [pushkarreddyy](https://github.com/pushkarreddyy) on 2026-11-26T15:18:59Z. --- 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

Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!529
No description provided.