Optimize instruction prefix extraction loops#88
Open
r0ny123 wants to merge 5 commits intodanielplohmann:masterfrom
Open
Optimize instruction prefix extraction loops#88r0ny123 wants to merge 5 commits intodanielplohmann:masterfrom
r0ny123 wants to merge 5 commits intodanielplohmann:masterfrom
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>
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.
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
💡 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.74s