PE: preallocate symbol_key in CodeViewInfo #529
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!529
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@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 mergingMotivation
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.
@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 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.@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: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!
@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) 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
@LAKSHYA-cmd-tech on GitHub · 2026-11-24 04:57 UTC · original · approved these changes
Verified on Windows 11:
@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 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.@pushkarreddyy on GitHub · 2026-11-26 15:18 UTC · original
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