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

perf(DI): Use static closures for DI service factories #36263

Closed
wants to merge 1 commit into from

Conversation

ChristophWurst
Copy link
Member

@ChristophWurst ChristophWurst commented Jan 20, 2023

  • Resolves: potential 🐌

Summary

Static closures do not capture $this and therefore allow the PHP garbage collector to free the surrounding object.

Ref https://stackoverflow.com/questions/19899468/php-closures-why-the-static-in-the-anonymous-function-declaration-when-bindin

Ref https://3v4l.org/0bpD8 vs https://3v4l.org/b3UHp

Benchmarks

Honestly not a lot:

Bildschirmfoto vom 2023-01-20 09-32-25

On the other hand this change has no disadvantage either.

Checklist

Static closures do not capture `$this` and therefore allow the PHP
garbage collector to free the surrounding object.

Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
@ChristophWurst ChristophWurst added this to the Nextcloud 26 milestone Jan 20, 2023
@ChristophWurst ChristophWurst self-assigned this Jan 20, 2023
@ChristophWurst ChristophWurst changed the title perf(DI): Use static closures for DI service builders perf(DI): Use static closures for DI service factories Jan 20, 2023
Copy link

@github-advanced-security github-advanced-security bot left a comment

Choose a reason for hiding this comment

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

Psalm found more than 10 potential problems in the proposed changes. Check the Files changed tab for more details.

@blizzz blizzz mentioned this pull request Feb 1, 2023
@skjnldsv skjnldsv mentioned this pull request Feb 23, 2023
@blizzz blizzz mentioned this pull request Mar 7, 2023
@blizzz blizzz modified the milestones: Nextcloud 26, Nextcloud 27 Mar 9, 2023
@ChristophWurst
Copy link
Member Author

conflicts

@ChristophWurst ChristophWurst deleted the perf/di/static-service-closures branch March 17, 2023 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Development

Successfully merging this pull request may close these issues.

2 participants