Skip to content

[HttpKernel][VarDumper] Truncate profiler data & optim perf #23465

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
Jul 11, 2017

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Jul 10, 2017

Q A
Branch? 3.3
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #23415, #21547 and hopefully #23110 and #23175
License MIT
Doc PR -

protected function getCasters()
{
return array(
'*' => function ($v, array $a, Stub $s, $isNested) {
Copy link
Member Author

@nicolas-grekas nicolas-grekas Jul 10, 2017

Choose a reason for hiding this comment

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

should be the main fix: nested objects are truncated, which prevent deep recursion into nested structures by default (eg "object" of the security decision log, requests attributes, etc.)

$i = 0;
$prefixedKeys = array();
foreach ($a as $k => $v) {
if (isset($k[0]) && "\0" !== $k[0] && !property_exists($class, $k)) {
Copy link
Member Author

@nicolas-grekas nicolas-grekas Jul 10, 2017

Choose a reason for hiding this comment

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

as shown by profiles in linked issue, this is a hot code path and calling property_exists() should be prevented

@@ -210,14 +210,12 @@ public function cloneVar($var, $filter = 0)
$this->filter = $filter;

try {
gc_disable();
Copy link
Member Author

Choose a reason for hiding this comment

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

shown also in linked profiles: cloning involves lots of Stub objects, thus can trigger lots of GC calls, for no benefit.

Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldnt we only re-enable based on gc_enabled()?

Copy link
Member

Choose a reason for hiding this comment

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

agreed

Copy link
Member Author

Choose a reason for hiding this comment

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

fixed

@szymach
Copy link

szymach commented Jul 10, 2017

Hey, I have just tried this fix and it indeed improves performance a lot. Basically it runs as fast as 3.2 did. Good job :)

@nicolas-grekas nicolas-grekas force-pushed the profile-sz branch 2 times, most recently from 02c613e to 0b3ee2d Compare July 10, 2017 09:24
Caster::PREFIX_VIRTUAL.'type_class' => new ClassStub(get_class($f->getConfig()->getType()->getInnerType())),
);
},
ConstraintViolationInterface::class => function (ConstraintViolationInterface $v, array $a) {
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 add this caster in the new Validator panel in 3.4 too ?

Copy link
Member Author

Choose a reason for hiding this comment

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

that's for you @ogizanagi

Copy link
Contributor

@ogizanagi ogizanagi Jul 10, 2017

Choose a reason for hiding this comment

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

Sure, I'll check this once this is merged on 3.4.

@nicolas-grekas nicolas-grekas force-pushed the profile-sz branch 2 times, most recently from 13d571a to 1037f82 Compare July 10, 2017 10:13
return array(
'*' => function ($v, array $a, Stub $s, $isNested) {
if (!$v instanceof Stub) {
foreach ($a as &$v) {
Copy link
Member

@stof stof Jul 10, 2017

Choose a reason for hiding this comment

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

@nicolas-grekas have you checked whether the usage of a reference here could be the reason why #23110 and #23175 happen (replacing the EntityManager somewhere it should not be replaced, and replacing the content of $_SESSION) ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I removed the reference so that if this is correct, then it might be fixed

@nicolas-grekas nicolas-grekas merged commit 754d3a7 into symfony:3.3 Jul 11, 2017
nicolas-grekas added a commit that referenced this pull request Jul 11, 2017
…f (nicolas-grekas)

This PR was merged into the 3.3 branch.

Discussion
----------

[HttpKernel][VarDumper] Truncate profiler data & optim perf

| Q             | A
| ------------- | ---
| Branch?       | 3.3
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #23415, #21547 and hopefully #23110 and #23175
| License       | MIT
| Doc PR        | -

Commits
-------

754d3a7 [HttpKernel][VarDumper] Truncate profiler data & optim perf
@nicolas-grekas nicolas-grekas deleted the profile-sz branch July 11, 2017 09:18
nicolas-grekas added a commit that referenced this pull request Jul 15, 2017
This PR was merged into the 3.3 branch.

Discussion
----------

[Profiler] Fix data collector getCasters() call

| Q             | A
| ------------- | ---
| Branch?       | 3.3 <!-- see comment below -->
| Bug fix?      | yes
| New feature?  | no <!-- don't forget updating src/**/CHANGELOG.md files -->
| BC breaks?    | no
| Deprecations? | no <!-- don't forget updating UPGRADE-*.md files -->
| Tests pass?   | yes
| Fixed tickets | N/A <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | N/A

Relates to #23465. Calling `DataCollector::getCasters()` using self results into overridden methods in child classes never been called.

Also removes an unused property.

Commits
-------

34e7094 [Profiler] Fix data collector getCasters() call
fabpot added a commit that referenced this pull request Jul 17, 2017
…taCollector::getCasters() method (ogizanagi)

This PR was merged into the 3.4 branch.

Discussion
----------

[Profiler][Validator] ValidatorDataCollector: use new DataCollector::getCasters() method

| Q             | A
| ------------- | ---
| Branch?       | 3.4 <!-- see comment below -->
| Bug fix?      | no
| New feature?  | no <!-- don't forget updating src/**/CHANGELOG.md files -->
| BC breaks?    | no
| Deprecations? | no <!-- don't forget updating UPGRADE-*.md files -->
| Tests pass?   | yes
| Fixed tickets | #23465 (comment) <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | N/A

~~First commit targets 3.3; see #23516

I didn't re-used the `ConstraintViolationInterface` caster used in the form collector, as it's the purpose of the validator collector to show the constraints data.

Commits
-------

c725a70 [Profiler][Validator] ValidatorDataCollector: use new DataCollector::getCasters() method
@fabpot fabpot mentioned this pull request Jul 17, 2017
@sroze
Copy link
Contributor

sroze commented Nov 28, 2017

Could we have an opt-in for this? As we can see in a few issues, this loses some information that might be useful to the developer. It could be nice to be able to "tune" a "deep debug" or "simple debug" something like that... 🤔

nicolas-grekas added a commit that referenced this pull request Jul 24, 2019
… objects (ogizanagi)

This PR was merged into the 4.4 branch.

Discussion
----------

[Messenger][Profiler] Remove cutting caster to dump full objects

| Q             | A
| ------------- | ---
| Branch?       | 4.4 <!-- see below -->
| Bug fix?      | no
| New feature?  | yes <!-- please update src/**/CHANGELOG.md files -->
| BC breaks?    | no     <!-- see https://symfony.com/bc -->
| Deprecations? | no <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files -->
| Tests pass?   | yes    <!-- please add some, will be required by reviewers -->
| Fixed tickets | N/A   <!-- #-prefixed issue number(s), if any -->
| License       | MIT
| Doc PR        | N/A

Obviously, not the ideal solution, but might open the discussion. Not being able to inspect more than 1 level deep in the profiler when dealing with DTOs and VOs in your messages is a pain 😕. You can't either access the `HandledStamp` `result` for instance.

This caster truncating collectors data was originally added in #23465 to mitigate performances issues, especially with the Form profiler. But actually a lot of useful information are now hidden to the developper.
Opting-out per collector might be a start. Either allowing to do it through config, or directly in code where sensible.

Commits
-------

e4fc5c0 [Messenger][Profiler] Remove cutting caster to dump full objects
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.

7 participants