-
Notifications
You must be signed in to change notification settings - Fork 89
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve MetalLexer Performance Using Combined Regular Expression #250
Labels
Comments
I want to work on this |
Can u assign me this work? |
@CrossGL-issue-bot assign me |
The issue you are trying to assign to yourself is already assigned. |
@CrossGL-issue-bot assign me this issue i will fix this easily |
The issue you are trying to assign to yourself is already assigned. |
I'll work on this, assign this to me. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The current implementation of MetalLexer iterates through a list of token patterns (TOKENS) and applies individual regex matches sequentially. While functional, this approach can lead to suboptimal performance due to multiple regex evaluations for each position in the input code.
To enhance performance, I propose combining all token patterns into a single master regex using named capturing groups. This approach reduces the overhead of repeated regex evaluations and improves the maintainability of the code.
Current Implementation
for token_type, pattern in TOKENS:
regex = re.compile(pattern)
match = regex.match(self.code, pos)
# Logic for handling the match
Proposed Improvement
Combine all token patterns into a single regex using named capturing groups. Each pattern will be associated with its corresponding token type:
TOKENS_PATTERN = "|".join(
f"(?P<{token_type}>{pattern})" for token_type, pattern in TOKENS
)
MASTER_REGEX = re.compile(TOKENS_PATTERN)
This allows the lexer to match all token types in one pass and determine the matched token using match.lastgroup.
@NripeshN Can I work on this?
The text was updated successfully, but these errors were encountered: