⚡ Optimize instruction prefix extraction loops#26
Conversation
Replaced inefficient list comprehensions with inline generator-like behavior in `getByteWithoutPrefixes` and `escapeToOpcodeOnly`. By using a static, class-level set `_PREFIXES` and doing straight array slicing, we avoid intermediate memory allocations and improve iteration performance by roughly 2x. Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
|
👋 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 New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
Code Review
This pull request refactors the prefix handling in IntelInstructionEscaper.py by introducing a centralized _PREFIXES set and utilizing slicing instead of manual string concatenation for better efficiency. A review comment suggests using a more idiomatic Python approach with a generator expression and next() to determine the prefix length, which would simplify the logic and avoid the for...else construct.
Replace the for/else loop in escapeToOpcodeOnly with a more idiomatic next() expression as suggested in code review, and apply the same pattern to getByteWithoutPrefixes for consistency. Also bind the class-level _PREFIXES set to a local name to avoid repeated attribute lookups inside the generator.
|
Addressed the review feedback in fc73014:
/gemini review Generated by Claude Code |
There was a problem hiding this comment.
Code Review
This pull request refactors the prefix handling logic in IntelInstructionEscaper.py by introducing a _PREFIXES constant and replacing manual loops with more concise generator expressions in escapeToOpcodeOnly and getByteWithoutPrefixes. The review feedback suggests moving the new constant to the top of the class to maintain consistency with existing code and extracting the duplicated prefix length calculation into a shared helper method to adhere to DRY principles.
Move _PREFIXES up next to the other class-level constants for consistency with the existing structure, and factor the duplicated prefix-length scan out of escapeToOpcodeOnly and getByteWithoutPrefixes into a shared _getPrefixLen helper.
|
Addressed both new review comments in 8344a60:
/gemini review Generated by Claude Code |
There was a problem hiding this comment.
Code Review
This pull request refactors the prefix handling in IntelInstructionEscaper.py by introducing a centralized _PREFIXES set and a helper method _getPrefixLen. This change eliminates redundant logic in escapeToOpcodeOnly and getByteWithoutPrefixes. The review feedback suggests converting _getPrefixLen from a static method to a class method to avoid hardcoding the class name and improve flexibility for potential subclassing.
💡 What:
_PREFIXESset to cache prefix lookups insmda/intel/IntelInstructionEscaper.py.[ins_bytes[i: i+2] ...]ingetByteWithoutPrefixesandescapeToOpcodeOnlywith sequential string slicing directly.🎯 Why:
📊 Measured Improvement:
getByteWithoutPrefixesandescapeToOpcodeOnlyover 100k instructions showed approx a 2x overall runtime improvement:getByteWithoutPrefixes: 0.99s -> 0.41sescapeToOpcodeOnly: 1.38s -> 0.74sPR created automatically by Jules for task 14142918817124732542 started by @r0ny123