Skip to content

Optimize parsing of PHP files #1427

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dreis2211
Copy link
Contributor

@dreis2211 dreis2211 commented Jul 11, 2025

Hi,

when profiling a Sonar scan of a medium sized project I noticed that while parsing the PHP files a significant overhead is spent on doing regexes through PatternExpression.

image

This PR adds a special CaseInsensitiveStringExpression to achieve the same, but without regexes. To get all of its benefits, I also switched the values of some common words to lowercase as this matches the standard way how they would be written inside the code (and thus reducing the overhead even more).

In local tests only doing parsing this cuts the portion of PatternExpression from ~21% to ~9%
Before
image
After
image
The new CaseInsensitiveStringExpression only accounts for ~2% of the samples, so quite an improvement to the previous state.
image

In terms of time this also accounts roughly for a 13% reduction in my local tests.

Would appreciate if this is considered.

Cheers,
Christoph

@dreis2211 dreis2211 changed the title Optimizing parsing of PHP files Optimize parsing of PHP files Jul 11, 2025
Prior to this commit, PatternExpression is used inside the grammar for
case-insensitive checks for e.g. keywords. This can be avoided by introducing
a special CaseInsensitiveStringExpression that omits the relatively expensive
regexes.
@dreis2211
Copy link
Contributor Author

dreis2211 commented Jul 31, 2025

@GabinL21 let me know if you need anything from me (I'm assuming you review this based on your reaction).

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.

1 participant