Skip to content

refactor: change magic finder to stack buffer#763

Merged
Pr0methean merged 11 commits intomasterfrom
change-magic-finder
Apr 6, 2026
Merged

refactor: change magic finder to stack buffer#763
Pr0methean merged 11 commits intomasterfrom
change-magic-finder

Conversation

@Its-Just-Nans
Copy link
Copy Markdown
Member

@Its-Just-Nans Its-Just-Nans commented Apr 1, 2026

  • The PR title must conform to Conventional Commits

  • specialize our MagicFinder to 4

  • use a stack array instead of a Box<[u8]>

  • reduce the BUFFER size to 1024 instead of 2048.

@Its-Just-Nans Its-Just-Nans changed the title Change magic finder fix: change magic finder to stack buffer Apr 1, 2026
Copy link
Copy Markdown
Contributor

@amazon-q-developer amazon-q-developer bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look good overall. This PR successfully optimizes the MagicFinder by specializing it to work with 4-byte magic signatures and replacing heap allocation with stack allocation. The implementation is clean and consistent across both modified files.


You can now have the agent implement changes and create commits directly on your pull request's source branch. Simply comment with /q followed by your request in natural language to ask the agent to make changes.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors MagicFinder and OptimisticMagicFinder to use fixed-size stack buffers and a defined MagicSize type, replacing heap-allocated slices and improving memory locality. Visibility for these internal components has been restricted to pub(crate). Feedback suggests considering MaybeUninit for the 2KB buffer in MagicFinder to avoid the performance cost of zero-initialization.

Comment thread src/read/magic_finder.rs Outdated
@Its-Just-Nans Its-Just-Nans changed the title fix: change magic finder to stack buffer DRAFT fix: change magic finder to stack buffer Apr 1, 2026
Comment thread src/read/magic_finder.rs
) -> Self {
Self {
buffer: vec![0; BUFFER_SIZE].into_boxed_slice(),
buffer: [0; BUFFER_SIZE],
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the change

@Its-Just-Nans Its-Just-Nans changed the title DRAFT fix: change magic finder to stack buffer fix: change magic finder to stack buffer Apr 4, 2026
@Its-Just-Nans
Copy link
Copy Markdown
Member Author

CI is currently blocked by rust-lang/libz-sys#265

@Its-Just-Nans
Copy link
Copy Markdown
Member Author

Currently this MR also reduces the BUFFER size to 1024 instead of 2048.

2048 would only be useful if there is a comment I think

Copy link
Copy Markdown
Member

@Pr0methean Pr0methean left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly looks good, but a couple of nits.

Comment thread src/read/magic_finder.rs Outdated
Comment thread src/read/magic_finder.rs Outdated
@Pr0methean Pr0methean enabled auto-merge April 6, 2026 05:12
@Pr0methean Pr0methean mentioned this pull request Apr 6, 2026
@Its-Just-Nans Its-Just-Nans changed the title fix: change magic finder to stack buffer refactor: change magic finder to stack buffer Apr 6, 2026
@Pr0methean Pr0methean added this pull request to the merge queue Apr 6, 2026
Merged via the queue into master with commit ef6392d Apr 6, 2026
133 checks passed
@Pr0methean Pr0methean deleted the change-magic-finder branch April 6, 2026 09:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants