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

Remove comments from mock pass #1030

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

robertbasic
Copy link
Collaborator

While debugging the memory leak issues, I've noticed that Mockery is doing a bit more work than really necessary. The Mock class is full of docblocks and comments that increase the generated code, meaning the string manipulation passes need more memory.

I'm not really sure about this approach. I've also learned that php has -w switch that strips away all comments and whitespace and creates output that can be used instead of Mock.php. The problem with that approach though, that we should be generating that file ourselves for every release (probably can be automated, but still, it's a step that can go wrong.) This StrippedMock.php has better performance impacts than the changes from this MR.

Thoughts?

Add a new string manipulation pass that removes all code comments and
empty lines from the generated mock code, so that the other string
manipulation passes have less code to work on.
Given that the str_replace has to happen on substrings that are before
the first curly bracket, split the generated mock code by the first
curly bracket, and then do the str_replace only on that smaller chunk of
code.

Not sure if there's really any benefit to this, as we're replacing one
string operation with another one.
@GrahamCampbell
Copy link
Contributor

I doubt there's better performance. Do you have any evidence? I actually suspect this is slower, because you have to do work to remove the comments Also, stripping phpdoc can be dangerous, because phpdoc can have semantic meaning, such as in doctrine.

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.

None yet

2 participants