Skip to content

[DI] Reference instead of inline for array-params #23143

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

Merged
merged 1 commit into from
Jun 14, 2017

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Jun 12, 2017

Q A
Branch? 3.4
Bug fix? no
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -
  • Tests to be written.

This PR is part of my "container on a diet" quest.

When big array parameters are resolved, they create data duplication in the dumped container. This is even worse when the same big array parameters are used several times.
Even though OPcache stores static arrays in shared memory (php7), it does not deduplicate them (it does for strings.)

Instead of inlining arrays, this PR leverages the $this->parameters property when possible.

@stof
Copy link
Member

stof commented Jun 12, 2017

couldn't this cause issue if we keep some parameters unresolved in the container ? Are we already unescaping string values containing a % before reaching the dumper ?

@nicolas-grekas
Copy link
Member Author

Tests added, PR is RFR.
@stof I don't see where this could break. Can you elaborate if you have a broken case?

@@ -80,10 +80,12 @@ protected function getTestService()
*/
public function getParameter($name)
{
$name = strtolower($name);
if (!(isset($this->parameters[$name]) || isset($this->loadedDynamicParameters[$name]) || array_key_exists($name, $this->parameters))) {
$name = strtolower($name);
Copy link
Member Author

Choose a reason for hiding this comment

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

µoptim here: conditionally call strtolower. This is a bit more important now that this will use getParameter internally a few more times.

Copy link
Member

Choose a reason for hiding this comment

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

should we deprecate the case insensitivity of parameter names ? This would be consistent with service ids.

Copy link
Member

Choose a reason for hiding this comment

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

+1,000 !!! We should stop changing the user config "magically" behind the scenes ... and that includes service IDs, param IDs, etc. ... unless there are strong technical reasons to do so. Thanks!

Copy link
Member Author

Choose a reason for hiding this comment

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

we may, in another PR :)

@nicolas-grekas nicolas-grekas force-pushed the params-ref-count branch 2 times, most recently from 96a8c32 to ee9ebc2 Compare June 12, 2017 18:11
@stof
Copy link
Member

stof commented Jun 13, 2017

@nicolas-grekas if I have an argument configured as %%array_param%%, will your code properly inject the string %array_param% or will it inject the array_param parameter instead ?

@nicolas-grekas
Copy link
Member Author

@stof test added, looks all good (the PhpDumper handles that logic)

$container->setParameter('array_1', array(123));
$container->setParameter('array_2', array(__DIR__));
$container->register('bar', 'BarClass')
->addMethodCall('setBaz', array('%array_1%', '%array_2%', '%%string%%'));
Copy link
Member

Choose a reason for hiding this comment

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

please make the content between the %% match the name of an existing parameter though (to ensure that working properly is not just due to the hasParameter check)

Copy link
Member Author

Choose a reason for hiding this comment

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

updated

@fabpot
Copy link
Member

fabpot commented Jun 14, 2017

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 7c3d0c7 into symfony:3.4 Jun 14, 2017
fabpot added a commit that referenced this pull request Jun 14, 2017
…olas-grekas)

This PR was merged into the 3.4 branch.

Discussion
----------

[DI] Reference instead of inline for array-params

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | no
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

- [x] Tests to be written.

This PR is part of my "container on a diet" quest.

When big array parameters are resolved, they create data duplication in the dumped container. This is even worse when the same big array parameters are used several times.
Even though OPcache stores static arrays in shared memory (php7), it does not deduplicate them (it does for strings.)

Instead of inlining arrays, this PR leverages the `$this->parameters` property when possible.

Commits
-------

7c3d0c7 [DI] Reference instead of inline for array-params
@nicolas-grekas nicolas-grekas deleted the params-ref-count branch July 10, 2017 15:58
This was referenced Oct 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants