Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Use isset() instead of array_key_exists() in DIC#8907

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Closed

Conversation

catch56
Copy link

It doesn't look like the array_key_exists() in Container::get() and Container::has() is necessary. Changing this to isset() removed over 1,000 calls on a default Drupal 8 install - attaching before/after xhprof screenshots with this change.

screen shot 2013-09-01 at 1 13 41 pm

screen shot 2013-09-01 at 1 13 49 pm

@stloyd
Copy link
Contributor

This is wrong as some services can benull (synthetic, i.e. request). Just check broken build at Travis-CI.

@catch56
Copy link
Author

Yes I'm sure about xdebug being disabled (although it looks like you deleted your comment?).

isset() || array_key_exists() handles the case of a null service, and still gives me significant reduction in calls.

screen shot 2013-09-01 at 2 03 37 pm

@lsmith77
Copy link
Contributor

didn't we go back and forth here before?

@catch56
Copy link
Author

Well remembered. I did a search and found it discussed here:#7007 (diff)

But isset() || array_key_exists() wasn't mentioned in that exchange.

@fabpot
Copy link
Member

@catch56 Does it bring a noticeable performance improvement on a full page?

@catch56
Copy link
Author

It's 0.8 of a millisecond on my local install and 1/45th of the total function calls on the page.

That's not huge but yes it's a measurable improvement (i.e. ten similar changes and they'd add up to 8ms).

@catch56
Copy link
Author

I think we can likely save some of the 1,200 or so strtolower() calls here as well - by checking for the string as passed in first in the common cases, then falling back to strtolower() later. That's roughly a millisecond on my machine as well - will put it in a new pull request but it'll need to depend on this one since it's the same lines of code.

@fabpot
Copy link
Member

@catch56 As this is also a performance optimization, feel free to do everything in this PR. That makes things easier for everyone. Thanks.

@catch56
Copy link
Author

OK sounds good, thanks!

@catch56
Copy link
Author

Pushed that commit. Here's before after xhprof UI screenshots showing the calls removed.

screen shot 2013-09-02 at 4 14 54 pm
screen shot 2013-09-02 at 4 13 35 pm

@catch56
Copy link
Author

Because that's Drupal coding standards which my brain defaults to. Updated.

fabpot added a commit that referenced this pull requestSep 3, 2013
This PR was submitted for the master branch but it was merged into the 2.3 branch instead (closes#8907).Discussion----------Use isset() instead of array_key_exists() in DICIt doesn't look like the array_key_exists() in Container::get() and Container::has() is necessary. Changing this to isset() removed over 1,000 calls on a default Drupal 8 install - attaching before/after xhprof screenshots with this change.![screen shot 2013-09-01 at 1 13 41 pm](https://f.cloud.github.com/assets/116285/1063965/d826057c-1300-11e3-96c3-2c94b89fe83a.png)![screen shot 2013-09-01 at 1 13 49 pm](https://f.cloud.github.com/assets/116285/1063961/99a0f7b2-1300-11e3-9bd2-b0bf22d4245e.png)Commits-------3c01ae6 Use isset() instead of array_key_exists() in DIC
@fabpot
Copy link
Member

merged in 2.3, thanks.

@fabpotfabpot closed thisSep 3, 2013
// available services. Service IDs are case insensitive, however since
// this method can be called thousands of times during a request, avoid
// calling strotolower() unless necessary.
foreach (array(false, true) as $strtolower) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Does flatten code would be more efficient than this loop ?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

6 participants
@catch56@stloyd@lsmith77@fabpot@GromNaN@mvrhov

[8]ページ先頭

©2009-2025 Movatter.jp