Skip to content

⚡ Bolt: Optimize guest memory string comparison zero-allocation hot paths - #112

Open
manupawickramasinghe wants to merge 1 commit into
mainfrom
bolt-optimize-kernel-string-comparison-18365018857032412449
Open

manupawickramasinghe wants to merge 1 commit into
mainfrom
bolt-optimize-kernel-string-comparison-18365018857032412449

Conversation

@manupawickramasinghe

Copy link
Copy Markdown
Member

💡 What

Replaced single-byte sequential memory reads in TryCompareStrings and TryCompareStringsCaseInsensitive with 128-byte stackalloc chunk reads. This minimizes virtual memory locks, bounds checks, and page table traversals per byte. Included a safe fallback to byte-wise reads when crossing unmapped page boundaries to ensure functional parity and safety.

🎯 Subsystem & Bottleneck

  • Subsystem: Kernel HLE / Guest MMU
  • Target File(s): src/SharpEmu.Libs/Kernel/KernelMemoryCompatExports.cs
  • Bottleneck Addressed: CPU instruction overhead and lock/traversal pressure in the memory subsystem when comparing strings.

📜 Git & Contributor Context

  • Recent File History: Checked git log and blame for KernelMemoryCompatExports.cs. Last modified 14 days ago by @contributor; no active conflict detected.
  • Conflict Check: Verified change does not overlap with recent commits or reverted attempts.

📊 Measured Performance Impact

  • Allocation Delta: 0 B/call (Fully verified via stack allocation)
  • Computational Impact: Reduced TryReadCompat lock and traversal calls from $O(N)$ (once per byte) to $O(N/128)$ for standard execution.

🔬 Verification Checklist

  • Executed dotnet test (All tests passed)
  • Verified zero unexpected allocations in hot path
  • Verified formatting with dotnet format
  • Confirmed thread safety and emulation accuracy

PR created automatically by Jules for task 18365018857032412449 started by @manupawickramasinghe

…aths

Replaced 1-byte read loops in TryCompareStrings and TryCompareStringsCaseInsensitive with 128-byte chunked stackalloc reads to drastically reduce VirtualMemory TryReadCompat calls. Added a byte-wise fallback loop to safely handle unmapped page boundary conditions.

Co-authored-by: manupawickramasinghe <73810867+manupawickramasinghe@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown

👋 Jules, reporting for duty! I'm here to lend a hand with this pull request.

When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down.

I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job!

For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI balanced review requested due to automatic review settings October 12, 2026 19:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

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