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

Rely on reflection to access null properties #4425

Open
wants to merge 1 commit into
base: 3.x
Choose a base branch
from

Conversation

nicolas-grekas
Copy link
Contributor

@nicolas-grekas nicolas-grekas commented Oct 29, 2024

Benchmark like https://gist.github.com/arnaud-lb/c4235164fb41e11672aa670da8fa4fc7 (which were done for another use case but is still relevant here) prove that using reflection instead of array-casts is significantly faster for accessing properties.

Checking for dynamic properties is done with property_exists.

@nicolas-grekas nicolas-grekas changed the title Rely on reflection to access properties Rely on reflection to access null properties Oct 29, 2024
src/Extension/CoreExtension.php Outdated Show resolved Hide resolved
src/Extension/CoreExtension.php Outdated Show resolved Hide resolved
@nicolas-grekas nicolas-grekas force-pushed the array-cast-less branch 2 times, most recently from c186115 to d8f39e6 Compare October 31, 2024 12:02
@nicolas-grekas
Copy link
Contributor Author

PR updated with a simpler and more performant approach, that makes DateTimeInterface a special case (because it is).

@@ -1720,6 +1738,8 @@ public static function getAttribute(Environment $env, Source $source, $object, $

return \constant($object::class.'::'.$item);
}
} else {
$item = (string) $item;
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we cast before the if?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

4 participants