PE: preallocate symbol_key in CodeViewInfo #529
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/529"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 usedformat!repeatedly:format!("{d1:08X}{d2:04X}{d3:04X}")format!("{b:02X}")within an 8-iteration loop, callingpush_stron each byteformat!("{:X}", self.age)and anotherpush_strThis caused multiple intermediate string allocations and reallocations on each symbol key lookup.
Solution
Stringwith capacity 40 usingString::with_capacity(40).core::fmt::Writeto format hexadecimal values directly into the buffer with zero intermediate heap allocations.symbol_key_matches_pdb_conventionverifying symbol key format conformance.No game files used.
Imported from Marvisak/VIctory. Originally posted by LAKSHYA-cmd-tech on 2026-11-24T04:57:21Z.
Review: APPROVED
Verified on Windows 11:
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 repeatedformat!heap allocations:format!.format!("{b:02X}")andpush_stron each byte.format!("{:X}")andpush_str.This caused multiple heap allocations per symbol key lookup.
Changes & Diff
String::with_capacity(40).core::fmt::Write.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(-)cargo xtask policy(Rule #1 compliance, zero game assets).rustfmt --edition 2024.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.
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!
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 areimage::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 ownsymbol_keypreallocation test passes.Side finding for the maintainer: those
image::testslook Windows-assuming —parses_own_test_binaryparses 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.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) towrite!into a preallocatedStringinstead of usingformat!. Its only caller is theinspectcommand (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 newsymbol_key_matches_pdb_conventiontest 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 closelabel.Generated by Claude Code
Imported from Marvisak/VIctory. Originally posted by pushkarreddyy on 2026-11-26T15:18:59Z.
Closing this PR after reviewing the triage feedback:
CodeViewInfo::symbol_keyis only called once perinspectrun, so preallocating theStringhas no measurable impact and produces identical output.Thank you for the review.
AI-assisted: yes (Gemini 4 Neon)
Pull request closed