Skip to content
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

Open
pracheeeeez opened this issue Jan 2, 2025 · 7 comments
Open
Assignees
Labels

Comments

@pracheeeeez
Copy link

pracheeeeez commented Jan 2, 2025

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?

@Manya123-max
Copy link

I want to work on this

@ManeeshDevarasetty
Copy link

Can u assign me this work?

@raghulchandramouli
Copy link

@CrossGL-issue-bot assign me

@CrossGL-issue-bot
Copy link

The issue you are trying to assign to yourself is already assigned.

@huntermarchi
Copy link

@CrossGL-issue-bot assign me this issue i will fix this easily

@CrossGL-issue-bot
Copy link

The issue you are trying to assign to yourself is already assigned.

@KeerthiKeswaran
Copy link

I'll work on this, assign this to me.

@github-actions github-actions bot added the stale label Jan 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

7 participants