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

Any reason for root-namespaced php built-in functions? #49

Closed
adriansuter opened this issue Apr 28, 2019 · 6 comments
Closed

Any reason for root-namespaced php built-in functions? #49

adriansuter opened this issue Apr 28, 2019 · 6 comments
Assignees
Milestone

Comments

@adriansuter
Copy link
Contributor

In \Slim\Psr7\NonBufferedBody::write() there are four function calls to php built-in functions. All of them are root-namespaced.

  • ob_get_level
  • ob_get_clean
  • flush
  • strlen

Is there any reason for that?

while (0 < \ob_get_level()) {
$buffered = \ob_get_clean() . $buffered;
}
echo $buffered . $string;
\flush();
return \strlen($string) + \strlen($buffered);

@l0gicgate
Copy link
Member

There isn't. This was just code ported from Slim 3. I missed it during the code review. You can PR that if you want!

@JoeBengalen
Copy link

FYI; Using the root-namespaced function calls is a micro performance optimization.
Why and how this works is explained by nikic in this video: https://youtu.be/M8Ktic5sPlo?t=2158

In short it is because PHP compiler will optimize internal functions call. Problem with non root namespaced function calls is that the compiler does not know if it is calling a root function or a function within the current namespace, because the compiler only parses a single file at a time.

@l0gicgate
Copy link
Member

@JoeBengalen I'd like to add more tests to the NonBufferedBody functionality later one. We will need to stub these functions so we can't use root namespace functions.

@JoeBengalen
Copy link

Oki, if it is required sure. Just wanted you to be aware of it :)

@danopz
Copy link
Member

danopz commented May 25, 2019

Is it really worth it to drop performance improvements for kind of "better" unit tests?

@l0gicgate
Copy link
Member

@danopz I'd much rather have test coverage than a micro-optimization that really doesn't make a difference on the grand scheme of things.

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

No branches or pull requests

4 participants