8000 Deterministic proxy names by lstrojny · Pull Request #25978 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

Deterministic proxy names #25978

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
Jan 31, 2018
Merged

Deterministic proxy names #25978

merged 1 commit into from
Jan 31, 2018

Conversation

lstrojny
Copy link
Contributor
@lstrojny lstrojny commented Jan 30, 2018

Proxy class names should be deterministic and independent of spl_object_hash() which is somewhat random to better support reproducible builds. See #25958

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

@@ -108,7 +108,7 @@ public function getProxyCode(Definition $definition)
*/
private function getProxyClassName(Definition $definition)
{
return preg_replace('/^.*\\\\/', '', $definition->getClass()).'_'.substr(hash('sha256', spl_object_hash($definition).$this->salt), -7);
return preg_replace('/^.*\\\\/', '', $definition->getClass()).'_'.substr(hash('sha256', serialize($definition).$this->salt), -7);
Copy link
Member
@nicolas-grekas nicolas-grekas Jan 30, 2018

Choose a reason for hiding this comment

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

I just looked at the current logic. It looks like this would be enough isn't it? (with lazy prefix to easy recognizing them):
return 'lazy'.preg_replace('/^.*\\\\/', '', $definition->getClass()).'_'.substr(hash('sha256', $definition->getClass()), -7);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, that should be enough. The only scenario where this could break is if we would have the same class name with a different shape in one process. That is probably achievable through runkit and the like but I guess that’s a case we can ignore.

@lstrojny
Copy link
Contributor Author

@nicolas-grekas not sure what to do about the resource tracking topic. Probably worth another PR?

@stof
Copy link
Member
stof commented Jan 31, 2018

@lstrojny we currently don't invalidate the cached container when the class changes, meaning the generated proxy class might not be regenerated properly when needed.
Adding the method call suggested by @nicolas-grekas will register the appropriate resource tracking.

@nicolas-grekas
Copy link
Member

I fixed resource tracking in #25981

8000

@@ -108,7 +108,7 @@ public function getProxyCode(Definition $definition)
*/
private function getProxyClassName(Definition $definition)
{
return preg_replace('/^.*\\\\/', '', $definition->getClass()).'_'.substr(hash('sha256', spl_object_hash($definition).$this->salt), -7);
return preg_replace('/^.*\\\\/', '', $definition->getClass()).'_'.substr(hash('sha256', $definition->getClass().$this->salt), -7);
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean we only have a maximum of one proxy per class? 🤔

Copy link
Member

Choose a reason for hiding this comment

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

does it mean anything to have more that one proxy per class? do you have an example?

Copy link
Member

Choose a reason for hiding this comment

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

you will get only one proxy class per class. You can still have multiple instance.

If you look at the code, the only part of the Definition impact the generated class is the class name. So multiple definitions can reuse the same proxy class safely.

Copy link
Contributor

Choose a reason for hiding this comment

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

You are right, this makes sense :)

@fabpot
Copy link
Member
fabpot commented Jan 31, 2018

Thank you @lstrojny.

@fabpot fabpot merged commit b173b81 into symfony:3.4 Jan 31, 2018
fabpot added a commit that referenced this pull request Jan 31, 2018
This PR was merged into the 3.4 branch.

Discussion
----------

Deterministic proxy names

Proxy class names should be deterministic and independent of spl_object_hash() which is somewhat random to better support reproducible builds. See #25958

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

Commits
-------

b173b81 Proxy class names should be deterministic and independent of spl_object_hash() which is somewhat random
@lstrojny lstrojny deleted the dev/deterministic-proxy-class-names branch January 31, 2018 17:42
This was referenced Mar 1, 2018
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
0